Click here to Skip to main content
16,018,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I would like to make a copy of an existing table in widows word using C#.Any ideas??


Thanks!
Soumya
Posted
Updated 23-Feb-12 19:42pm
v2

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

C#
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();  
 
Share this answer
 
Comments
Soumya Joseph 27-Feb-12 1:13am    
Thanks for the Code.I would like to give a suggestion to ur code.
We need to increment the range of the Table 1 So as to give a break in between the Table 1 and Table 2.
// 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();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900