网站首页 > 开源技术 正文
Aspose.Words For .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
在Word文档和Aspose.Words文档对象模型中,没有列的概念。按照设计,Microsoft Word中的表行完全独立,基本属性和操作仅包含在表的行和单元格中。这为表提供了一些有趣属性的可能性:
- 表中的每一行可以具有完全不同数量的单元格。
- 垂直地,每行的单元格可以具有不同的宽度。
- 可以连接具有不同行格式和单元格计数的表。
对Microsoft Word中的列执行的任何操作实际上都是“快捷方法”,它通过共同修改行的单元格来执行操作,使得它们看起来应用于列。在Aspose.Words文档对象模型中, Table 节点由 Row 和 Cell 节点组成。列也没有本机支持。
通过遍历表的行的相同单元索引来对列实现此类操作,下面的代码通过证明一个fa?ade类来收集组成表的“列”的单元格,从而使这些操作更容易。下面的示例演示了一个用于处理表的列的Facade对象。
/// ///表示Microsoft Word文档中表的列的Facade对象。 /// internal class Column { private Column(Table table, int columnIndex) { if (table == null) throw new ArgumentException("table"); mTable = table; mColumnIndex = columnIndex; } /// /// 从表中返回一个新的列Facade,并提供从零开始的索引。 /// public static Column FromIndex(Table table, int columnIndex) { return new Column(table, columnIndex); } /// /// 返回组成列的单元格。 /// public Cell[] Cells { get { return (Cell[])GetColumnCells().ToArray(typeof(Cell)); } } /// ///返回列中给定单元格的索引。 /// public int IndexOf(Cell cell) { return GetColumnCells().IndexOf(cell); } /// ///在此列之前插入一个全新的列到表中。 /// public Column InsertColumnBefore() { Cell[] columnCells = Cells; if (columnCells.Length == 0) throw new ArgumentException("Column must not be empty"); //创建此列的克隆。 foreach (Cell cell in columnCells) cell.ParentRow.InsertBefore(cell.Clone(false), cell); //这是新专栏. Column column = new Column(columnCells[0].ParentRow.ParentTable, mColumnIndex); //我们希望确保单元格都可以使用(至少有一个段落)。 foreach (Cell cell in column.Cells) cell.EnsureMinimum(); // 增加此列表示的索引,因为现在有一个额外的列前面。 mColumnIndex++; return column; } /// ///从表中删除列。 /// public void Remove() { foreach (Cell cell in Cells) cell.Remove(); } /// /// 返回列的文本。 /// public string ToTxt() { StringBuilder builder = new StringBuilder(); foreach (Cell cell in Cells) builder.Append(cell.ToString(SaveFormat.Text)); return builder.ToString(); } /// ///提供构成此外观所代表的列的最新单元格集合。 /// private ArrayList GetColumnCells() { ArrayList columnCells = new ArrayList(); foreach (Row row in mTable.Rows) { Cell cell = row.Cells[mColumnIndex]; if (cell != null) columnCells.Add(cell); } return columnCells; } private int mColumnIndex; private Table mTable; }
下面的示例显示如何将空白列插入表中:
//获取文档中的第一个表. Table table = (Table)doc.GetChild(NodeType.Table, 0, true); // 获取表格中的第二列. Column column = Column.FromIndex(table, 0); //将列的纯文本打印到屏幕. Console.WriteLine(column.ToTxt()); //在此列的左侧创建一个新列. //这与在Microsoft Word中使用“Insert Column Before”命令相同. Column newColumn = column.InsertColumnBefore(); //为每个列单元格添加一些文本. foreach (Cell cell in newColumn.Cells) cell.FirstParagraph.AppendChild(new Run(doc, "Column Text " + newColumn.IndexOf(cell)));
下面的示例演示如何从文档中的表中删除列:
//获取文档中的第二个表. Table table = (Table)doc.GetChild(NodeType.Table, 1, true); //从表中获取第三列并将其删除. Column column = Column.FromIndex(table, 2); column.Remove();
点击下方“了解更多”免费下载Aspose.Words For .Net
↓↓↓
猜你喜欢
- 2024-10-12 使用Aspose.Word将报表导出为Word文档
- 2024-10-12 SpringBoot 将外部引入的Jar包打进Jar包中
- 2024-10-12 在 Python 中将 HTML 转换为 PNG、JPEG、BMP、GIF 或 TIFF 图像
- 2024-10-12 为什么Aspose文档控件备受开发者喜欢?
- 2024-10-12 Word处理控件Aspose.Words如何在 Java 中将 DOC 或 DOCX 转换为 JPG
- 2024-10-12 文档开发工具Aspose.Wordsv20.9四大新功能演示
- 2024-10-12 Word处理控件Aspose.Words for Java 8月新版发布!支持Java 12
- 2024-10-12 java如何生成动态Word文件(java动态生成word文档)
- 2024-10-12 Word文档管理首选工具Aspose.Words for .NET完整功能一览
- 2024-10-12 如何使用Aspose.Words以编程方式处理文档部分(1)
你 发表评论:
欢迎- 03-19基于layui+springcloud的企业级微服务框架
- 03-19开箱即用的前端开发模板,扩展Layui原生UI样式,集成第三方组件
- 03-19SpringMVC +Spring +Mybatis + Layui通用后台管理系统OneManageV2.1
- 03-19SpringBoot+LayUI后台管理系统开发脚手架
- 03-19layui下拉菜单form.render局部刷新方法亲测有效
- 03-19Layui 遇到的坑(记录贴)(layui chm)
- 03-19基于ASP.NET MVC + Layui的通用后台开发框架
- 03-19LayUi自定义模块的定义与使用(layui自定义表格)
- 最近发表
-
- 基于layui+springcloud的企业级微服务框架
- 开箱即用的前端开发模板,扩展Layui原生UI样式,集成第三方组件
- SpringMVC +Spring +Mybatis + Layui通用后台管理系统OneManageV2.1
- SpringBoot+LayUI后台管理系统开发脚手架
- layui下拉菜单form.render局部刷新方法亲测有效
- Layui 遇到的坑(记录贴)(layui chm)
- 基于ASP.NET MVC + Layui的通用后台开发框架
- LayUi自定义模块的定义与使用(layui自定义表格)
- Layui 2.9.11正式发布(layui2.6)
- Layui 2.9.13正式发布(layui2.6)
- 标签列表
-
- jdk (81)
- putty (66)
- rufus (78)
- 内网穿透 (89)
- okhttp (70)
- powertoys (74)
- windowsterminal (81)
- netcat (65)
- ghostscript (65)
- veracrypt (65)
- asp.netcore (70)
- wrk (67)
- aspose.words (80)
- itk (80)
- ajaxfileupload.js (66)
- sqlhelper (67)
- express.js (67)
- phpmailer (67)
- xjar (70)
- redisclient (78)
- wakeonlan (66)
- tinygo (85)
- startbbs (72)
- webftp (82)
- vsvim (79)
本文暂时没有评论,来添加一个吧(●'◡'●)