翻譯|使用教程|編輯:胡濤|2023-02-20 10:33:02.540|閱讀 215 次
概述:本文演示如何使用 Spire.Doc 從現有 Word 表格中刪除行和列。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
添加行和列是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.docx2013);
輸出:
完整代碼:
[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.docx2013); } } }
[VB.NET]
Imports Spire.Doc Namespace Delete_Rows_and_Columns Class Program Private 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 - 1 table.Rows(i).Cells.RemoveAt(2) Next doc.SaveToFile("result.docx",FileFormat.docx2013); End Sub End Class End Namespace
以上便是如何在 C#、VB.NET 中刪除 Word 表格中的行和列,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn