Aspose.Words的Table, Row,
Cell三级对象,依次实现对表格、表格行、行内列单元的三级封装处理。
Aspose.Words -
表格行复制、插入及编辑
1 Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| using Aspose.Words; using Aspose.Words.Tables; using System; using System.Text.RegularExpressions;
namespace TableTest { class Program { static string MyDir = "C:\\Dev\\Test\\"; static void Main(string[] args) { Document doc = new Document(MyDir + "in.docx");
Table table = (Table)doc.GetChild(NodeType.Table, 1, true);
int rowCount = 0; foreach (Row row in table.Rows) { if(rowCount == 1) { Row rowClone = (Row)row.Clone(true);
row.Range.Replace(new Regex("__newName__"), "Name1"); row.Range.Replace(new Regex("__newPrice__"), "111");
row.ParentNode.InsertAfter(rowClone, row); } rowCount++; } doc.Save(MyDir + "out.docx"); } } }
|