亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

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

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

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

Jar包導入

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

方法二:通過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報表.pdf'; paragraph.appendHyperlink(filePath,'點擊打開報表', 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); //段落末尾自動添加間隔 section.getParagraphs().get(i).getFormat().setAfterAutoSpacing(true); //應用段落樣式 section.getParagraphs().get(i).applyStyle(style1.getName()); } //保存文檔 doc.saveToFile('InsertHyperlinks.docx', FileFormat.Docx_2013); }}

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

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

標簽: word
相關文章:
主站蜘蛛池模板: 毛片无限看 | 国产精品jvid在线观看 | 欧美成人黑人xx视频免费观看 | 麻豆国产91 | 特黄一级| 亚洲大片在线观看 | 久久精品国产999大香线焦 | 国产在线精品一区二区三区不卡 | 日韩一级特黄毛片在线看 | 伊人久久精品一区二区三区 | 免费久草视频 | 日本巨乳中文字幕 | 49pao强力在线高清基地 | 亚洲第一综合网 | 国产免费麻豆 | 黑人在线播放 | 久久97精品久久久久久久看片 | 欧美日韩亚洲一区二区精品 | 国产精品不卡无毒在线观看 | 亚洲日本韩国欧美 | 狠狠色丁香久久婷婷综合_中 | 激情婷婷网 | 国产精品揄拍100视频最近 | 亚洲欧美日韩在线观看二区 | 日韩一区二区三区免费视频 | 日本一级毛片视频无遮挡免费 | 亚洲精品色综合色在线观看 | 亚洲精品成人456在线播放 | 亚洲国产精品乱码在线观看97 | 日韩一区二区精品久久高清 | 欧美一区二区三区免费看 | 美女毛片在线 | 日本特黄色大片 | 国产成人综合日韩精品婷婷九月 | 国产精品一区二区三区免费 | aaa大片 | 国产精品亚洲成在人线 | 欧美日批 | 1717she精品国产真正免费 | 亚洲欧美一区二区三区综合 | 影视先锋影音在线中文字幕 |