Corrupt Tables Using DocumentBuilder When Creating > 7 Columns



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 The error can be replicated using the following code:

Document doc = new Document(MapPath(“”));
DocumentBuilder builder = new DocumentBuilder(doc);


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.Write(string.Format(“cell{0} row{1}”,j,i));

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.

Mike Cook



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 and we will have a look.



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.