请帮助我使用 Java 中的 Aspose word 报告在文档中创建超链接
问问题
860 次
1 回答
2
您可以使用以下任何Aspose.Words for Java代码来满足此要求:
方法#1:
Document doc = new Document(getMyDir() + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHyperlink("Aspose", "http://www.aspose.com/", false);
doc.save(getMyDir() + "awjava-16.4.0.docx");
方法#2:
Document doc = new Document(getMyDir() + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get paragraph you want to append this Hyperlink to
Paragraph para = (Paragraph)doc.getChildNodes(NodeType.PARAGRAPH, true).get(1);
// Move cursor to this paragraph
builder.moveTo(para);
// We want to insert a Hyperlink like this:
// { " HYPERLINK Test1 \\l Test2 \\m \\n \\o Test3 \\t Test4" }
// Create instance of FieldHyperlink class and lets build the above field code
FieldHyperlink field = (FieldHyperlink)builder.insertField(FieldType.FIELD_HYPERLINK, false);
// HYPERLINK Test1
field.setAddress("Test1");
// HYPERLINK Test1 \\l Test2
field.setSubAddress("Test2");
// HYPERLINK Test1 \\l Test2 \\m
field.isImageMap(true);
// HYPERLINK Test1 \\l Test2 \\m \\n
field.setOpenInNewWindow(true);
// HYPERLINK Test1 \\l Test2 \\m \\n \\o Test3
field.setScreenTip("Test3");
// HYPERLINK Test1 \\l Test2 \\m \\n \\o Test3 \\t Test4
field.setTarget("Test4");
doc.save(getMyDir() + "awjava-16.4.0.docx");
我与 Aspose 一起担任开发人员宣传员。
于 2016-06-07T07:33:20.193 回答