文檔半島外圍網上直營>>Aspose中文文檔>>創建文檔
                創建文檔
Aspose.Words是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
如何使用 Aspose.Words創建文檔
在Aspose.Words中,我們通常使用Document類來創建文檔,并使用DocumentBuilder類來修改它。
以下代碼示例展示了如何創建文檔:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello World!");
doc.Save("CreateDocument.docx");
如何使用 Open XML SDK 創建文檔您還可以使用 Open XML SDK 執行相同的操作。 同時請注意,它看起來有些更復雜、更麻煩。
以下是我們需要添加的命名空間:
using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework;
以下代碼示例展示了如何創建文檔:
public void CreateADocumentFeature()
{
using (WordprocessingDocument wordDocument =
WordprocessingDocument.Create(ArtifactsDir + "Create a document - OpenXML.docx",
WordprocessingDocumentType.Document))
{
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
// Create the document structure and add some text.
mainPart.Document = new Document();
Body body = mainPart.Document.AppendChild(new Body());
Paragraph para = body.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
run.AppendChild(new Text("Create text in body - Create wordprocessing document"));
}
}
 下載此示例的示例文件。                
            
 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線