0

我想用一个表替换一个字符串,我不能让它工作。

下面是替换字符串的代码:

var newDoc = new FileInfo(OpenXml_docx);
File.Copy(sourceDoc.FullName, newDoc.FullName);
using (WordprocessingDocument wDoc = WordprocessingDocument.Open(newDoc.FullName, true)) {
    XDocument xDoc = wDoc.MainDocumentPart.GetXDocument();
    IEnumerable<XElement> content = xDoc.Descendants(W.p);
    int count = OpenXmlRegex.Replace(content, findeDas, "#BlaBla", null);
    Console.WriteLine("Example #1 Count: {0}", count); 
    wDoc.MainDocumentPart.PutXDocument();
}

我应该怎么办 ?

4

1 回答 1

0

你能展示你的正则表达式吗?(findeDas值)。

您也可以尝试使用其他替代替换:

var newDoc = new FileInfo(OpenXml_docx);
File.Copy(sourceDoc.FullName, newDoc.FullName);
using (WordprocessingDocument wDoc = WordprocessingDocument.Open(newDoc.FullName, true)) {
    XDocument xDoc = wDoc.MainDocumentPart.GetXDocument();
    IEnumerable<XElement> content = xDoc.Descendants(W.p);
    int count = 0;
    foreach (var e in content) {  
        count += OpenXmlRegex.Replace(e, findeDas, "#BlaBla", null);
    }
    Console.WriteLine("Example #1 Count: {0}", count); 
    wDoc.MainDocumentPart.PutXDocument();
}
于 2020-07-03T12:06:35.633 回答