rows.insert或rows.add前row必须有单元格cell

private void button3_Click(object sender, EventArgs e)

{
            object savePathWord ="row.docx";
            File.Copy("rowtemplate.docx", savePathWord.ToString(),true);

Aspose.Words.Document doc = new Aspose.Words.Document(savePathWord.ToString());
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);

NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true); //拿到所有表格
            Aspose.Words.Tables.Table table = allTables[1] as Aspose.Words.Tables.Table; //拿到第二个表格

var row=CreateRow(3,(new string[]{"1","2","3"}),doc); //创建一行
            table.Rows.Insert(1,row); //将此行插入第一行的上方

Aspose.Words.Tables.Row r2 = new Aspose.Words.Tables.Row(doc);
            Aspose.Words.Tables.Cell c21 = new Aspose.Words.Tables.Cell(doc);
            Aspose.Words.Tables.Cell c22 = new Aspose.Words.Tables.Cell(doc);
            Aspose.Words.Tables.Cell c23 = new Aspose.Words.Tables.Cell(doc);            
            Aspose.Words.Paragraph p = new Paragraph(doc);
            p.AppendChild(new Run(doc, "测试"));
            c21.AppendChild(p);
            r2.Cells.Add(c21);
            r2.Cells.Add(c22);
            r2.Cells.Add(c23);
            table.Rows.Add(r2); //添加一行

doc.Save(savePathWord.ToString());
            MessageBox.Show("ok");

}

Aspose.Words.Tables.Cell CreateCell(string value,Document doc)
        {
            Aspose.Words.Tables.Cell c1 = new Aspose.Words.Tables.Cell(doc);
            Aspose.Words.Paragraph p = new Paragraph(doc);
            p.AppendChild(new Run(doc,value));
            c1.AppendChild(p);
            return c1;
        }

Aspose.Words.Tables.Row CreateRow(int columnCount,string[] columnValues,Document doc)
        {
            Aspose.Words.Tables.Row r2 = new Aspose.Words.Tables.Row(doc);
            for (int i = 0; i < columnCount; i++)
            {
                if (columnValues.Length >i)
                {
                    var cell = CreateCell(columnValues[i], doc);
                    r2.Cells.Add(cell);
                }
                else
                {
                    var cell = CreateCell("", doc);
                    r2.Cells.Add(cell);
                }
                
            }
            return r2;

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Aspose.Word 操作word表格的行 插入行 添加行的更多相关文章

  1. Aspose.Words操作word生成PDF文档

    Aspose.Words操作word生成PDF文档 using Aspose.Words; using System; using System.Collections.Generic; using ...

  2. Aspose.Word 操作word复杂表格 拆分单元格 复制行 插入行 文字颜色

    private void button3_Click(object sender, EventArgs e)         {             object savePathWord =&q ...

  3. Aspose.Words 操作 Word 画 EChart 图

    使用 Aspose.Words 插件在 Word 画 EChart 图 使用此插件可以画出丰富的 EChart 图,API 参考 https://reference.aspose.com/words/ ...

  4. C#使用Aspose.Words操作word文档

    最近接到个需求,由于客服这边要导出大量有一定规则的word文件,里面的内容希望系统自动填充,例如 这里我使用Aspose.Words.dll这个类库, 1.首先,我们需要创建模板文件,毕竟有规则的东西 ...

  5. 在word中的表格指定位置插入一行

    //创建一个Document类对象,并加载Word文档 Document doc = new Document(); doc.LoadFromFile(@"C:\Users\Administ ...

  6. Aspose.Words操作Word.PDF,让图片和文本垂直居中,水平居中解决方案

    x 环境 { "Aspose.Words": {"Version":"18.x"} } 需求与难题 生成试卷的时候,如果数学题目中有特殊符号 ...

  7. java使用poi操作word, 支持动态的行(一个占位符插入多条)和表格中动态行, 支持图片

    依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifa ...

  8. C# 操作Word文本框——插入表格/读取表格/删除表格

    在文本框中,我们可以操作很多元素,如文本.图片.表格等,在本篇文章中将着重介绍如何插入表格到文本框,插入的表格我们可以对表格进行格式化操作来丰富表格内容.此外,对于文本框中的表格内容,我们也可以根据需 ...

  9. Java 操作Word表格——创建嵌套表格、添加/复制表格行或列、设置表格是否禁止跨页断行

    本文将对如何在Java程序中操作Word表格作进一步介绍.操作要点包括 如何在Word中创建嵌套表格. 对已有表格添加行或者列 复制已有表格中的指定行或者列 对跨页的表格可设置是否禁止跨页断行 创建表 ...

随机推荐

  1. Difference between Satisfiable, Valid, Unsatisfiable & Invalid

    A formula is satisfiable if it is possible to find an interpretation (model) that makes the formula  ...

  2. Solr4:数据导入(dataimport)时,不符合Solr日期类型要求的字段的处理

    背景: 要求将一个SQL Server2012版本中的数据库导入到Solr中.数据表中有一字段用来存储birthday日期字段,为nvarchar类型,长度为8,格式为:yyyyMMdd. 导入Sol ...

  3. iOS CoreData技术学习资源汇总

    一.CoreData学习指引 1. 苹果官方:Core Data Programming Guide 什么是CoreData? 创建托管对象模型 初始化Core Data堆栈 提取对象 创建和修改自定 ...

  4. SOA架构改造简单记录

    前端支持PC.Mobile.H5三个平台 nginx做负载均衡,主备机,keepalived,检测脚本,master和slave切换时完成相关工作: web做集群,web仅仅是web,与后端服务模块采 ...

  5. JIT

    http://www.cppblog.com/vczh/category/9583.html

  6. bash + script

    shell "" 保留$,`,\, 换行含义,‘’保留字面值 $(), ``用于命令替换 算术扩展如 $[1+1] for循环: for Host in host1, host2, ...

  7. PowerDesigner 16.5对SQL Server 2012 生成数据库时"不支持扩展属性"问题

    团队合作设计一套系统数据模型,创建了PDM后,Table.View.Store Procedure等都创建好了,且创建了多个Schema方便管理这些数据库对象,但Table.view.Column等对 ...

  8. Subgradient Algorithm

    Subgradient是一种可以优化不可微的凸函数的方法. 首先回顾凸函数的定义: $f(y) \geq f(x) + \nabla f(x)^T(y-x), all \hspace{2 pt} x, ...

  9. Word2010撤销按钮失效,Ctrl+Z失效解决办法

    1.打开注册表编辑器.按Win+R,在运行框中键入regedit,然后单击“确定”. 2.在注册表编辑器中,展开到下列注册表子项: HKEY_CURRENT_USER\Software\Microso ...

  10. apache+tomcat整合后的编码问题

    apache+tomcat整合提供webserver服务的方式是为了实现两个目的:一是方便利用apache http server将客户请求均衡的分给tomcat1,tomcat2....去处理,即负 ...