[英]OpenXML - replace a string by a table
I want to replace a string by a table, I can't make it work.我想用一个表替换一个字符串,我不能让它工作。
Here is the code for replacing a string:下面是替换字符串的代码:
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();
}
What should I do?我应该怎么办?
Can you show your regex?你能展示你的正则表达式吗? (
findeDas
value). (
findeDas
值)。
Also you could probably try to use other override of Replace:您也可以尝试使用其他替代替换:
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.