文檔半島外圍網(wǎng)上直營>>Aspose中文文檔>>從文檔中刪除分節(jié)符
                從文檔中刪除分節(jié)符
Aspose.Words是一種高級Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺應(yīng)用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
使用Aspose.Words
在Aspose.Words中,使用ControlChar類的SectionBreak字段來查找所有分節(jié)符。
以下代碼示例演示如何從文檔中刪除分頁符:
Document doc = new Document(MyDir + "Remove section breaks.docx");
// Loop through all sections starting from the section that precedes the last one
for (int i = doc.Sections.Count - 2; i >= 0; i--)
{
// Copy the content of the current section to the beginning of the last section.
doc.LastSection.PrependContent(doc.Sections[i]);
// Remove the copied section.
doc.Sections[i].Remove();
}
	點擊復(fù)制
使用 Open XML SDK
需要添加的命名空間:
uusing System.Collections.Generic; using System.IO; using System.Linq; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework;
點擊復(fù)制
以下代碼示例演示如何從文檔中刪除分頁符:
public void RemoveSectionBreaksFeature()
{
	using (WordprocessingDocument myDoc = WordprocessingDocument.Open(MyDir + "Remove section breaks.docx", true))
	{
		MainDocumentPart mainPart = myDoc.MainDocumentPart;
		List<ParagraphProperties> paraProps = mainPart.Document.Descendants<ParagraphProperties>()
			.Where(IsSectionProps).ToList();
		foreach (ParagraphProperties pPr in paraProps)
			pPr.RemoveChild(pPr.GetFirstChild<SectionProperties>());
		using (Stream stream = File.Create(ArtifactsDir + "Remove section breaks - OpenXML.docx"))
		{
			mainPart.Document.Save(stream);
		}
	}
}
private static bool IsSectionProps(ParagraphProperties pPr)
{
	SectionProperties sectPr = pPr.GetFirstChild<SectionProperties>();
	if (sectPr == null)
		return false;
		return true;
}
	點擊復(fù)制

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網(wǎng)安備
            50010702500608號
渝公網(wǎng)安備
            50010702500608號
             
            
 客服熱線
客服熱線