2015-04-23 156 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 –