"{Some Text}"
이 포함 된 단락을 제거하려고합니다. 아래의 방법은 그 일을 처리하지만 단락을 제거한 후에는 빈 단락 요소가 남아있는 것으로 나타났습니다.빈 단락 요소를 제거하려면 어떻게해야합니까?
<w:p />
요소를 프로그래밍 방식으로 제거하려면 어떻게해야합니까?
다음은 처음 단락을 제거하는 데 사용 된 내용입니다. document.xml이 afterwords과 같은 방법
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();
}
입니다 :
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />
<w:p />
그냥 추측하십시오 - "not"가 누락 되었습니까? 'if (! P.InnerText.Contains ("{SomeText}"))'? –
7 단락이 최상위 태그입니까? – rene
예, 최상위 태그입니다. @rene –