文檔半島外圍網(wǎng)上直營>>Aspose中文文檔>>從流中打開文檔
                從流中打開文檔
Aspose.Words是一種高級(jí)Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺(tái)應(yīng)用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
如何使用 Aspose.Words創(chuàng)建文檔
只需將包含文檔的流對(duì)象傳遞到Document構(gòu)造函數(shù)即可。
以下代碼示例演示如何從流中打開文檔:
Stream stream = File.Open(MyDir + "Document.docx", FileMode.Open);
using (stream)
{
	Document doc = new Document(stream);
	DocumentBuilder builder = new DocumentBuilder(doc);
	builder.Writeln("Append text in body - Open and add to wordprocessing stream");
	doc.Save(ArtifactsDir + "Open document from stream - Aspose.Words.docx");
}
如何使用 Open XML SDK 創(chuàng)建文檔
您還可以使用 Open XML SDK 執(zhí)行相同的操作。同時(shí)請(qǐng)注意,它看起來有些更復(fù)雜、更麻煩。
例如,以下代碼示例打開Public Documents 文件夾中的OpenDocumentFromStream.docx文件并向其中添加文本:
public void OpenDocumentFromStreamFeature()
{
	using (Stream stream = File.Open(MyDir + "Document.docx", FileMode.Open))
	{
		using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(stream, true))
		{
			Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
			Paragraph para = body.AppendChild(new Paragraph());
			Run run = para.AppendChild(new Run());
			run.AppendChild(new Text("Append text in body - Open and add to wordprocessing stream"));
		}
	}
}
 下載此示例的示例文件。                
            
 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網(wǎng)安備
            50010702500608號(hào)
渝公網(wǎng)安備
            50010702500608號(hào)
             
            
 客服熱線
客服熱線