2015-04-23 93 views

回答

1

這可以通過在段落中附加超鏈接字段來完成。請參閱下面的示例代碼

// Create or load a document 
Aspose.Words.Document wordDoc = new Aspose.Words.Document(); 

// Get first paragraph 
Aspose.Words.Paragraph para = wordDoc.FirstSection.Body.FirstParagraph; 
para.Runs.Add(new Run(wordDoc, "Visit ")); 

// Add the hyperlink field to the paragraph 
FieldHyperlink field = (FieldHyperlink)para.AppendField(Aspose.Words.Fields.FieldType.FieldHyperlink, false); 
// URL 
field.Address = @"""http://www.aspose.com"""; 
// Text 
field.Result = "Aspose"; 
field.Update(); 

// Set color of the last run 
para.Runs[para.Runs.Count - 1].Font.Color = System.Drawing.Color.Blue; 

// Save the document 
string dst = (dataDir + @"hyperlink.docx"); 
wordDoc.Save(dst); 

我使用Aspose作爲Developer Evangelist。

+0

謝謝Razzaq –