Free Support Forum - aspose.com

Problem in formatting while appending multiple document

Hi

We are using Aspose.word.dll (version 10.0.0.0) (licensed)

We have multple word document which we have to append with our one master template and each document have specific category which have to add dynamically before the its content.
We are using DocumentBuilder.InsertHTML() method for inserting category as heading1 (h1) at the top of each document.

When we generate the output, it display the category as heading1 (which is correct) but the already heading present in that document comes as normal text (which is incorrect). It should come as the next heading

please find below code which we have used for appending multiple word document and inserting category in each word document.

Aspose.Words.Document genratedDocFrag = new Aspose.Words.Document(appendfile);
DocumentBuilder builder = new DocumentBuilder(genratedDocFrag);
builder.MoveToDocumentStart();
string html = “

Heading1

”;
builder.InsertHtml(html);

DocumentBuilder docBuilderTemp = new DocumentBuilder(MasterTemplateDoc);
docBuilderTemp.MoveToDocumentEnd();
docBuilderTemp.InsertBreak(BreakType.SectionBreakNewPage);

foreach (Aspose.Words.Section srcSection in genratedDocFrag)
{
Aspose.Words.Section newSection = (Aspose.Words.Section)MasterTemplateDoc.ImportNode(srcSection, true, ImportFormatMode.UseDestinationStyles);
MasterTemplateDoc.LastSection.AppendContent(newSection);
}
MasterTemplateDoc.UpdateFields();
MasterTemplateDoc.Save(outputFileName); Aspose.Words.Document genratedDocFrag = new Aspose.Words.Document(appendfile);
DocumentBuilder builder = new DocumentBuilder(genratedDocFrag);
builder.MoveToDocumentStart();
string html = “

Hardware

”;
builder.InsertHtml(html);

DocumentBuilder docBuilderTemp = new DocumentBuilder(MasterTemplateDoc);
docBuilderTemp.MoveToDocumentEnd();
docBuilderTemp.InsertBreak(BreakType.SectionBreakNewPage);

foreach (Aspose.Words.Section srcSection in genratedDocFrag)
{
Aspose.Words.Section newSection = (Aspose.Words.Section)MasterTemplateDoc.ImportNode(srcSection, true, ImportFormatMode.UseDestinationStyles);
MasterTemplateDoc.LastSection.AppendContent(newSection);
}
MasterTemplateDoc.UpdateFields();
MasterTemplateDoc.Save(outputFileName);


Please find the attached image in which “Hardware” heading we are adding but the text enclosed in recatngle is coming as normal text

Please let us know the solution ASAP.

Thanks
Samanvay

Hi

Thanks for your request. Could you please try using the following code to insert Heading content:

// Create DocumentBuilder, which we will use to generate document.

DocumentBuilder builder = new DocumentBuilder();

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

builder.Writeln("Heading 1");

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

builder.Writeln("Heading 1.1");

builder.Writeln("Heading 1.2");

// Now we can save the final document.

builder.Document.Save("out.doc");

Please let me know how it goes on your side.

Best regards,