Free Support Forum - aspose.com

Problem With DocumentBuilder ParagraphFormat.StyleName

Hi

Are there any known issues with the use of DocumentBuilder.ParagraphFormat.StyleName?

I am using a template I created with the desired styles. However if I attempt to use any of the styles with DocumentBuilder.ParagraphFormat.StyleName in my code, the resulting Word document will not load. Word just hangs.

The example code below produces a usable Word document if the line setting the StyleName is commented out, but I get the problem described above if it is left in.

Aspose.Word.Word.SetLicense(this.Server.MapPath("Aspose.Office.lic"),this);
Document doc = new Document(MapPath("WordExtractTemplate.dot"));
DocumentBuilder b = new DocumentBuilder(doc);

// Set merge fields
b.MoveToMergeField("ExtractTitle");
b.Write("New Report");
b.MoveToMergeField("ExtractSubTitle");
b.Write("New Report Sub Title");
b.MoveToMergeField("PublicationDate");
b.Write("26/01/2005");
b.MoveToMergeField("Breadcrumb");
b.Write("Chapter 3: A New Template");
b.MoveToMergeField("ProductID");
b.Write("Prod1");
b.MoveToMergeField("FooterProductID");
b.Write("Prod1");

b.MoveToMergeField("StartExtract");
b.ParagraphFormat.ClearFormatting();

b.ParagraphFormat.StyleName = "Extract_Body";
b.Writeln("Some Example Text");

doc.MailMerge.DeleteFields();

doc.Save("testExtract.doc", SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);

I don't want to have to set all formatting attributes in code, as I'd like the flexibility to change them in the template in the future without touching the code.

I am using Word 2000 (9.0.6926 SP-3) to open the document, and Aspose.Word.dll file version 1.0.1850.31896. I'd be happy to send you the template I am using.

Any help appreciated.

Regards
Mike Cook

Hi

Further investigation reveals that template I’ve been given has all content placed in a table cell. When the table is converted to text everything works fine. So the issue appears to be using styles within a table. I’m happy to proceed without the table.

Hope this helps.

Mike

Hi Mike,

Thank you for reporting the issue in such great detail. We have the issue fixed, it will be released in Aspose.Word 2.1.8 in the next 2-3 days.