简体   繁体   中英

How to create PPTX when using POI XSLF?

When I create a PPTX with POI XSLF I get a blank slide:

XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide slide = ppt.createSlide();
XSLFTextBox shape = slide.createTextBox();
XSLFTextParagraph p = shape.addNewTextParagraph();
XSLFTextRun r1 = p.addNewTextRun();
r1.setText("the");
r1.setFontColor(Color.blue);
r1.setFontSize(24);

OutputStream out = new FileOutputStream("d:/font.pptx");
ppt.write(out);
out.close();

Why is the slide blank without any text?

Your text box has no anchor (position and size).

You can check the examples of POI how to add a text box: XSLF Examples - Tutorial 6

XSLFTextBox shape = slide.createTextBox();
shape.setAnchor(new Rectangle(x, y, width, height));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM