ఖచ్చితంగా, PowerPoint ప్రెజెంటేషన్లతో పని చేయడానికి Apache POIని ఉపయోగించే కొన్ని ప్రోగ్రామింగ్ ఉదాహరణలు ఇక్కడ ఉన్నాయి:
- కొత్త PowerPoint ప్రెజెంటేషన్ను సృష్టిస్తోంది:
జావా// Create a new PowerPoint presentation
XMLSlideShow ppt = new XMLSlideShow();
// Add a blank slide to the presentation
XSLFSlide slide = ppt.createSlide();
// Write the presentation to a file
FileOutputStream out = new FileOutputStream("new-presentation.pptx");
ppt.write(out);
out.close();
- స్లయిడ్కి వచనాన్ని జోడిస్తోంది:
జావా// Get the slide to add text to
XSLFSlide slide = ppt.getSlides().get(0);
// Create a new text box
XSLFTextBox textBox = slide.createTextBox();
// Set the position and size of the text box
textBox.setAnchor(new Rectangle(50, 50, 300, 200));
// Add some text to the text box
textBox.setText("Hello World");
// Set the font size of the text
XSLFTextParagraph paragraph = textBox.getTextParagraphs().get(0);
XSLFTextRun textRun = paragraph.getTextRuns().get(0);
textRun.setFontSize(36.0);
// Write the presentation to a file
FileOutputStream out = new FileOutputStream("presentation-with-text.pptx");
ppt.write(out);
out.close();
- స్లయిడ్కి చిత్రాన్ని జోడించడం:
జావా// Get the slide to add the image to
XSLFSlide slide = ppt.getSlides().get(0);
// Load the image file
File imageFile = new File("image.png");
byte[] imageData = Files.readAllBytes(imageFile.toPath());
// Add the image to the slide
XSLFPictureData pictureData = ppt.addPicture(imageData, XSLFPictureData.PICTURE_TYPE_PNG);
XSLFPictureShape pictureShape = slide.createPicture(pictureData);
// Set the position and size of the image
pictureShape.setAnchor(new Rectangle(50, 50, 300, 200));
// Write the presentation to a file
FileOutputStream out = new FileOutputStream("presentation-with-image.pptx");
ppt.write(out);
out.close();
- స్లయిడ్కి చార్ట్ని జోడిస్తోంది:
జావా// Get the slide to add the chart to
XSLFSlide slide = ppt.getSlides().get(0);
// Create a new chart
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet();
XSSFRow row = sheet.createRow(0);
row.createCell(0).setCellValue("Category");
row.createCell(1).setCellValue("Value");
row = sheet.createRow(1);
row.createCell(0).setCellValue("A");
row.createCell(1).setCellValue(10);
row = sheet.createRow(2);
row.createCell(0).setCellValue("B");
row.createCell(1).setCellValue(20);
XDDFChart chart = new XDDFChart(XDDFChartTypes.BAR, XDDFChartStyle.from(10));
XDDFDataSource<String> categories = XDDFDataSourcesFactory.fromStringCellRange(sheet, new CellRangeAddress(0, 0, 0, 1));
XDDFNumericalDataSource<Double> values = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(1, 2, 1, 1));
XDDFChartData data = chart.createData(XDDFChartTypes.BAR, null, categories, values);
chart.plot(data);
// Add the chart to the slide
XSLFChart xslfChart = slide.createChart();
xslfChart.embedChart(wb.getPackagePart());
xslfChart.setAnchor(new Rectangle(50, 50, 500, 400));
xslf