色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

Java 添加超鏈接到 Word 文檔方法詳解

瀏覽:150日期:2022-05-27 16:30:00

在Word文檔中,超鏈接是指在特定文本或者圖片中插入的能跳轉(zhuǎn)到其他位置或網(wǎng)頁的鏈接,它也是我們在編輯制作Word文檔時(shí)廣泛使用到的功能之一。今天這篇文章就將為大家演示如何使用Free Spire.Doc for Java在Word文檔中添加文本超鏈接和圖片超鏈接。

Jar包導(dǎo)入

方法一:下載Free Spire.Doc for Java包并解壓縮,然后將lib文件夾下的Spire.Doc.jar包作為依賴項(xiàng)導(dǎo)入到Java應(yīng)用程序中。

方法二:通過Maven倉庫安裝JAR包,配置pom.xml文件的代碼如下

<repositories> <repository> <id>com.e-iceblue</id> <url>http://repo.e-iceblue.cn/repository/maven-public/</url> </repository></repositories><dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.doc.free</artifactId> <version>2.7.3</version> </dependency></dependencies>

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:xxxxx@163.com','xxxxx@163.com', HyperlinkType.E_Mail_Link); //添加文檔鏈接 paragraph = section.addParagraph(); paragraph.appendText('文檔鏈接:'); String filePath = 'C:UsersAdministratorDesktop報(bào)表.pdf'; paragraph.appendHyperlink(filePath,'點(diǎn)擊打開報(bào)表', HyperlinkType.File_Link); //添加圖片超鏈接 paragraph = section.addParagraph(); paragraph.appendText('圖片鏈接:'); paragraph = section.addParagraph(); DocPicture picture = paragraph.appendPicture('C:UsersAdministratorIdeaProjectsSpire.Doclogo (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); //段落末尾自動(dòng)添加間隔 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 文檔方法詳解

到此這篇關(guān)于Java 添加超鏈接到 Word 文檔方法詳解的文章就介紹到這了,更多相關(guān)Java 添加超鏈接到 Word 文檔內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: word
相關(guān)文章:
主站蜘蛛池模板: avtt天堂网永久资源手机版 | 亚洲一区视频 | 国产麻豆交换夫妇 | 久久久久久在线 | 国产精品国产三级国产an | 欧美在线播放成人免费 | 亚洲欧美成人 | 韩国一级毛片视频 | 亚洲女精品一区二区三区 | 日韩三级影院 | 手机看片久久高清国产日韩 | 国内精品一区二区 | 国产一区二区三区在线免费 | 久久亚洲精品中文字幕二区 | 国产丶欧美丶日韩丶不卡影视 | 欧美精品束缚一区二区三区 | 久久精品国产第一区二区 | 国产精品久久久久久小说 | 美女一级片视频 | 国产成人亚洲合集青青草原精品 | 日韩一级视频在线观看播放 | 刺激免费视频 | 宫女淫春| 欧美一级视频高清片 | 精品亚洲一区二区三区 | 永久免费毛片手机版在线看 | 亚洲国产精品成人综合久久久 | 国产成人tv在线观看 | 亚洲一级免费毛片 | 美女视频黄色网址 | 天天鲁天天爱天天鲁天天 | jiz欧美高清 | 欧美人成片免费看视频不卡 | 毛片免费视频观看 | 一级黄色香蕉视频 | ⅹxx中国xxx人妖 | 亚洲成人黄色网址 | 国产主播大尺度精品福利 | 亚洲欧美一二三区 | 久久一区二区三区免费 | 国产免费一级精品视频 |