轉帖|使用教程|編輯:李顯亮|2019-08-16 14:29:55.543|閱讀 1885 次
概述:本系列教程將為大家帶來Spire.Doc for .NET在使用過程中的各類實際操作,本篇文章介紹了如何設置 Word 表格的格式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一個專業的Word .NET庫,設計用于幫助開發人員高效地開發創建、閱讀、編寫、轉換和打印任何來自.NET( C#, VB.NET, ASP.NET)平臺的Word文檔文件的功能。
本系列教程將為大家帶來Spire.Doc for .NET在使用過程中的各類實際操作,本篇文章介紹了如何設置 Word 表格的格式。>>下載Spire.Doc最新試用版體驗
在Word文檔中,表格可以幫助我們清晰、直觀的分析和整理數據。一個表格通常至少包含一行,每行至少包含一個單元格,一個單元格可以包含多種元素如文本和表格(即嵌套表格)等。
添加和插入行
*添加和插入行
//載入文檔 Document document = new Document("Table.docx"); //獲取第一個節 Section section = document.Sections[0]; //獲取第一個表格 Table table = section.Tables[0] as Table; //添加一行到表格的最后 table.AddRow(true, 4); //插入一行到表格的第三行 table.Rows.Insert(2, table.AddRow()); //保存文檔 document.SaveToFile("AddRow.docx", FileFormat.Docx2013);
*添加列
//載入文檔 Document document = new Document("Table.docx"); //獲取第一個節 Section section = document.Sections[0]; //獲取第一個表格 Table table = section.Tables[0] as Table; //添加一列到表格,設置單元格的寬度和寬度類型 for (int i = 0; i < table.Rows.Count; i++) { TableCell cell = table.Rows[i].AddCell(true); cell.Width = table[0, 0].Width; cell.CellWidthType = table[0, 0].CellWidthType; } //保存文檔 document.SaveToFile("AddColumn.docx", FileFormat.Docx2013);
設置行高和列寬
//載入文檔 Document document = new Document("Table.docx"); //獲取第一個表格 Table table = document.Sections[0].Tables[0] as Table; //設置第一行的行高 table.Rows[0].Height = 40; for (int i = 0; i < table.Rows.Count; i++) { //設置第二列的列寬 table.Rows[i].Cells[1].Width = 40; } //保存文檔 document.SaveToFile("SetRowHeightAndColumnWidth.docx", FileFormat.Docx2013);
刪除行和列
//載入文檔 Document doc = new Document("Table.docx"); //獲取第一個表格 Table table = doc.Sections[0].Tables[0] as Table; //刪除第二行 table.Rows.RemoveAt(1); //刪除第二列 for (int i = 0; i < table.Rows.Count; i++) { table.Rows[i].Cells.RemoveAt(1); } //保存文檔 doc.SaveToFile("RemoveRowAndColumn.docx", FileFormat.Docx2013);
*購買Spire.Doc正版授權的朋友可以點擊哦~~
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn