Free Support Forum - aspose.com

Using Style Identifier

Hi,

I put 2 headings consecutively with DocumentBuilder. This is the code:

ParagraphFormat paraForm = builder.getParagraphFormat();
paraForm.setStyleIdentifier(StyleIdentifier.HEADING_1);
paraForm.setLeftIndent(indentHeading(StyleIdentifier.HEADING_1));
builder.writeln(“FirstOne”);
paraForm.clearFormatting();

paraForm.setStyleIdentifier(StyleIdentifier.HEADING_2);
paraForm.setLeftIndent(indentHeading(StyleIdentifier.HEADING_2));
builder.writeln(“SecondOne”);
paraForm.clearFormatting();

The resulted document has
* If I don’t use clearFormatting(), FirstOne with Heading2 style and the SecondOne with Heading1 style.
* If I use clearFormatting(), FirstOne with normal style and the SecondOne with Heading1 style.
What is wrong with the code?
Expect an answer ASAP…

Hi

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

Thanks for your request. Please use the following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);

builder.writeln("FirstOne");

builder.getParagraphFormat().clearFormatting();

builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);

builder.writeln("SecondOne");

builder.getParagraphFormat().clearFormatting();

doc.save("C:\\Temp\\out.doc");

This should help.

Best regards.