Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Oct 10, 2020 4:41 pm

Hi,
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

markeye3
 
Posts: 27
Joined: Wed Jul 29, 2015 5:59 pm

Mon Oct 12, 2020 7:31 am

Hello,

Thanks for your inquiry.
I tested your code with the latest Spire.Office Platinum(Hotfix) Version:5.9.6 and the total time spent was about 30min, this indeed took a long time. I have posted this issue to our Dev team to investigate if it can be optimized. If it there is any good news, I will inform you immediately. But as for the memory issue, I tested it several times and did not encounter the OutOfMemory error, the memory consumption was about 200MB. Could you please provide your OS information (e.g. Windows 7, 64bit 8GB) and your application target framework (e.g. .NET Framework 4.5) to help us investigate further?
Besides, regarding the competitors you mentioned, could you please provide the download link of the product and the test code you used? Thanks in advance.

Sincerely,
Elena
E-iceblue support team
User avatar

Elena.Zhang
 
Posts: 279
Joined: Thu Jul 23, 2020 1:18 am

Return to Spire.Doc