如何使用C#在Windows Word中制作表格的副本

如何使用C#在Windows Word中制作表格的副本

问题描述:


我想使用C#在寡妇字中复制现有表格.任何想法?


谢谢!
Soumya

Hi,
I would like to make a copy of an existing table in widows word using C#.Any ideas??


Thanks!
Soumya

以下C#代码将帮助您使用Office interop assebly复制现有表:

Below C# code will help you to copy the existing table using Office interop assebly:

using Microsoft.Office.Interop.Word;

Word.Range range = table.Range; 
range.Copy();  

Word.Range rng = table.Range; 
rng.SetRange(table.Range.End, table.Range.End);  

Word.Table tableCopy = document.Tables.Add(rng, 1, 1, ref missing, ref missing); 
tableCopy.Range.Paste();  


//docTable是表1
//tableCopy是表2,它是表1的副本

范围范围= docTable.Range;
range.Copy();
range.SetRange(docTable.Range.End +1,docTable.Range.End +1);

表格tableCopy = doc.Tables.Add(rng,1,1,缺少参考,缺少参考);
tableCopy.Range.Paste();
// docTable is the Table 1
// tableCopy is the Table 2 which is the Replica of Table 1

Range range = docTable.Range;
range.Copy();
range.SetRange(docTable.Range.End + 1, docTable.Range.End + 1);

Table tableCopy = doc.Tables.Add(rng, 1, 1, ref missing, ref missing);
tableCopy.Range.Paste();