.NET DocX - замена текста таблицей - PullRequest
0 голосов
/ 27 августа 2018

В настоящее время я использую DocX, чтобы создать слово doc, а затем заменить текст в шаблоне.

Теперь мне нужно заменить текст таблицей (по сути, вставить таблицу в определенную точку в документе)и не могу понять.

Любая помощь была бы отличной.

Вот мой код для вставки таблицы, но в настоящее время он просто добавляет ее в конец документа.

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);
...