Aspose.Word 操作word表格的行 插入行 添加行
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表格的行 插入行 添加行的更多相关文章
- Aspose.Words操作word生成PDF文档
Aspose.Words操作word生成PDF文档 using Aspose.Words; using System; using System.Collections.Generic; using ...
- Aspose.Word 操作word复杂表格 拆分单元格 复制行 插入行 文字颜色
private void button3_Click(object sender, EventArgs e) { object savePathWord =&q ...
- Aspose.Words 操作 Word 画 EChart 图
使用 Aspose.Words 插件在 Word 画 EChart 图 使用此插件可以画出丰富的 EChart 图,API 参考 https://reference.aspose.com/words/ ...
- C#使用Aspose.Words操作word文档
最近接到个需求,由于客服这边要导出大量有一定规则的word文件,里面的内容希望系统自动填充,例如 这里我使用Aspose.Words.dll这个类库, 1.首先,我们需要创建模板文件,毕竟有规则的东西 ...
- 在word中的表格指定位置插入一行
//创建一个Document类对象,并加载Word文档 Document doc = new Document(); doc.LoadFromFile(@"C:\Users\Administ ...
- Aspose.Words操作Word.PDF,让图片和文本垂直居中,水平居中解决方案
x 环境 { "Aspose.Words": {"Version":"18.x"} } 需求与难题 生成试卷的时候,如果数学题目中有特殊符号 ...
- java使用poi操作word, 支持动态的行(一个占位符插入多条)和表格中动态行, 支持图片
依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifa ...
- C# 操作Word文本框——插入表格/读取表格/删除表格
在文本框中,我们可以操作很多元素,如文本.图片.表格等,在本篇文章中将着重介绍如何插入表格到文本框,插入的表格我们可以对表格进行格式化操作来丰富表格内容.此外,对于文本框中的表格内容,我们也可以根据需 ...
- Java 操作Word表格——创建嵌套表格、添加/复制表格行或列、设置表格是否禁止跨页断行
本文将对如何在Java程序中操作Word表格作进一步介绍.操作要点包括 如何在Word中创建嵌套表格. 对已有表格添加行或者列 复制已有表格中的指定行或者列 对跨页的表格可设置是否禁止跨页断行 创建表 ...
随机推荐
- ECshop鼠标划过弹出 微信扫一扫代码
效果如上图 安装步骤:1,将以下代码放到page_header.lbi里 <div class="f_l"><a href="../index.p ...
- Difference between LET and LET* in Common LISP
Difference between LET and LET* in Common LISP LET Parallel binding which means the bindings com ...
- ASP.NET 4.0 forms authentication issues with IE11
As I mentioned earlier, solutions that rely on User-Agent sniffing may break, when a new browser or ...
- No Assistant Results
由于修改一些文件名字等会导致这个不工作. "Organizer" / "Projects" / 选择你的项目. "Delete" .
- Winform 数据库连接app.config文件配置 数据库连接字符串
1.添加配置文件 新建一个winform应用程序,类似webfrom下有个web.config,winform下也有个App.config;不过 App.config不是自动生成的需要手动添加,鼠标右 ...
- AX ERP 真正的自动批处理
AX real batch job- AX ERP 真正的批处理 在AX3标准功能中,自动化任务是利用Batch来进行自动化处理任务,标准功能的局限是无法真正做到无人值守.比如服务器重启,必须手动去开 ...
- UNIX环境高级编程笔记之线程
本章涉及到线程的一些基本知识点,讨论了现有的创建线程和销毁线程的POSIX.1原语,此外,重点介绍了线程同步问题,讨论了三种基本的同步机制:互斥量.读写锁.条件变量.
- java之抽象类
1.用abstract关键字来修饰一个类时,这个类叫做抽象类:用abstract来修饰一个方法时,该方法叫做抽象方法. 2.含有抽象方法的类必须被声明抽象类,抽象类必须被继承,抽象方法必须被重写. 3 ...
- MSIL 教程(三):类和异常处理(转)
转自:http://www.cnblogs.com/Yahong111/archive/2007/08/16/857771.html 续上文[翻译]MSIL 教程(二):数组.分支.循环.使用不安全代 ...
- VS2012未找到与约束ContractName...匹配的导出
用VS2012创建ARCGIS插件项目时,提示“未找到与约束ContractName...匹配的导出”,此前一直都是正常的额 经查,发现是近期系统相关更新导致,解决办法有两种途径: 一是删除近期更新的 ...