Corrupt Tables Using DocumentBuilder When Creating > 7 Columns


#1

Hi

When I create tables with more than 7 columns using DocumentBuilder, I get the following error when opening the resulting Word doc: “A table in this document has become corrupted…”.

I am using Word 2000(9.0.6926 SP-3) and (I think) the latest version of Aspose Word (dll version 2.1.1.0). The error can be replicated using the following code:

Aspose.Word.Word.SetLicense(this.Server.MapPath(“Aspose.Office.lic”),this);
Document doc = new Document(MapPath(“myTemplate.dot”));
DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToMergeField(“startExtract”);
builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleName = “Heading 2”;
builder.Writeln(“Table Title”);

builder.ParagraphFormat.StyleName = “TableBody”;
builder.RowFormat.HeightRule = RowHeightRule.Auto;
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;

foreach (Border border in builder.CellFormat.Borders)
{
border.LineStyle = LineStyle.Single;
border.LineWidth = 1;
border.Color = System.Drawing.Color.Black;
}

builder.CellFormat.Width = 50;

for(int i=0; i<20; ++i)
{
for(int j=0;j<8; ++j)
{
builder.InsertCell();
builder.Write(string.Format(“cell{0} row{1}”,j,i));
}
builder.EndRow();
}
builder.EndTable();

doc.MailMerge.DeleteFields();
doc.Save(“testExtract.doc”, SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);

Is this a known issue. I can send you a copy of my template if that would help.

Regards
Mike Cook


#2

Hi,

We had a very similar problem some time ago and although we worked around we never fully understood or solved it. I think it was related to styles, try avoid using ParagraphFormat.StyleName = "TableBody" or maybe try using some different style there just to see if it makes any difference.

If that does not help, send the document to me to word@aspose.com and we will have a look.


#3

Hi

The code works if ParagraphFormat.StyleName is set to “Normal”, however if I create and use new style with exactly the same attributes as Normal it still corrupts the table.

I can proceed by setting all paragraph format settings in code for now, but it would be good to have this fixed in a future release so that style changes can be made on the template without requiring an application rebuild.

Regards
Mike