我有一些代码来替换单词2010 docx中的文本.
object fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, "document.docx");
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);
aDoc.Activate();
Microsoft.Office.Interop.Word.Find fnd = wordApp.ActiveWindow.Selection.Find;
fnd.ClearFormatting();
fnd.Replacement.ClearFormatting();
fnd.Forward = true;
fnd.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
fnd.Text = "{id}";
fnd.Replacement.Text = "123456";
fnd.Execute(Replace: WdReplace.wdReplaceAll);
Run Code Online (Sandbox Code Playgroud)
这没有格式化.但是当{id}被格式化时,它不会替换文本.
如何使此代码忽略格式化?
我收到以下错误消息:
Warning: Unexpected character in input: '\' (ASCII=92) state=1
Run Code Online (Sandbox Code Playgroud)
这是给我这个麻烦的代码行.
$tag_value = preg_replace('/\{(.*?)\}/e', '$values[\\1]', $tag_value);
Run Code Online (Sandbox Code Playgroud)
我使用PHP 5.2.9并且升级不是一个选项.
正则表达不是我的专长,我无法自己解决这个问题.任何帮助将不胜感激.