我有以下方法(不是我的程序)将表数据插入到文档的末尾。我想将数据插入文档中的书签。如何引用该书签而不是\ endofdoc?
private static void CreateTable(Microsoft.Office.Interop.Word.Document oWordDoc, int RowCount, int ColumnCount, string[,] TableContent)
{
Table oTable;
object oEndOfDoc = "\\endofdoc";
object missing = System.Reflection.Missing.Value;
Range wrdRng = oWordDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oTable = oWordDoc.Tables.Add(wrdRng, RowCount, ColumnCount, ref missing, ref missing);
oTable.ID = "ContentTable";
int r, c;
for (r = 0; r < RowCount; r++)
for (c = 0; c < ColumnCount; c++)
{
oTable.Cell(r + 1, c + 1).Range.Text = TableContent[r, c];
}
//oTable.Rows[1].Range.Font.Bold = 1;
oTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleThickThinLargeGap;
oTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
}
答案 0 :(得分:1)
以下代码是从c-sharpcorner中挑选出来的,这可以帮助您开始处理书签。
//BOOK MARK FOR START OF SELECTION
Object oBookmarkStart = "BookMark__Start";
Object oRngoBookMarkStart = oWordDoc.Bookmarks.get_Item(ref oBookmarkDesignInfoStart).Range.Start;
//BOOK MARK FOR END OF SELECTION
Object oBookmarkEnd = "BookMark__End";
Object oRngoBookMarkEnd = oWordDoc.Bookmarks.get_Item(ref oBookmarkDesignInfoEnd).Range.Start;
//SETTING THE RANGE ON THE BOOKMARK BETWEEN TWO BOOKMARKS
Word.Range rngBKMarkSelection = oWordDoc.Range(ref oRngoBookMarkStart, ref oRngoBookMarkEnd);
//SELECTING THE TEXT
rngBKMarkSelection.Select();
rngBKMarkSelection.Delete(ref oMissing, ref oMissing);