700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Word控件Spire.Doc 【Table】教程(17):如何在 C# VB.NET 中删除 Word 表格中的行和列

Word控件Spire.Doc 【Table】教程(17):如何在 C# VB.NET 中删除 Word 表格中的行和列

时间:2018-07-23 21:11:00

相关推荐

Word控件Spire.Doc 【Table】教程(17):如何在 C# VB.NET 中删除 Word 表格中的行和列

Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。

E-iceblue功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Spire.Doc 最新下载(qun 767755948)/product/3368/download

添加行和列是Word表格处理中的常见任务,相反,有时我们也有删除表格中的行或列的需求。本文演示如何使用 Spire.Doc 从现有 Word 表格中删除行和列。

下面是原始表格的屏幕截图。之后,我们将从表中删除彩色行和列。

详细步骤:

第 1 步:实例化一个 Document 对象并加载 Word 文档。

Document doc = new Document();doc.LoadFromFile("Sample.docx");

第 2 步:从文档中获取表格。

Table table = doc.Sections[0].Tables[0] as Table;

Table table = doc.Sections[0].Tables[0] as Table;

第 3 步:从表中删除第三行。

table.Rows.RemoveAt(2);

第 4 步:从表中删除第三列。

for (int i = 0; i < table.Rows.Count; i++){table.Rows[i].Cells.RemoveAt(2);}

第 5 步:保存文件。

doc.SaveToFile("result.docx",FileFormat.docx);

输出

完整代码

[C#]

using Spire.Doc;namespace Delete_Rows_and_Columns{class Program{static void Main(string[] args){Document doc = new Document();doc.LoadFromFile("Sample.docx");Table table = doc.Sections[0].Tables[0] as Table;table.Rows.RemoveAt(2);for (int i = 0; i < table.Rows.Count; i++){table.Rows[i].Cells.RemoveAt(2);}doc.SaveToFile("result.docx",FileFormat.docx);}}}

[]

Imports Spire.DocNamespace Delete_Rows_and_ColumnsClass ProgramPrivate Shared Sub Main(args As String())Dim doc As New Document()doc.LoadFromFile("Sample.docx")Dim table As Table = TryCast(doc.Sections(0).Tables(0), Table)table.Rows.RemoveAt(2)For i As Integer = 0 To table.Rows.Count - 1table.Rows(i).Cells.RemoveAt(2)Nextdoc.SaveToFile("result.docx",FileFormat.docx);End SubEnd ClassEnd Namespace

以上便是如何在 C#、 中删除 Word 表格中的行和列,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。