を含む段落を削除しようとしています"{Some Text}"
。以下のメソッドはまさにそれを行いますが、段落を削除した後、空の段落要素が残っていることに気付きました。
<w:p />
プログラムで要素を削除するにはどうすればよいですか?
以下は、最初に段落を削除するために使用したものです。
using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(file, true))
{
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
Document D = mainPart.Document;
foreach (Paragraph P in D.Descendants<Paragraph>())
{
if (P.InnerText.Contains("{SomeText}"))
{
P.RemoveAllChildren();
//P.Remove(); //doesn't remove
}
}
D.Save();
}
document.xml のあとがきは次のようになります。
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />