I'm having trouble with the performance of documents with large tables. Application memory grows significantly and sometimes throws an OutOfMemory error.
The following code takes over an hour on my machine using Spire.Office for WPF:
- Code: Select all
int rowCount = 1000;
int columnCount = 30;
using (var doc = new Document())
{
doc.CreateMinialDocument();
doc.Sections[0].PageSetup.Orientation = PageOrientation.Landscape;
var table = doc.LastSection.AddTable(true);
table.ResetCells(rowCount + 1, columnCount);
table.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
table.TableFormat.LayoutType = LayoutType.Fixed;
table.TableFormat.Paddings.Top = 0f;
table.TableFormat.Paddings.Left = 0.04f * 72f;
table.TableFormat.Paddings.Bottom = 0f;
table.TableFormat.Paddings.Right = 0.04f * 72f;
var row = table.Rows[0];
row.RowFormat.IsBreakAcrossPages = false;
row.IsHeader = true;
for (int column = 0; column < columnCount; column++)
{
row.Cells[column].SetCellWidth(column <= 1 ? 8 : 3, CellWidthType.Percentage);
row.Cells[column].AddParagraph().AppendText($"Col{column + 1}");
}
for (int i = 1; i <= rowCount; i++)
{
row = table.Rows[i];
row.RowFormat.IsBreakAcrossPages = false;
for (int column = 0; column < columnCount; column++)
{
row.Cells[column].SetCellWidth(column <= 1 ? 8 : 3, CellWidthType.Percentage);
row.Cells[column].AddParagraph().AppendText($"R{i}C{column + 1}");
}
}
doc.SaveToFile("C:\\Temp\\TestLargeTable.docx", FileFormat.Docx2013);
}
Unfortunately, this is a major roadblock for me as we deal with many documents of this nature. Similar code from your competitors takes a couple of seconds and uses very little memory.
Thanks,
Mark