首页 > 解决方案 > 如何在MS WORD c#中填写表格

问题描述

我需要从列表中填写 MS WORD 表格。我的行数不固定,我找不到 c# 的方法

标签: c#wpfms-word

解决方案


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

推荐阅读