Aspose.Words使用教程之表的合并与拆分

  Aspose.Words文档对象模型的表格由独立行和单元格组成,那样可以方便地实现加入或划分表格。

为了可以操作表格来与另外表格进行拆分与添加,我们只需要将一个表的行移动到另一个表里面即可。

两张表结合为一张表

注意:第二张表的行被转移到第一张表的末尾并且第二张表会被删除。

代码如下:

C#
// Load the document.
Document doc = new Document(MyDir + "Table.Document.doc");
// Get the first and second table in the document.
// The rows from the second table will be appended to the end of the first table.
Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);
Table secondTable = (Table)doc.GetChild(NodeType.Table, 1, true);
// Append all rows from the current table to the next.
// Due to the design of tables even tables with different cell count and widths can be joined into one table.
while (secondTable.HasChildNodes)
   firstTable.Rows.Add(secondTable.FirstRow);
// Remove the empty table container.
secondTable.Remove();
doc.Save(MyDir + "Table.CombineTables Out.doc");
Visual Basic
‘ Load the document.
Dim doc As New Document(MyDir & "Table.Document.doc")
‘ Get the first and second table in the document.
‘ The rows from the second table will be appended to the end of the first table.
Dim firstTable As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table)
Dim secondTable As Table = CType(doc.GetChild(NodeType.Table, 1, True), Table)
‘ Append all rows from the current table to the next.
‘ Due to the design of tables even tables with different cell count and widths can be joined into one table.
Do While secondTable.HasChildNodes
   firstTable.Rows.Add(secondTable.FirstRow)
Loop
‘ Remove the empty table container.
secondTable.Remove()
doc.Save(MyDir & "Table.CombineTables Out.doc")

拆分一张表为两张独立表:

注意:我们首先需要选择一个在哪儿分割表的行。一旦我们知道这个地方,遵循这些简单的步骤我们可以从原始表创建两张表:
   1.创建一个复制的表,然后从原始表移动行并且插入进这张表。
   2.从指定的行所有后续行移动到第二张表。
 
C#

// Load the document.
Document doc = new Document(MyDir + "Table.SimpleTable.doc");  
// Get the first table in the document.
Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);
// We will split the table at the third row (inclusive).   
Row row = firstTable.Rows[2];   
// Create a new container for the split table.   
Table table = (Table)firstTable.Clone(false);   
// Insert the container after the original.   
firstTable.ParentNode.InsertAfter(table, firstTable);   
// Add a buffer paragraph to ensure the tables stay apart.   
firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);   
Row currentRow;   
do   
{   
    currentRow = firstTable.LastRow;   
    table.PrependChild(currentRow);   }   
while 
(
   currentRow != row); 
   doc.Save(MyDir + "Table.SplitTable Out.doc");
Visual Basic
‘ Load the document.
Dim doc As New Document(MyDir & "Table.SimpleTable.doc")
‘ Get the first table in the document.
Dim firstTable As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table)
‘ We will split the table at the third row (inclusive).
Dim row As Row = firstTable.Rows(2)
‘ Create a new container for the split table.
Dim table As Table = CType(firstTable.Clone(False), Table)
‘ Insert the container after the original.
firstTable.ParentNode.InsertAfter(table, firstTable)
‘ Add a buffer paragraph to ensure the tables stay apart.
firstTable.ParentNode.InsertAfter(New Paragraph(doc), firstTable)
Dim currentRow As Row
Do
    currentRow = firstTable.LastRow
    table.PrependChild(currentRow)
Loop While currentRow IsNot row
doc.Save(MyDir & "Table.SplitTable Out.doc")

Aspose.Words最新版下载

时间: 2024-08-25 17:26:18

Aspose.Words使用教程之表的合并与拆分的相关文章

Aspose.Words使用教程之如何重命名合并字段

本文为Aspose.Words使用教程--重命名合并字段,什么是Aspose.Words呢?它是一款先进的文 档处理控件!有什么用呢?无需MS Word也可执行各种文档处理任务,包括文档的生成.修改.渲染.打印,文档格式转换和邮件合并等文档处理! 一个示例展示如何创建自己的合并字段类,代表一个在微软的Word文档中允许您获取或设置它的名称的合并字段. Example 如何在一个文档里重命名字段. C#  using System;   using System.Text;   using Sys

Aspose.Words使用教程之在文档中找到并替换文本

Aspose.Words使用教程之在文档中找到并替换文本 Aspose.Words是一款先进的文档处理控件,在不使用Microsoft Words的情况下,它可以使用户在各个应用程序中执行各种文档处理任务,其中包括文档的生成.修改.渲染.打印,文档格式转换和邮件合并等文档处理.此外,Aspose.Words支持DOC,OOXML,RTF,HTML,OpenDocument, PDF, XPS, EPUB和其他格式. 使用范围:在前的范围内替换查找或替换特定的字符串,因为它会返回替换的数量,所以它

Aspose.Words使用教程之如何写入纯文本(TXT)文件

Aspose.Words可以通过使用[Document]构造函数和其他文档格式一样输入纯文本数据. Example 输入一个纯文本文件到一个Aspose.Words文档对象里面. C# using System;   using System.IO;   using System.Reflection;using System.Text; using Aspose.Words; namespace LoadTxt   {   class Program   {   public static v

线性表算法-合并

线性表算法-合并

基础数据结构-线性表-顺序表的合并操作

因为最近笔记本B面裂了准备去修,复杂些的会优先加上注释,所以在家先把代码和题目贴上来以后补文字,有疑问可以在下面留言. 顺序表的合并操作 题目描述建立顺序表的类,属性包括:数组.实际长度.最大长度(设定为1000) 已知两个递增序列,把两个序列的数据合并到顺序表中,并使得顺序表的数据递增有序输入第1行先输入n表示有n个数据,接着输入n个数据,表示第1个序列,要求数据递增互不等 第2行先输入m表示有m个数据,接着输入m个数据,表示第2个序列,要求数据递增互不等输出顺序表内容包括顺序表的实际长度和数

非递减顺序表的合并

//顺序表的合并 //输入元素函数 put //输出元素函数 output //合并 Merge #include<stdio.h> #include<stdlib.h> #include<algorithm> using namespace std; #define LIST_INIT_SIZE 80 #define LISTINCREMENT 10 typedef struct { int *elem; int length; //有效长度 int size; //

MyEclipse数据库教程:表、外键和索引的使用方法

MyEclipse数据库教程:表.外键和索引的使用方法 MyEclipse的数据库资源管理器工具提供了大量的向导和操作,来轻松地创建和删除表.关系和索引.在本教程中,你将学习到: 创建和删除表 创建和删除外键 创建和删除索引 没有MyEclipse?立即下载 1. 创建一个新的索引 创建索引是开发人员重要的性能工具,典型的就是在DBMS上创建一个表的索引键.然而可能在其他领域中经常需要使用ORDER BY或WHERE子句来增强性能.假设您可能在CITY中有很多订购的客户,您可以在该领域中创建索引

队列链表实现以及有序表的合并

#include<iostream> #include<algorithm> using namespace std; typedef struct Node{ int data; Node *next; }LNode, *LinkList; void Creat(LinkList &L){ L = new Node; L->next = NULL; cout << "你已经成功创建了一个队列" << endl; } voi

DWZ(JUI) 教程 普通表单提交

原文:DWZ(JUI) 教程 普通表单提交 一类是普通的表单提交,另一类就是列表页面的表单提交,主要是用来查询搜索列表使用的.今天我就简单介绍一下前者. 这是官网上的普通列表页面, <div class="pageContent"> <form method="post" action="demo/common/ajaxDone.html" class="pageForm required-validate"