在书签处插入

本文关键字:插入 书签 | 更新日期: 2023-09-27 18:35:35

我有以下方法(不是我的程序)将表数据插入文档末尾。 我想将数据插入到文档中的书签中。 如何引用该书签而不是 ''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;
    }

在书签处插入

以下代码是从 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);