Hello,
I want to generate a table in a Word document with some merged cells in the first row, and the other rows containing data. I need to specify the column width explicitly (using the DocumentBuilder.CellFormat.Width property), but I get strange results.
Here is the code to isolate the problem:
Document Doc = new Document();
Doc.EnsureMinimum();
DocumentBuilder Db = new DocumentBuilder(Doc);
Db.InsertCell();
Db.CellFormat.HorizontalMerge = CellMerge.First;
// Uncomment this line to reproduce the bug: cells width in the whole table are ‘messed up’
// Db.CellFormat.Width=350;
Db.Write("Text in the merged cells.");
Db.InsertCell();
//This cell is merged to the previous and should be empty.
Db.CellFormat.HorizontalMerge = CellMerge.Previous;
Db.InsertCell();
Db.CellFormat.HorizontalMerge = CellMerge.Previous;
Db.InsertCell();
Db.CellFormat.HorizontalMerge = CellMerge.Previous;
Db.InsertCell();
Db.CellFormat.HorizontalMerge = CellMerge.Previous;
Db.EndRow();
Db.InsertCell();
Db.CellFormat.HorizontalMerge = CellMerge.None;
Db.Write("Text in one cell.");
Db.InsertCell();
Db.Write("Text in another cell.");
//Uncomment this line to reproduce the bug: cells width in the whole table are ‘messed up’
// Db.CellFormat.Width=200;
Db.InsertCell();
Db.Write("Text in another cell.");
Db.InsertCell();
Db.Write("Text in another cell.");
Db.InsertCell();
Db.Write("Text in another cell.");
Db.EndRow();
Doc.Save(@"c:\test.doc");
If I execute this code as is (without uncommenting the cell width initializing lines), the ouput Word document is OK.
When I uncomment the line Db.CellFormat.Width=350;
, the output document contains the first cell of the first row with a tiny width, and the cells in the row below are far too wide. (I attached the output doc)
When I uncomment the line // Db.CellFormat.Width=200;
, the output document contains a table with strange layout, too.
I use Aspose.word 3.1.1.0 (but it was the same with 3.1.0.0), and Word 2003 as viewer.