簡體   English   中英

閱讀Word書簽

[英]Read Word bookmarks

有誰能告訴我如何使用openXml 2.0實現Word 2010文檔中的所有書簽。 我使用Microsoft.Office.Interop.Word讀取書簽,但是由於存在問題,因此無法部署我的網站,所以我切換到openxml,有人可以告訴我如何讀取所有書簽嗎?

你可以遍歷所有

file.MainDocumentPart.RootElement.Descendants<BookmarkStart>()

喜歡:

IDictionary<String, BookmarkStart> bookmarkMap = 
     new Dictionary<String, BookmarkStart>();

// get all
foreach (BookmarkStart bookmarkStart in file.MainDocumentPart.RootElement.Descendants<BookmarkStart>())
{
    bookmarkMap[bookmarkStart.Name] = bookmarkStart;
}

// get their text
foreach (BookmarkStart bookmarkStart in bookmarkMap.Values)
{
  Run bookmarkText = bookmarkStart.NextSibling<Run>();
  if (bookmarkText != null)
  {
      string bookmarkText = bookmarkText.GetFirstChild<Text>().Text;
  }
}

https://stackoverflow.com/a/3318381/28004提取的代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM