c#asposeWord表格操作

使用aspose找到表格节点,如何对找到的表格节点进行表格实例创建,同时对表格的第一行第一列进行读取?

简单示例如下

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();
        }
    }
}
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632