Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void ppt_with_excel() throws IOException, InvalidFormatException {
- FileInputStream fis = new FileInputStream("ppt_with_excel.pptx");
- XMLSlideShow ppt = new XMLSlideShow(fis);
- fis.close();
- XSLFSlide sl = ppt.getSlides().get(0);
- XSLFGraphicFrame gf = (XSLFGraphicFrame)sl.getShapes().get(0);
- XSLFPictureShape ps = gf.getFallbackPicture();
- PackagePart pp = ps.getPictureData().getPackagePart();
- // determine click-me image extension
- File clickMe;
- if ("image/x-emf".equals(pp.getContentType())) {
- clickMe = new File("clickMe.emf");
- // else png, gif, ...
- } else {
- throw new IOException("I don't have 'click me' image for content type "+pp.getContentType());
- }
- OutputStream os = pp.getOutputStream();
- InputStream is = new FileInputStream(clickMe);
- IOUtils.copy(is, os);
- is.close();
- os.close();
- FileOutputStream fos = new FileOutputStream("bla.pptx");
- ppt.write(fos);
- fos.close();
- ppt.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment