簡體   English   中英

單詞自動化目錄

[英]word automation table of content

我有一個文檔,其中有一些文本和目錄

foreach (Word.TableOfContents toC in wordDoc.TablesOfContents)
        {
            toC.Update();

        }  

但標題開頭的單詞相同,我想在目錄中刪除該單詞,

 toC.Range.Text = toC.Range.Text.Replace("text to be removed", "");

但是現在看起來混亂了對齊方式和間距,沒有人知道如何更改文本而不弄亂目錄的布局嗎?

如果還有其他方法可以做到這一點,就像在模板中一樣,如果我能以某種方式告訴目錄在生成指定的文本時將其替換為情感字符串,那么我似乎陷入了僵局那樣的東西??

不確定這是否是直接編輯TOC內容的最佳方法。 可以嘗試這種方法

  1. 所有目錄均使用“標題”樣式。
  2. 創建一個說“ NONTOCHeading”的樣式的副本
  3. 將不想顯示在目錄中的標題設置為“ NONTOCHeading”
  4. 更新目錄

好,我這樣解決了

object findText = "text to be removed";
                object replaceText = string.Empty;
                object item = Word.WdGoToItem.wdGoToPage;
                object whichItem = Word.WdGoToDirection.wdGoToFirst;
                object replaceAll = Word.WdReplace.wdReplaceAll;
                object forward = true;
                object matchAllWord = true;
                toC.Range.Document.GoTo(ref item, ref whichItem, ref missing, ref missing);
                toC.Range.Find.Execute(ref findText, ref missing, ref matchAllWord,
                                  ref missing, ref missing, ref missing, ref forward,
                                  ref missing, ref missing, ref replaceText, ref replaceAll,
                                  ref missing, ref missing, ref missing, ref missing);

但您不應該更新目錄,否則需要手動替換文本

暫無
暫無

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

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