Bri*_*ley 5 c# docx novacode-docx
我使用C#制作一个简单的Windows应用程序,使用Novacode来操作Word文档.
我在我的Word文档中有一个我想要克隆的源表.我可以使用以下代码找到源表:
Table sourceTable = document.Tables[3];
Run Code Online (Sandbox Code Playgroud)
我可以通过行和列看到这实际上是我要克隆的表.
我的Word文档中有一个字符串,就在它之后我想插入克隆的源表.事实上,我可能需要不止一次插入它.
我不知道如何找到我的字符串,它的索引,然后在该索引处插入一个或多个克隆表.
谢谢.
小智 9
我是这样做的,我使用一个标签,我插入并替换为表:
// Add a Table to this document.
var table = document.AddTable(2, 3);
// Specify some properties for this Table.
table.Alignment = Alignment.center;
// Add content to this Table.
table.Rows[0].Cells[0].Paragraphs.First().Append("A");
table.Rows[0].Cells[1].Paragraphs.First().Append("B");
table.Rows[0].Cells[2].Paragraphs.First().Append("C");
table.Rows[1].Cells[0].Paragraphs.First().Append("D");
table.Rows[1].Cells[1].Paragraphs.First().Append("E");
table.Rows[1].Cells[2].Paragraphs.First().Append("F");
// Insert table at index where tag #TABLE# is in document.
document.InsertTable(table));
foreach (var paragraph in document.Paragraphs)
{
paragraph.FindAll("#TABLE#").ForEach(index => paragraph.InsertTableAfterSelf((table)));
}
//Remove tag
document.ReplaceText("#TABLE#", "");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5459 次 |
| 最近记录: |