翻譯|使用教程|編輯:胡濤|2023-02-20 10:33:02.540|閱讀 215 次
概述:本文演示如何使用 Spire.Doc 從現(xiàn)有 Word 表格中刪除行和列。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時(shí)適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
添加行和列是Word表格處理中的常見任務(wù),相反,有時(shí)我們也有刪除表格中的行或列的需求。本文演示如何使用 Spire.Doc 從現(xiàn)有 Word 表格中刪除行和列。
下面是原始表格的屏幕截圖。之后,我們將從表中刪除彩色行和列。
詳細(xì)步驟:
第 1 步:實(shí)例化一個(gè) 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 表格中的行和列,如果您有其他問題也可以繼續(xù)瀏覽本系列文章,獲取相關(guān)教程,你還可以給我留言或者加入我們的官方技術(shù)交流群。
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn