彩票走势图

Aspose.Words使用方法:插入现有表格的复制

原创|其它|编辑:郝浩|2012-10-19 17:26:14.000|阅读 6528 次

概述:有时在文档中已经存在一个一个表格,但是如果想添加一个复制的表然后应用一些修改,最简单的方法就是......

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

在使用Aspose.Words时,有时在文档中已经存在一个一个表格,但是如果想添加一个复制的表然后应用一些修改,最简单的方法就是:

C#

Document doc = new Document(MyDir + "Table.SimpleTable.doc");

// Retrieve the first table in the document.
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

// Create a clone of the table.
Table tableClone = (Table)table.Clone(true);

// Insert the cloned table into the document after the original
table.ParentNode.InsertAfter(tableClone, table);

// Insert an empty paragraph between the two tables or else they will be combined into one
// upon save. This has to do with document validation.
table.ParentNode.InsertAfter(new Paragraph(doc), table);

doc.Save(MyDir + "Table.CloneTableAndInsert Out.doc");

Visual Basic

Dim doc As New Document(MyDir & "Table.SimpleTable.doc")

' Retrieve the first table in the document.
Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table)

' Create a clone of the table.
Dim tableClone As Table = CType(table.Clone(True), Table)

' Insert the cloned table into the document after the original
table.ParentNode.InsertAfter(tableClone, table)

' Insert an empty paragraph between the two tables or else they will be combined into one
' upon save. This has to do with document validation.
table.ParentNode.InsertAfter(New Paragraph(doc), table)

doc.Save(MyDir & "Table.CloneTableAndInsert Out.doc")
 

如果新表包含不同的内容,你需要首先清除现有表中的内容。

C#

foreach (Cell cell in tableClone.GetChildNodes(NodeType.Cell, true))
    cell.RemoveAllChildren();

Visual Basic

For Each cell As Cell In tableClone.GetChildNodes(NodeType.Cell, True)
    cell.RemoveAllChildren()
Next cell

同样的技术可以用来添加副本的一个现有的行到一个表中。

C#

Document doc = new Document(MyDir + "Table.SimpleTable.doc");

// Retrieve the first table in the document.
Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

// Clone the last row in the table.
Row clonedRow = (Row)table.LastRow.Clone(true);

// Remove all content from the cloned row's cells. This makes the row ready for
// new content to be inserted into.
foreach (Cell cell in clonedRow.Cells)
    cell.RemoveAllChildren();

// Add the row to the end of the table.
table.AppendChild(clonedRow);

doc.Save(MyDir + "Table.AddCloneRowToTable Out.doc");
 

Visual Basic

Dim doc As New Document(MyDir & "Table.SimpleTable.doc")

' Retrieve the first table in the document.
Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table)

' Clone the last row in the table.
Dim clonedRow As Row = CType(table.LastRow.Clone(True), Row)

' Remove all content from the cloned row's cells. This makes the row ready for
' new content to be inserted into.
For Each cell As Cell In clonedRow.Cells
    cell.RemoveAllChildren()
Next cell

' Add the row to the end of the table.
table.AppendChild(clonedRow)

doc.Save(MyDir & "Table.AddCloneRowToTable Out.doc")

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP