成都创新互联网站制作重庆分公司

Java在PPT中添加文本、图片超链接

本文介绍通过Java程序在PPT幻灯片中添加超链接的方法,可以给文本或者图片设置超链接,设置超链接时,可设置包括网页链接、邮件地址链接、幻灯片跳转链接等不同指向对象的链接。文中方法使用了免费版PPT类库(Free Spire.Presentation for Java),可在官网 下 载jar包,并解压将lib文件夹下的jar导入java程序。

晋江网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。创新互联公司于2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司

如下导入效果:

Java 在PPT中添加文本、图片超链接

程序运行环境:Java、IDEA、jdk1.8.0、无需安装Microsoft PowerPoint

Java代码示例

 import com.spire.presentation.*;
 import com.spire.presentation.drawing.FillFormatType;
 
 import java.awt.geom.Rectangle2D;
 
 public class AddHyperlink {
     public static void main(String[] args) throws Exception{
         //加载测试PPT
         Presentation ppt = new Presentation();
         ppt.loadFromFile("test.pptx");
 
         //实例化Rectangle2D.Double类的对象
         Rectangle2D.Double rec = new Rectangle2D.Double(350, 150, 400, 180);
 
         //在第1张幻灯片上添加形状
         IAutoShape shape1 = ppt.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, rec);
         shape1.getFill().setFillType(FillFormatType.NONE);
         shape1.getLine().setFillType(FillFormatType.NONE);
 
         //添加链接到网页的超链接
         ParagraphEx para1 = new ParagraphEx();
         PortionEx tr1 = new PortionEx();
         tr1.setText("1. 网页地址链接:点击访问网页");
         tr1.getClickAction().setAddress("https://www.baidu.com/");
         para1.getTextRanges().append(tr1);
         shape1.getTextFrame().getParagraphs().append(para1);
         shape1.getTextFrame().getParagraphs().append(new ParagraphEx());
 
         //添加链接到邮箱地址的超链接
         ParagraphEx para2 = new ParagraphEx();
         PortionEx tr2 = new PortionEx();
         tr2.setText("2. 邮箱地址链接:点击发送邮件");
         tr2.getClickAction().setAddress("mailto:123654zz@163.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("3. 幻灯片跳转链接:点击跳转到第二张幻灯片");
         ClickHyperlink link = new ClickHyperlink(ppt.getSlides().get(1));
         tr3.setClickAction(link);
         para3.getTextRanges().append(tr3);
         shape1.getTextFrame().getParagraphs().append(para3);
 
         //添加图片到第2张幻灯片,并设置超链接
         String imaPath = "pd.png";
         Rectangle2D.Float rect = new Rectangle2D.Float(230, 200, 500, 250);
         IEmbedImage image = ppt.getSlides().get(1).getShapes().appendEmbedImage(ShapeType.RECTANGLE, imaPath, rect);
         image.getLine().setFillType(FillFormatType.NONE);
         ClickHyperlink hyperlink = new ClickHyperlink("https://www.baidu.com/");
         image.setClick(hyperlink);
 
         //保存文档
         ppt.saveToFile("AddHyperlink.pptx", FileFormat.PPTX_2010);
         ppt.dispose();
     }
 }

超链接添加效果可在幻灯片放映中查看:

文本超链接:

Java 在PPT中添加文本、图片超链接

图片超链接:

Java 在PPT中添加文本、图片超链接

(本文完)


文章名称:Java在PPT中添加文本、图片超链接
网站链接:http://cxhlcq.com/article/gjjgss.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部