-
JAVA apache poi - PowerPoint 읽고 새로운 PowerPoint 생성JAVA 2021. 7. 2. 15:56728x90
List<XSLFShape> shapes = slides.get(0).getShapes();
JAVA 에서 파워포인트를 읽고 원하는 컨텐츠만 뽑아서
다른 이름으로 저장하는 방법을 알아보겠다
우선 원본파일의 경로가 필요하다
String originalPath = "c:\\Users\\won\\hello.pptx";
원본파일을 읽는다
XMLSlideShow originalPpt = new XMLSlideShow(new FileInputStream(originalPath));
ppt 슬라이드를 가져온다
List<XSLFSlide> slides = originalPpt.getSlides();
첫번째 슬라이드의 구성요소(Picture, Shape 등,,,)를 가져온다
List<XSLFShape> shapes = slides.get(0).getShapes();
제거하고 싶은 구성요소(AutoShape)를 shapes 에서 제거한다
for(int i = 0; i < shapes.size(); i++) { // instanceof 로 XSLFAutoShape 인지 XSLFPictureShape 인지 구분할 수 있다 if(shapes.get(i) instanceof XSLFAutoShape) { slides.get(0).removeShape(shapes.get(i)); } }
저장할 ppt 경로를 지정하고 FileOutputStream 객체를 생성한다
String path = "c:\\Users\\won\\Bye.pptx"; FileOutputStream out = new FileOutputStream(path);
원본 ppt를 out 객체에 기록한다
originalPpt.write(out);
객체를 반환한다
out.close(); originalPpt.close();
728x90728x90'JAVA' 카테고리의 다른 글
ArrayList에서 Optional 객체 찾기, filter 조건 걸기, 배열에서 filter 조건걸기 (0) 2021.12.01 String으로 저장된 날짜를 Date 형식으로 변환하여 DB에 저장하기 (0) 2021.09.14 Ramda Loop 돌면서 원하는 값 추출하기 (0) 2021.07.01 [JAVA] 한글 깨짐 (0) 2021.06.14