.NET DocX-用表格替换文本

时间:2018-08-26 21:07:44

标签: c# .net docx

我目前正在使用DocX创建Word文档,然后替换模板中的文本。

我现在需要用表格替换文本(基本上将表格插入文档中的特定位置),并且无法弄清楚。

任何帮助都会很棒。

这是我插入表的代码,但是当前只是将其附加到文档的末尾。

template.ReplaceText("[advice]", factfind.Advice ?? "");

    Table table = template.AddTable(factfind.Quotes.Count + 1, 7);

    for (var i = 0; i < factfind.Quotes.Count; i++)
    {
        table.Rows[i].Cells[0].Paragraphs.First().Append(factfind.Quotes[i].Products[0].Provider.Name ?? "");
        table.Rows[i].Cells[1].Paragraphs.First().Append("£" + factfind.Quotes[i].Products[0].PaymentOptions[0].Payments[0].FinancialComponents.Gross);
        table.Rows[i].Cells[2].Paragraphs.First().Append("£" + factfind.Quotes[i].Products[0].DetailCategories[0].Details[3].Value + " " + "Per month");
        table.Rows[i].Cells[3].Paragraphs.First().Append(factfind.Quotes[i].Products[0].DetailCategories[0].Details[2].Value + " " + "Days");
        table.Rows[i].Cells[4].Paragraphs.First().Append(factfind.Quotes[i].Products[0].DetailCategories[0].Details[1].Value + " " + "Days");
        table.Rows[i].Cells[5].Paragraphs.First().Append(factfind.Quotes[i].Products[0].DetailCategories[0].Details[0].Value + " " + "Months");
        table.Rows[i].Cells[6].Paragraphs.First().Append(factfind.Quotes[i].Products[0].ProductType ?? "");
    }

    template.InsertTable(table);

0 个答案:

没有答案