[英]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.