Exporting a DataTable from WinForms to a docx file takes a lot of time

未关闭
#448 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
csharp
领域
backend

调研方向

Reproduce the report using the shown DocX.Create, InsertSection, AddTable, and InsertTableAfterSelf flow, comparing behavior between versions 2.3.0 and 2.4.0. Inspect why table-cell paragraphs remain empty and why section header/footer warnings appear during export. Done means table contents are populated and the export time is no longer unexpectedly slow.

由索引模型根据 Issue 内容生成。

描述

Hi.
I've just updated from 2.3.0 to 2.4.0, because I just want to use the new parameter from Section page numeration. But now the exporting process takes a lot of time, and I don't know why, because I'm using the same code as I used on the previous version. What happened with the new version?

Edit: More than that, my all table is empty. Seems none of the paragraphs inside the table object are filled. But is the same code as in 2.3.0, what has been changed?

OK. I've started debugging this thing and I found the following:
After each line of code which is using some appending operation, or anything that involve an object on the file, I get the following lines of information in debugger:

This document contains more than 1 section. Consider using Sections[wantedSection].Headers.
This document contains more than 1 section. Consider using Sections[wantedSection].Headers.
This document contains more than 1 section. Consider using Sections[wantedSection].Headers.
This document contains more than 1 section. Consider using Sections[wantedSection].Footers.
This document contains more than 1 section. Consider using Sections[wantedSection].Footers.
This document contains more than 1 section. Consider using Sections[wantedSection].Footers.

My code is the following, what I'm doing wrong?

DocX doc = DocX.Create(filePath, DocumentTypes.Document);
while (doc.Sections.Count < numeGrup.Count)
{
    // I need to insert sections for each group in "numeGrup" list
    doc.InsertSection();
}
var sec = doc.Sections[0];
for (int k = 0; k < numeGrup.Count; k++)
{
    sec = doc.Sections[k];
    sec.PageLayout.Orientation = Orientation.Landscape;
    sec.PageNumberType.PageNumberStart = 1;
    sec.PageWidth = 800;
    sec.MarginLeft = 20;
    sec.MarginRight = 20;
    sec.MarginTop = 20;
    sec.MarginBottom = 20;
    sec.InsertParagraph(numeGrup[k].Key.Nume).SpacingBefore(20d).Font("Arial").FontSize(10).Bold().SpacingAfter(10d);
    var table = doc.AddTable(detaliiPeFirma.Count() + 1 + groups.Count, 9);
    table.SetTableCellMargin(TableCellMarginType.left, 1);
    table.SetTableCellMargin(TableCellMarginType.right, 1);
    table.SetTableCellMargin(TableCellMarginType.top, 1);
    table.SetTableCellMargin(TableCellMarginType.bottom, 1);
    var p = sec.InsertParagraph();
    p.InsertTableAfterSelf(table);
    table.Design = TableDesign.LightGrid;
    var headerRow = table.Rows.First();
    headerRow.TableHeader = true;
    headerRow.Cells[0].Paragraphs[0].Append("Field1").Bold().FontSize(10);
    headerRow.Cells[1].Paragraphs[0].Append("Field2").Bold().FontSize(10);
    headerRow.Cells[2].Paragraphs[0].Append("Field3").Bold().FontSize(10);
    headerRow.Cells[3].Paragraphs[0].Append("Field4").Bold().FontSize(10);
    headerRow.Cells[4].Paragraphs[0].Append("Field5").Bold().FontSize(10);
    headerRow.Cells[5].Paragraphs[0].Append("Field6").Bold().FontSize(10);
    headerRow.Cells[6].Paragraphs[0].Append("Field7").Bold().FontSize(10);
    headerRow.Cells[7].Paragraphs[0].Append("Field8").Bold().FontSize(10);
    headerRow.Cells[8].Paragraphs[0].Append("Field9").Bold().FontSize(10);
}

I put only a part of my code, the generation of tables and filling of headers of the tables. But no paragraph inside table's cells are filled. And it's working very slow now! Maybe because of those messages in the debugger?

主要语言
C#
星标
1.9k
派生
482
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

xceedsoftware/DocX 的其他 Issue

查看 xceedsoftware/DocX 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。