We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to insert "H" style text?

hi, currently I can use the documentBuilder.ParagraphFormat.StyleName = "Heading 1" to insert H1 style text, but I couldn't find the way to insert the H style paragraph. could you give me some advise? thanks.
This message was posted using Aspose.Live 2 Forum

Hi Andy,

Thanks for your inquiry.

Could you please attach your template here for testing?

Thanks,

hi, this is the code, the attachment is the generated document. But I can't insert the "H" style Paragraph.

DocumentBuilder builder = new DocumentBuilder();
Document doc = builder.Document;
List headlineList = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);

builder.ListFormat.List = headlineList;

//builder.ParagraphFormat.StyleName = "Heading"; // this doesn't work.
///builder.Writeln("Heading");

builder.ListFormat.ListLevelNumber = 0;
builder.ParagraphFormat.StyleName = "Heading 1";
builder.Writeln("Heading 1");

builder.ListFormat.ListLevelNumber = 1;
builder.ParagraphFormat.StyleName = "Heading 2";
builder.Writeln("Heading 1.1");
builder.Writeln("Heading 1.2");
builder.ListFormat.ListLevelNumber = 2;
builder.ParagraphFormat.StyleName = "Heading 3";
builder.Writeln("Heading 1.2.1");

builder.ListFormat.ListLevelNumber = 0;
builder.ParagraphFormat.StyleName = "Heading 1";
builder.Writeln("Heading 1");

builder.ListFormat.ListLevelNumber = 1;
builder.ParagraphFormat.StyleName = "Heading 2";
builder.Writeln("Heading 1.1");
builder.Writeln("Heading 1.2");

doc.Save(MyDir + "DocumentBuilder.InsertToc Out.doc");

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. When you say H style, do you mean “Header” style in MS Word? If so, you can use the following code:

DocumentBuilder builder = new DocumentBuilder();

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Header;

builder.Writeln("Header");

builder.Document.Save(@"Test001\out.doc");

Hope this helps.

Best regards,

hi, I test the above code, it doesn’t work, the attachmentment is the code generated document.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. As I can see, “Header” style is properly applied to the paragraph, please see the attached screenshot.

If you need to use some specific formatting for this style, you can set it programmatically or use your own template for generating document:

DocumentBuilder builder = new DocumentBuilder();

// change formation of 'Header' style.

builder.Document.Styles[StyleIdentifier.Header].ParagraphFormat.Alignment = ParagraphAlignment.Center;

builder.Document.Styles[StyleIdentifier.Header].Font.Bold = true;

builder.Document.Styles[StyleIdentifier.Header].Font.Size = 24;

// Insert 'header' text.

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Header;

builder.Writeln("Header");

builder.Document.Save(@"Test001\out.doc");

Hope this helps.

Best regards,

hi,I test the above way, but the Alignment is still Left, but the Bold and Size work well. Could you give me some advice?

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I used the latest version of Aspose.Words for testing, and as I can see all works just as expected. I attached the document produced by this code.

You can download the latest version of Apsose.Words from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

Best regards,

thanks. I download the latest version and it works well.

best regards

andy