要在Powerpoint中设置超链接,Apache POI提供了createHyperlink()方法,该方法负责在幻灯片上创建链接。请参见以下示例,我们将在Powerpoint中演示使用Java程序的超链接实现。
package poiexample;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
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;
public class ReadImageExample {
public static void main(String[] args) throws FileNotFoundException, IOException {
XMLSlideShow ppt = new XMLSlideShow();
try (OutputStream os = new FileOutputStream("srcmini.pptx")) {
// Setting layout
XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
XSLFSlideLayout tc = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
XSLFSlide slide = ppt.createSlide(tc);
// Setting title
XSLFTextShape title = slide.getPlaceholder(0);
title.setText("Hyperlink Example");
// Setting body
XSLFTextShape body = slide.getPlaceholder(1);
body.clearText();
XSLFTextRun r = body.addNewTextParagraph().addNewTextRun();
r.setText("Click here to visit srcmini.");
XSLFHyperlink link = r.createHyperlink();
link.setAddress("https://www.srcmini.com");
ppt.write(os);
}catch(Exception e) {
System.out.println(e);
}
}
}
【apache poi powerpoint超级链接】输出:
文章图片
推荐阅读
- apache poi powerpoint删除幻灯片
- apache poi powerpoint幻灯片重新排序
- apache poi powerpoint布局
- apache poi powerpoint图像
- apache poi powerpoint页面大小
- apache poi powerpoint幻灯片
- apache poi word文档段落
- apache poi超链接
- apache poi word表格