3
我正在尝试创建Word插件。我如何以编程方式替换段落中的文字?我需要替换:\r
到\t\r
。以编程方式替换段落中的格式化文本(链接,内容)
第一次尝试:
Globals.ThisAddIn.Application.ActiveDocument.Paragraphs[nr].Range.Text =
Globals.ThisAddIn.Application.ActiveDocument
.Paragraphs[nr].Range.Text.Replace("\r", "\t\r");
其良好的只有文字,但如果我有段链接或内容及其不起作用。
第二次尝试:
Globals.ThisAddIn.Application.ActiveDocument.Paragraphs[nr].Range.Find.Execute("\r");
Globals.ThisAddIn.Application.Selection.Text = "\t"
这种失败像1
第三次尝试:
Globals.ThisAddIn.Application.Selection.Find
.Execute("\r", Wrap: Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue);
Word.Find findObject = Application.Selection.Find;
// findObject.ClearFormatting();
findObject.Text = "\r";
// findObject.Replacement.ClearFormatting();
findObject.Replacement.Text = "\t\r"
object replaceAll = Word.WdReplace.wdReplaceAll;
findObject.Execute(ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref replaceAll, ref missing, ref missing, ref missing, ref missing);
这种失败多了一个,因为删除1项(用于将文本从第[1]第[2]段至第一段)
花点时间阅读帮助中心的[编辑帮助](http://stackoverflow.com/editing-help)。堆栈溢出的格式与其他站点不同。您的帖子看起来越好,用户就越容易帮助您。 – gunr2171 2014-11-05 16:02:37
你能详细说明你的代码“不工作”或“失败”吗?你在期待什么,究竟发生了什么?如果您遇到异常,请发布它发生的行和异常详细信息。 – gunr2171 2014-11-05 16:06:27