![](/img/trans.png)
[英]OpenXML: Replace <sdt/> element with table in WordprocessingML
[英]OpenXML - replace a string by a table
我想用一个表替换一个字符串,我不能让它工作。
下面是替换字符串的代码:
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();
}
我应该怎么办?
你能展示你的正则表达式吗? ( 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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.