文檔半島外圍網上直營>>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);
// Specify font formatting before adding text.
Aspose.Words.Font font = builder.Font;
font.Size = 16;
font.Bold = true;
font.Color = Color.Blue;
font.Name = "Arial";
font.Underline = Underline.Dash;
builder.Write("Insert text");
doc.Save("ModifiedDocument.docx");
	點擊復制
	
以下是我們需要使用的命名空間:
	
pusing DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing;
點擊復制
	
	
下面是使用OpenAndAddTextToWordDocument作為函數來解釋此功能的代碼:
public void OpenAndAddTextToWordDocumentFeature()
{
// Open a WordprocessingDocument for editing using the filepath.
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(MyDir + "Document.docx", true))
{
// Assign a reference to the existing document body.
Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
// Add new text.
Paragraph para = body.AppendChild(new Paragraph());
Run run = para.AppendChild(new Run());
run.AppendChild(new Text("Append text in body - Open and add text to word document"));
}
}
	點擊復制
	

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線