Creating multiple tables for Word.Table using C#

N

nish

Hi,

I am struggling with this code. I am trying to create 3 separate
tables and print them in word, however I end up with 1 big table and 1
nested table inside and 1 more nested table within that.

Here is my code..

// CALL CreateTable - see method below
Word.Table oTable = CreateTable();

// Return with created table and add cell items
for (int y=0; y < dt.Columns.Count; y++)
{
for (int z=1; z <= 2; z++)
{
if (z == 1)
oTable.Cell(y,z).Range.Text = dt.Columns[y].ColumnName;
else
oTable.Cell(y,z).Range.Text = dt.Rows[x][y].ToString();
}
}




private Word.Table CreateTable()
{
// Create Table
object oTableBehavior =
Word.WdDefaultTableBehavior.wdWord9TableBehavior;
object oFitBehavior = Word.WdAutoFitBehavior.wdAutoFitFixed;


Word.Table oTable = oDoc.Tables.Add(oWord.Selection.Range, 24, 2,
ref oTableBehavior, ref oFitBehavior);


//Set table properties
object oStyle = "Table Grid";
oTable.set_Style(ref oStyle);

return oTable;
}


Please advise...
I am saving and activating this....



oDoc.SaveAs(ref fileName, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing);

oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref
readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing, ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref
oMissing, ref oMissing, ref oMissing, ref oMissing);
oWord.ShowMe();

oDoc.Activate();

// Exit out of word
oWord.Quit(ref oMissing, ref oMissing, ref oMissing);


Many thanks,
Nisha
 
Joined
Aug 8, 2006
Messages
2
Reaction score
0
Multiple nested tables issue

Hi Nisha,

Your post is more than a year old, but I am having issues in creating nested tables (2 levels) in C#/MS Word. Could you please reply if you have anything that can help me?

Appreciate it.

Malay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top