如何在MS WORD c#中填表?

问题描述 投票:-2回答:1

我需要在MS WORD中用List填表。我的行数不固定,我找不到如何用c#来做。

c# wpf ms-word
1个回答
0
投票
       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();
© www.soinside.com 2019 - 2024. All rights reserved.