Word interop : Multiple tables in one bookmark
is it possible to insert multiple tables in one bookmark in Word 2007. I have template Word file and bookmark is in the middle of file. I need pagebreak after each table. My code seems to insert all the tables into the top-left cell of the previous table. I use VS2008 (3.5).
{ Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
object bookmark = "Tables"
oDoc = oWord.Documents.Open(ref fileName,
ref missing, ref missing, ref missing, ref 开发者_JS百科missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);
var oJ = from o in dbcontext.Org_Jedinica
select o;
Word.Table oTable;
Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref bookNaziv).Range;
foreach (var orgJedinica in oJ)
{
oTable = oDoc.Tables.Add(wrdRng, 24, 2, ref oMissing, ref oMissing);
oTable.Cell(1, 1).Range.Text = "..."; ...
}
}
You need to move the cursor out of the table after adding each one.
Try using the EndKey
mathod. Not sure which value of WdUnits
you need. Either way, you need to move the cursor.
If you can't figure out how to move the cursor to the end of the bookmark, you can always create an empty document and put all the tables in it. Use EndKey
with WdStory
to go to the end of the page. Then insert the document into your original document.
精彩评论