新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Java添加超鏈接到Word文檔-創(chuàng)新互聯(lián)
在Word文檔中,超鏈接是指在特定文本或者圖片中插入的能跳轉(zhuǎn)到其他位置或網(wǎng)頁的鏈接,它也是我們在編輯制作Word文檔時廣泛使用到的功能之一。今天這篇文章就將為大家演示如何使用Free Spire.Doc for Java在Word文檔中添加文本超鏈接和圖片超鏈接。
在漳州等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計制作按需定制制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),營銷型網(wǎng)站,成都外貿(mào)網(wǎng)站制作,漳州網(wǎng)站建設(shè)費(fèi)用合理。Jar包導(dǎo)入
方法一: 下載 Free Spire.Doc for Java 包并解壓縮,然后 將lib文件夾下 的Spire.Doc.jar包 作為依賴項(xiàng)導(dǎo)入 到Java應(yīng)用程序中。
方法二: 通過Maven倉庫安裝JAR包, 配置pom.xml文件 的代碼如下
com.e-iceblue http://repo.e-iceblue.cn/repository/maven-public/ e-iceblue spire.doc.free 2.7.3
Java代碼
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.HorizontalAlignment;
import com.spire.doc.documents.HyperlinkType;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.documents.ParagraphStyle;
import com.spire.doc.fields.DocPicture;
public class InsertHyperlinks {
public static void main(String[] args) {
//創(chuàng)建Word文檔
Document doc = new Document();
Section section = doc.addSection();
//添加網(wǎng)頁鏈接
Paragraph paragraph = section.addParagraph();
paragraph.appendText("網(wǎng)頁鏈接:");
paragraph.appendHyperlink("https://www.baidu.com/","主頁", HyperlinkType.Web_Link);
//添加郵箱鏈接
paragraph = section.addParagraph();
paragraph.appendText("郵箱鏈接:");
paragraph.appendHyperlink("mailto:[email protected]","[email protected]", HyperlinkType.E_Mail_Link);
//添加文檔鏈接
paragraph = section.addParagraph();
paragraph.appendText("文檔鏈接:");
String filePath = "C:\\Users\\Administrator\\Desktop\\報表.pdf";
paragraph.appendHyperlink(filePath,"點(diǎn)擊打開報表", HyperlinkType.File_Link);
//添加圖片超鏈接
paragraph = section.addParagraph();
paragraph.appendText("圖片鏈接:");
paragraph = section.addParagraph();
DocPicture picture = paragraph.appendPicture("C:\\Users\\Administrator\\IdeaProjects\\Spire.Doc\\logo (2).jpg");
paragraph.appendHyperlink("https://www.baidu.com/",picture, HyperlinkType.Web_Link);
//創(chuàng)建段落樣式
ParagraphStyle style1 = new ParagraphStyle(doc);
style1.setName("style");
style1.getCharacterFormat().setFontName("宋體");
doc.getStyles().add(style1);
for (int i = 0; i < section.getParagraphs().getCount(); i++) {
//將段落居中
section.getParagraphs().get(i).getFormat().setHorizontalAlignment(HorizontalAlignment.Center);
//段落末尾自動添加間隔
section.getParagraphs().get(i).getFormat().setAfterAutoSpacing(true);
//應(yīng)用段落樣式
section.getParagraphs().get(i).applyStyle(style1.getName());
}
//保存文檔
doc.saveToFile("InsertHyperlinks.docx", FileFormat.Docx_2013);
}
}

文章題目:Java添加超鏈接到Word文檔-創(chuàng)新互聯(lián)
本文鏈接:http://fisionsoft.com.cn/article/dhcggh.html


咨詢
建站咨詢
