首先请查看原词表:

注意:开始之前,请下载最新版本的Spire.Doc,并在bin文件夹中添加Spire.Doc.dll作为Visual Studio的引用。
第 1 步:创建一个新的 word 文档并从文件中加载该文档。
Document doc = new Document();doc.LoadFromFile("sample.docx");
第 2 步:从word文档中获取第一个表格。
Table table = doc.Sections[0].Tables[0] as Spire.Doc.Table;
第 3 步:插入一个新行作为第三行。
TableRow row = table.AddRow();table.Rows.Insert(2, row);
第 4 步:在表的末尾添加两行,一行有格式,另一行没有格式。
table.AddRow(true,2);table.AddRow(false, 2);
第 5 步:将文档保存到文件并设置其文件格式。
doc.SaveToFile("Result.docx",FileFormat.Docx2013);
word表格添加行后的有效截图:

完整代码:
using Spire.Doc;namespace AddRow{ class Program { static void Main(string[] args) { Document doc = new Document(); doc.LoadFromFile("sample.docx"); Table table = doc.Sections[0].Tables[0] as Spire.Doc.Table; //Insert a new row as the third row TableRow row = table.AddRow(); table.Rows.Insert(2, row); //Add two rows at the end of the table table.AddRow(true, 2); table.AddRow(false, 2); doc.SaveToFile("Result.docx", FileFormat.Docx2013); } }}
以上便是如何在 C# 中向现有的 word 表添加一行,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询在线客服 ;
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!