新聞中心
這篇文章主要為大家展示了Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接,內(nèi)容簡(jiǎn)而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會(huì)有收獲的,下面讓小編帶大家一起來(lái)看看吧。
使用工具:Free Spire.Presentation for Java(免費(fèi)版)Jar文件獲取及導(dǎo)入:
方法1:通過(guò)官網(wǎng)下載獲取jar包。解壓后將lib文件夾下的Spire.Presentation.jar文件導(dǎo)入Java程序。(如下圖)
方法2:通過(guò)maven倉(cāng)庫(kù)安裝導(dǎo)入。具體安裝教程參見(jiàn)此網(wǎng)頁(yè)。
【示例1】添加文本超鏈接
import com.spire.presentation.*; import com.spire.presentation.drawing.FillFormatType; import java.awt.*; import java.awt.geom.Rectangle2D; public class TextHyperlink { public static void main(String[] args) throws Exception { //創(chuàng)建一個(gè)PPT文檔,默認(rèn)包含一張幻燈片 Presentation presentation = new Presentation(); //在文檔最后追加一張幻燈片并填充一些內(nèi)容,方便之后添加超鏈接鏈接到此幻燈片 presentation.getSlides().append(); Rectangle2D.Double rec = new Rectangle2D.Double(presentation.getSlideSize().getSize().getWidth() / 2 - 255, 120, 500, 280); IAutoShape shape = presentation.getSlides().get(1).getShapes().appendShape(ShapeType.RECTANGLE, rec); shape.getFill().setFillType(FillFormatType.NONE); shape.getLine().setWidth(0); ParagraphEx para1 = new ParagraphEx(); PortionEx tr1 = new PortionEx(); tr1.setText("這是第二頁(yè)!"); para1.getTextRanges().append(tr1); shape.getTextFrame().getParagraphs().append(para1); para1.setAlignment(TextAlignmentType.CENTER); tr1.getFill().setFillType(FillFormatType.SOLID); tr1.getFill().getSolidColor().setColor(Color.blue); shape.getTextFrame().getParagraphs().append(new ParagraphEx()); //在第一張幻燈片上添加形狀 IAutoShape shape1 = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rec); shape1.getFill().setFillType(FillFormatType.NONE); shape1.getLine().setWidth(0); //添加鏈接到網(wǎng)頁(yè)的超鏈接 ParagraphEx para2 = new ParagraphEx(); PortionEx tr2 = new PortionEx(); tr2.setText("點(diǎn)擊鏈接到網(wǎng)頁(yè)"); tr2.getClickAction().setAddress("https://www.jianshu.com/"); para2.getTextRanges().append(tr2); shape1.getTextFrame().getParagraphs().append(para2); shape1.getTextFrame().getParagraphs().append(new ParagraphEx()); //添加鏈接到郵箱地址的超鏈接 ParagraphEx para3 = new ParagraphEx(); PortionEx tr3 = new PortionEx(); tr3.setText("點(diǎn)擊鏈接到郵箱地址"); tr3.getClickAction().setAddress("mailto:Tina.tang@e-iceblue.com"); para3.getTextRanges().append(tr3); shape1.getTextFrame().getParagraphs().append(para3); shape1.getTextFrame().getParagraphs().append(new ParagraphEx()); //添加鏈接到其他文檔的超鏈接 ParagraphEx para4 = new ParagraphEx(); PortionEx tr4 = new PortionEx(); tr4.setText("點(diǎn)擊鏈接到其他文檔"); tr4.getClickAction().setAddress("C:\\Users\\Test1\\Desktop\\月銷售統(tǒng)計(jì)表.xlsx"); para4.getTextRanges().append(tr4); shape1.getTextFrame().getParagraphs().append(para4); shape1.getTextFrame().getParagraphs().append(new ParagraphEx()); //添加超鏈接跳轉(zhuǎn)到其他幻燈片 ParagraphEx para5 = new ParagraphEx(); PortionEx tr5 = new PortionEx("點(diǎn)擊跳轉(zhuǎn)到第二張幻燈片"); ClickHyperlink link = new ClickHyperlink(presentation.getSlides().get(1)); tr5.setClickAction(link); para5.getTextRanges().append(tr5); shape1.getTextFrame().getParagraphs().append(para5); //保存文檔 presentation.saveToFile("output/TextHyperlink.pptx", FileFormat.PPTX_2010); } }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.cdcxhl.com,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
本文題目:Java如何實(shí)現(xiàn)在PPT中添加文本和圖片超鏈接-創(chuàng)新互聯(lián)
當(dāng)前URL:http://www.dlmjj.cn/article/goope.html