Aspose.Words.Tables.Row类操作word表格行
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表格行的更多相关文章
- Aspose.Word 操作word表格的行 插入行 添加行
rows.insert或rows.add前row必须有单元格cell private void button3_Click(object sender, EventArgs e) { ...
- 黄聪:C#操作Word表格的常见操作(转)
几种常见C#操作Word表格操作有哪些呢?让我们来看看具体的实例演示: bool saveChange = false; //C#操作Word表格操作 object missing = System. ...
- 转发:VB程序操作word表格(文字、图片)
很多人都知道,用vb操作excel的表格非常简单,但是偏偏项目中碰到了VB操作word表格的部分,google.baidu搜爆了,都没有找到我需要的东西.到是搜索到了很多问这个问题的记录.没办法,索性 ...
- Java 操作Word表格——创建嵌套表格、添加/复制表格行或列、设置表格是否禁止跨页断行
本文将对如何在Java程序中操作Word表格作进一步介绍.操作要点包括 如何在Word中创建嵌套表格. 对已有表格添加行或者列 复制已有表格中的指定行或者列 对跨页的表格可设置是否禁止跨页断行 创建表 ...
- Java 操作Word表格
本文将对如何在Java程序中操作Word表格作进一步介绍.操作要点包括 如何在Word中创建嵌套表格. 对已有表格添加行或者列 复制已有表格中的指定行或者列 对跨页的表格可设置是否禁止跨页断行 创建表 ...
- c#操作word表格
http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...
- Delphi 操作word 表格
var wordApp, WordDoc, WrdSelection, wrdtable: variant; strAdd: string; wdPar,wdRange:OleVariant; iCo ...
- Aspose.Word 操作word复杂表格 拆分单元格 复制行 插入行 文字颜色
private void button3_Click(object sender, EventArgs e) { object savePathWord =&q ...
- C#中使用Spire.docx操作Word文档
使用docx一段时间之后,一些地方还是不方便,然后就尝试寻找一种更加简便的方法. 之前有尝试过使用Npoi操作word表格,但是太烦人了,随后放弃,然后发现免费版本的spire不错,并且在莫种程度上比 ...
随机推荐
- JAVA常见错误处理方法 和 JVM内存结构
OutOfMemoryError在开发过程中是司空见惯的,遇到这个错误,新手程序员都知道从两个方面入手来解决:一是排查程序是否有BUG导致内存泄漏:二是调整JVM启动参数增大内存.OutOfMemor ...
- Android 5.0 Uicc框架分析
已同步更新至个人blog: dxjia.cn Uicc框架 UICC框架是Android在4.1引入的,使的对卡的管理控制更加清晰.要了解这个UICC框架,需要从UiccController开始, ...
- [转载] A set of top Computer Science blogs
This started out as a list of top Computer Science blogs, but it more closely resembles a set: the o ...
- 在Linux下用源码编译安装apache2
Linux下安装一个软件,最好去看下它的官方guide,apache2.4的安装安装guide 0. installation guide http://httpd.apache.org/docs/2 ...
- C#集合 -- 自定义集合与代理
前面章节所讨论的集合都可以直接实例化,因此我们可以非常方便地使用这些集合类.但是如果你试图在集合添加或移除元素时添加控制,它们就不适用了.对于强类型集合,在某些情况下,你需要添加这样的控制: 添加或移 ...
- [原创]HierarchyView的实现原理和Android设备无法使用HierarchyView的解决方法
最近在看一个老外写的东西,发现里面有个类,使用这个类可以让任何设备使用HierarchyView. 众所周知,市面上卖的Android设备,一般都不能使用HierarchyView,所以借此机会,了解 ...
- (转)关于tcp和udp的缓冲区
(一)基础知识 IPv4 数据报最大大小是65535(16位),包括IPv4头部. IPv6 数据报最大大小是65575,包括40个字节的IPv4头部 MTU,这是由硬件规定的,如以太网的MTU是15 ...
- __get,__set
__get,__set 为php的magic方法,在类中定义为 public 类型. class UserModel { private $id; public $name; public funct ...
- 用SQL server导出到oracle,查询时提示“表或视图不存在ORA-00942”错误
用SQL server2005的导出工具,将数据导出表到oracle,表名称里看到有这张表了,但查询或删除时都提示“ORA-00942表或者试图不存在”的错误,上网查了一下,是如下原因: “查询或删除 ...
- 华为手机连不上adb解决方法
1.关闭qq,豌豆荚等一连接usb自动侦测手机的程序... 2.安装hisuite软件,这个应该跟相应的版本有关,新版本最好要安装这个软件,否则也可能导致怎么都连接不上 3.打开usb调试功能 4.a ...