Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.60/5 (3 votes)
See more:
Hello,
I tried googleing but could not accurtely find how to add data in an already existing table in a word document. All articles give how to create table and add data into it. But what if the table is already existing. How to i know to which table in the document would i be pointing to in case there are many tables in the docuemnt. Could any one please help.?
Posted
Comments
asjadazeez 13-May-11 7:31am    
OK please provide some solution. I see that there have been about 10 views but not a single solution until now. Can this be done. ?
Sandeep Mewara 13-May-11 12:17pm    
Woo! Demanding you are... :)

AFAIK, you cannot add text to an existing word document, but you can replace text.

Check out these links -

http://msdn.microsoft.com/en-us/library/6b9478cs(v=vs.80).aspx[^]

http://weblogs.asp.net/guystarbuck/archive/2008/05/13/automated-search-and-replace-in-multiple-word-2007-documents-with-c.aspx[^]

Another option is to use Word XML, if you want complete control of your word document - this way you could create xml files, save them as .doc. The main advantage in this case is that you can parse the xml and do whatever your requirement suggests you to do. Check out the following example:

http://weblogs.asp.net/cnagel/archive/2004/09/25/234188.aspx[^]

PS - If somebody knows of more good ways to go about, please comment/post a solution, thanks!
 
Share this answer
 
Comments
asjadazeez 13-May-11 9:47am    
Wel thanks for the reply but that was not the answer i was looking for.
I have posted my own solution as an answer.
Karthik. A 13-May-11 10:03am    
Actually, the first link (MSDN) does something on the similar lines, as you do in your answer. Anyway, you are welcome!
Possible solution is here.
If any one helpe me with a better one , i would be thankful.
MIDL
using Word = Microsoft.Office.Interop.Word;
Word.Table WordTable;

//Someting else here like to open the already existing word doc with a table.

WordTable = WordDoc.Tables[x];//x is the number of table starting with 1
WordTable.Cell(RowNo, CellNo).Range.Text = "Some data";//Row cell numbers start with 1
 
Share this answer
 

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