[英]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.