如何用java创建超链接_Java如何在PPT中的幻灯片上创建超链接?
在Java編程中,如何在PPT中的幻燈片上創建超鏈接?
注意:需要訪問網址:http://poi.apache.org/download.html , 下載一個Apache POI軟件包。這里下載最新版本:poi-bin-3.17-20170915.tar.gz解壓并全部導入 。
需要導入全部包,如下圖所示 -
以下是使用Java在PPT中的幻燈片上創建超鏈接的程序。
package com.yiibai;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xslf.usermodel.SlideLayout;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
import org.apache.poi.xslf.usermodel.XSLFTextRun;
import org.apache.poi.xslf.usermodel.XSLFTextShape;
import org.apache.xmlbeans.impl.xb.xsdschema.ListDocument.List;
public class CreateHyperlinkOnSlide {
public static void main(String args[]) throws IOException {
// create an empty presentation
XMLSlideShow ppt = new XMLSlideShow();
// getting the slide master object
java.util.List sl = ppt.getSlideMasters();
XSLFSlideMaster slideMaster = sl.get(0);
// select a layout from specified list
XSLFSlideLayout slidelayout = slideMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
// creating a slide with title and content layout
XSLFSlide slide = ppt.createSlide(slidelayout);
// selection of title place holder
XSLFTextShape body = slide.getPlaceholder(1);
// clear the existing text in the slide
body.clearText();
// adding new paragraph
XSLFTextRun textRun = body.addNewTextParagraph().addNewTextRun();
// setting the text
textRun.setText("易百教程網");
// creating the hyperlink
XSLFHyperlink link = textRun.createHyperlink();
// setting the link address
link.setAddress("http://www.yiibai.com/");
// create the file object
File file = new File("hyperlink.pptx");
FileOutputStream out = new FileOutputStream(file);
// save the changes in a file
ppt.write(out);
System.out.println("slide cretated successfully");
out.close();
}
}
執行上面示例代碼,得到以下結果 -
slide cretated successfully
這就創建一個PPT文件:hyperlink.pptx了,如下所示 -
¥ 我要打賞
糾錯/補充
收藏
加QQ群啦,易百教程官方技術學習群
注意:建議每個人選自己的技術方向加群,同一個QQ最多限加 3 個群。
總結
以上是生活随笔為你收集整理的如何用java创建超链接_Java如何在PPT中的幻灯片上创建超链接?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java编程赋值运算符_跟我学java编
- 下一篇: php大于等于符号怎么打出来_PHP常用