使用aspose找到表格节点,如何对找到的表格节点进行表格实例创建,同时对表格的第一行第一列进行读取?
2条回答 默认 最新
- CSDN专家-showbo 2022-02-23 15:39关注
简单示例如下
using System; using System.Collections.Generic; using System.Linq; using Aspose.Words; using Aspose.Words.Tables; namespace Aspose.Words { class Program { static void Main(string[] args) { var fn = @"C:\Users\Admin\Desktop\t.docx"; Document doc = new Document(fn); var tables = doc.GetChildNodes(NodeType.Table, true); foreach(Table table in tables) { Console.WriteLine(table.Rows[0].Cells[0].GetText());//获取第一行第一列的单元格,注意下标从0开始 if (table.Rows[0].Cells.Count > 1) {//第一行包含2个以上单元格 table.Rows[0].Cells[1].FirstParagraph.Runs.Clear();//清除第一行,第二列单元格的内容 table.Rows[0].Cells[1].FirstParagraph.AppendChild(new Run(doc, "动态更新表格一,行1,单元格2的值"));//更新第一行,第二列单元格的内容 } } Console.ReadKey(); } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用