http://www.aspose.com/docs/display/wordsnet/Aspose.Words.Tables.Row+Class

Retrieves the index of a row in a table.

获得行索引

[C#]

int rowIndex = table.IndexOf(row);

Shows how to make a clone of the last row of a table and append it to the table.

克隆最后一行并添加到表格

[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");

Shows how to iterate through all tables in the document and display the content from each cell.

遍历所有表格并显示每个单元格的内容

[C#]

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

// Here we get all tables from the Document node. You can do this for any other composite node
// which can contain block level nodes. For example you can retrieve tables from header or from a cell
// containing another table (nested tables).
NodeCollection tables = doc.GetChildNodes(NodeType.Table, true); // Iterate through all tables in the document
foreach (Table table in tables)
{
// Get the index of the table node as contained in the parent node of the table
int tableIndex = table.ParentNode.ChildNodes.IndexOf(table);
Console.WriteLine("Start of Table {0}", tableIndex); // Iterate through all rows in the table
foreach (Row row in table.Rows)
{
int rowIndex = table.Rows.IndexOf(row);
Console.WriteLine("\tStart of Row {0}", rowIndex); // Iterate through all cells in the row
foreach (Cell cell in row.Cells)
{
int cellIndex = row.Cells.IndexOf(cell);
// Get the plain text content of this cell.
string cellText = cell.ToString(SaveFormat.Text).Trim();
// Print the content of the cell.
Console.WriteLine("\t\tContents of Cell:{0} = \"{1}\"", cellIndex, cellText);
}
//Console.WriteLine();
Console.WriteLine("\tEnd of Row {0}", rowIndex);
}
Console.WriteLine("End of Table {0}", tableIndex);
Console.WriteLine();
}

Shows how to build a nested table without using DocumentBuilder.

不用documentbuilder类创建嵌套表格

[C#]

public void NestedTablesUsingNodeConstructors()
{
Document doc = new Document(); // Create the outer table with three rows and four columns.
Table outerTable = CreateTable(doc, 3, 4, "Outer Table");
// Add it to the document body.
doc.FirstSection.Body.AppendChild(outerTable); // Create another table with two rows and two columns.
Table innerTable = CreateTable(doc, 2, 2, "Inner Table");
// Add this table to the first cell of the outer table.
outerTable.FirstRow.FirstCell.AppendChild(innerTable); doc.Save(MyDir + "Table.CreateNestedTable Out.doc"); Assert.AreEqual(2, doc.GetChildNodes(NodeType.Table, true).Count); // ExSkip
} /// <summary>
/// Creates a new table in the document with the given dimensions and text in each cell.
/// </summary>
private Table CreateTable(Document doc, int rowCount, int cellCount, string cellText)
{
Table table = new Table(doc); // Create the specified number of rows.
for (int rowId = 1; rowId <= rowCount; rowId++)
{
Row row = new Row(doc);
table.AppendChild(row); // Create the specified number of cells for each row.
for (int cellId = 1; cellId <= cellCount; cellId++)
{
Cell cell = new Cell(doc);
row.AppendChild(cell);
// Add a blank paragraph to the cell.
cell.AppendChild(new Paragraph(doc)); // Add the text.
cell.FirstParagraph.AppendChild(new Run(doc, cellText));
}
} return table;
}

Shows how to insert a table using the constructors of nodes.

使用节点构造函数创建表格

[C#]

Document doc = new Document();

// We start by creating the table object. Note how we must pass the document object
// to the constructor of each node. This is because every node we create must belong
// to some document.
Table table = new Table(doc);
// Add the table to the document.
doc.FirstSection.Body.AppendChild(table); // Here we could call EnsureMinimum to create the rows and cells for us. This method is used
// to ensure that the specified node is valid, in this case a valid table should have at least one
// row and one cell, therefore this method creates them for us. // Instead we will handle creating the row and table ourselves. This would be the best way to do this
// if we were creating a table inside an algorthim for example.
Row row = new Row(doc);
row.RowFormat.AllowBreakAcrossPages = true;
table.AppendChild(row); // We can now apply any auto fit settings.
table.AutoFit(AutoFitBehavior.FixedColumnWidths); // Create a cell and add it to the row
Cell cell = new Cell(doc);
cell.CellFormat.Shading.BackgroundPatternColor = Color.LightBlue;
cell.CellFormat.Width = 80; // Add a paragraph to the cell as well as a new run with some text.
cell.AppendChild(new Paragraph(doc));
cell.FirstParagraph.AppendChild(new Run(doc, "Row 1, Cell 1 Text")); // Add the cell to the row.
row.AppendChild(cell); // We would then repeat the process for the other cells and rows in the table.
// We can also speed things up by cloning existing cells and rows.
row.AppendChild(cell.Clone(false));
row.LastCell.AppendChild(new Paragraph(doc));
row.LastCell.FirstParagraph.AppendChild(new Run(doc, "Row 1, Cell 2 Text")); doc.Save(MyDir + "Table.InsertTableUsingNodes Out.doc");

Aspose.Words.Tables.Row类操作word表格行的更多相关文章

  1. Aspose.Word 操作word表格的行 插入行 添加行

    rows.insert或rows.add前row必须有单元格cell private void button3_Click(object sender, EventArgs e) {         ...

  2. 黄聪:C#操作Word表格的常见操作(转)

    几种常见C#操作Word表格操作有哪些呢?让我们来看看具体的实例演示: bool saveChange = false; //C#操作Word表格操作 object missing = System. ...

  3. 转发:VB程序操作word表格(文字、图片)

    很多人都知道,用vb操作excel的表格非常简单,但是偏偏项目中碰到了VB操作word表格的部分,google.baidu搜爆了,都没有找到我需要的东西.到是搜索到了很多问这个问题的记录.没办法,索性 ...

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

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

  5. Java 操作Word表格

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

  6. c#操作word表格

    http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...

  7. Delphi 操作word 表格

    var wordApp, WordDoc, WrdSelection, wrdtable: variant; strAdd: string; wdPar,wdRange:OleVariant; iCo ...

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

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

  9. C#中使用Spire.docx操作Word文档

    使用docx一段时间之后,一些地方还是不方便,然后就尝试寻找一种更加简便的方法. 之前有尝试过使用Npoi操作word表格,但是太烦人了,随后放弃,然后发现免费版本的spire不错,并且在莫种程度上比 ...

随机推荐

  1. BW标准数据源初始化设置

    在安装了一干补丁和做好了BW与R3的链接之后(此处有BISIS操心,具体事宜不详),我们就可以登录到R3系统看个究竟了. 磨刀不误砍柴工,先检查一下两边系统的补丁: R3端如下, ,貌似我们是19,通 ...

  2. A/B测试

    昨天把前段时间开发的二胡调音器的应用发布到了亚马逊应用程序商店,看到了一个A/B测试的标签,了解一下A/B测试的工作原理. A/B测试是一种新兴的网页优化方法,可以用于增加转化率注册率等网页指标. 使 ...

  3. python use dom to write xml file

    #encoding:utf-8 ''' write xml in dom style ''' from xml.dom.minidom import Document doc = Document() ...

  4. struts2:struts.xml配置文件详解

    1. 几个重要的元素 1.1 package元素 package元素用来配置包.在Struts2框架中,包是一个独立的单位,通过name属性来唯一标识包.还可以通过extends属性让一个包继承另一个 ...

  5. Maven3路程(四)用Maven创建Struts2项目

    采用struts版本:struts-2.3.8 一.创建一个web项目 参考前面文章,项目名:maven-struts-demo. 二.配置pom.xml文件添加struts2依赖 <proje ...

  6. EvreryDay Collect

    1.在使用WebService时我们经常会考虑以下问题:怎么防止别人访问我的WebService? 在System.Net中提供了一个NetworkCredential,只有获得该凭证的用户才能访问相 ...

  7. WinStore控件之Button、HyperlinkButton、RadioButton、CheckBox、progressBar、ScrollViewer、Slider

    1.Button protected override void OnNavigatedTo(NavigationEventArgs e) { /* * Button - 按钮控件,其全部功能是通过其 ...

  8. UML3

    在UML系统开发中有三个主要的模型: 功能模型: 从用户的角度展示系统的功能,包括用例图. 对象模型: 采用对象,属性,操作,关联等概念展示系统的结构和基础,包括类图. 动态模型: 展现系统的内部行为 ...

  9. [转]SharePoint开发中可能用到的各种Context(上下文)

    SharePoint是一个B/S结构的产品,所以在开发过程中会使用到各种各样的上下文(Context)信息,借此机会来总结一下.特别是Javascript的Ctx非常实用,这里记录一下! 一.Http ...

  10. nginx rewrite重写与防盗链配置

    nginx rewrite重写规则与防盗链配置方法 时间:2016-02-04 15:16:58来源:网络 导读:nginx rewrite重写规则与防盗链配置方法,rewrite规则格式中flag标 ...