Как заполнить таблицу в MS WORD c# - PullRequest
0 голосов
/ 27 апреля 2020

Мне нужно заполнить таблицу в MS WORD из списка. Количество моих строк не фиксировано, и я не могу найти способ сделать это по c#

1 Ответ

0 голосов
/ 27 апреля 2020
       it will add numers of rows

     string pathDocument = AppDomain.CurrentDomain.BaseDirectory + "example.docx";

            DocX document = DocX.Create(pathDocument);

            Table table = document.AddTable(res.Count, 10);

            table.Alignment = Alignment.center;

            table.Design = TableDesign.TableGrid;
            for(var row=0;row<res.Count;row++)
            {

                table.Rows[row].Cells[0].Paragraphs[0].Append((row+1).ToString());
            }

            document.InsertParagraph().InsertTableAfterSelf(table);


            document.Save();
...