Hi, guys!
I have the problem with inserting table inside cell. I want to insert table within cell with several columns.
My sample code is:
private void WriteTable(bool insertInnerTable)
{
var isOuterTable = !_builder.CurrentParagraph.IsInCell;
var table = _builder.StartTable();
var columnsCount = 2;
var rowCount = 3;
if (isOuterTable)
{
for (int c = 0; c < columnsCount; c++)
{
Cell cell = _builder.InsertCell();
cell.CellFormat.PreferredWidth = PreferredWidth.FromPercent(50);
cell.CellFormat.Shading.BackgroundPatternColor = Color.LightGray;
_builder.Font.Bold = false;
_builder.MoveTo(cell.FirstParagraph);
_builder.Write(string.Format("header {0}", c + 1));
}
_builder.EndRow();
_builder.CellFormat.ClearFormatting();
_builder.RowFormat.ClearFormatting();
}
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
{
for (int columnIndex = 0; columnIndex < columnsCount; columnIndex++)
{
Cell cell = _builder.InsertCell();
cell.CellFormat.PreferredWidth = PreferredWidth.FromPercent(50);
if (insertInnerTable)
{
WriteTable(false);
}
else
{
_builder.Write("value");
}
}
_builder.EndRow();
rowIndex++;
}
table.AllowAutoFit = false;
_builder.EndTable();
}
I got:
header 1 | header 2 |
---|---|
value | value |
value | value |
value | value |
value | value |
value | value |
value | value |
value | value |
value | value |
As you see, columns in tables are not the same widths from row to row. Why? What am I doing wrong?
Thanks,
Yulia.