Hi,
I am creating a table with a lot of rows, for some reason, the table will not break over multiple pages, each row is quite small - there are just a lot of them! instead of breaking onto multiple pages, the rows which wont fit on the starting page are just cut off.
I have tried setting KeepTogether to false but it doesnt seem to make any difference!
here is the function which creates the table:
Code:
public MigraDoc.DocumentObjectModel.Tables.Table buildSizedTable(int rows, List<int> colWidths, List<TableElement> cellData, MigraDoc.DocumentObjectModel.Font font)
{
int _cellDataIdx = 0;
MigraDoc.DocumentObjectModel.Tables.Table _table = new Table();
_table.TopPadding = 3;
_table.BottomPadding = 3;
_table.LeftPadding = 3;
_table.RightPadding = 3;
//_table.KeepTogether = false;
MigraDoc.DocumentObjectModel.Font _font = font.Clone();
for (int cols = 0; cols < colWidths.Count; cols++)
{
_table.AddColumn(((page.Width - leftMargin - rightMargin) / 100) * colWidths[cols]);
}
try
{
for (int r = 0; r < rows; r++)
{
Row _row = _table.AddRow();
_row.HeightRule = RowHeightRule.Auto;
for (int c = 0; c < colWidths.Count; c++)
{
Cell _cell = _row.Cells[c];
if (cellData[_cellDataIdx].format.borders.IndexOf("T") != -1)
{
_cell.Borders.Top.Width = cellData[_cellDataIdx].format.borderWidth;
}
if (cellData[_cellDataIdx].format.borders.IndexOf("B") != -1)
{
_cell.Borders.Bottom.Width = cellData[_cellDataIdx].format.borderWidth;
}
if (cellData[_cellDataIdx].format.borders.IndexOf("L") != -1)
{
_cell.Borders.Left.Width = cellData[_cellDataIdx].format.borderWidth;
}
if (cellData[_cellDataIdx].format.borders.IndexOf("R") != -1)
{
_cell.Borders.Right.Width = cellData[_cellDataIdx].format.borderWidth;
}
font.Bold = cellData[_cellDataIdx].format.bold;
font.Italic = cellData[_cellDataIdx].format.italic;
font.Size = cellData[_cellDataIdx].format.size;
font.Underline = cellData[_cellDataIdx].format.underlined;
if (cellData[_cellDataIdx].fill)
{
_cell.Shading.Color = cellData[_cellDataIdx].fillColor;
}
if (cellData[_cellDataIdx].mergeRight > 0)
{
_cell.MergeRight = cellData[_cellDataIdx].mergeRight;
}
if (cellData[_cellDataIdx].mergeDown > 0)
{
_cell.MergeDown = cellData[_cellDataIdx].mergeDown;
}
buildCell(_cell, cellData[_cellDataIdx], font);
_cellDataIdx++;
}
}
_table.KeepTogether = false;
document.LastSection.Add(_table);
}
catch
{
}
return _table;
}
The cellData object in the parameters is basically an array of objects holding styling information for each cell.
Im really stuck on this - I am creating quite a lot of print documents, all of which have an unfixed number of rows in each table, so this is a big problem for me!
Any ideas?