[英]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內容的最佳方法。 可以嘗試這種方法
好,我這樣解決了
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.