apache poi powerpoint超级链接

要在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超级链接

文章图片

    推荐阅读