如何将模板MS Excel文件中的格式分配给Apache POI XSSFWorkbook中的单元格?

时间:2019-03-25 15:59:52

标签: java excel apache-poi xssf

在Apache POI XWPFDocument(Word)中,我使用此代码将用户定义的格式MyHeadline分配给新段落。 MyHeadline包含在通过LibreOffice创建的template.docx中。

XWPFDocument document = new XWPFDocument(new FileInputStream("template.docx"));
XWPFParagraph paragraph = document.createParagraph();
paragraph.setStyle("MyHeadline");

我的问题:使用Apache POI XSSFWorkbook(Excel)是否有类似的方法?

故障代码!

XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream("template.xlsx"));
XSSFSheet sheet = workbook.getSheetAt(0);
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
cell.setCellValue("Brennholzverleih");
cell.setCellStyle("MyCellStyle"); // This is what I want to do. "MyCellStyle" is an
                                  // user defined cell format contained in "template.xlsx".
                                  // Of course there is no setCellStyle(String) method!

0 个答案:

没有答案