List of usage examples for org.apache.poi.ss.usermodel Workbook createSheet
Sheet createSheet();
From source file:org.exist.xquery.corenlp.Tokenize.java
License:Open Source License
private void createXSLXSpreadsheet(List<List<CoreLabel>> sentences, List<CoreLabel> tokens) { Workbook workbook = null; if (outputFormat == OutDocType.XSLX) { workbook = new SXSSFWorkbook(); } else {/*from ww w.j a v a 2s .co m*/ workbook = new HSSFWorkbook(); } CreationHelper creationHelper = workbook.getCreationHelper(); org.apache.poi.ss.usermodel.Sheet sheet = workbook.createSheet(); Font boldFont = workbook.createFont(); boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD); // Header CellStyle headerStyle = workbook.createCellStyle(); headerStyle.setFont(boldFont); int lineIndex = 0; for (List<CoreLabel> sentence : sentences) { for (CoreLabel token : sentence) { String value = token.get(CoreAnnotations.OriginalTextAnnotation.class); Row row = sheet.createRow(lineIndex); row.createCell(0).setCellValue(creationHelper.createRichTextString(value)); row.createCell(1).setCellValue(creationHelper.createRichTextString(backgroundSymbol)); lineIndex++; } Row row = sheet.createRow(lineIndex); row.createCell(0).setCellValue(creationHelper.createRichTextString("")); row.createCell(1).setCellValue(creationHelper.createRichTextString("")); lineIndex++; } try (OutputStream os = Files.newOutputStream(tempOutFile)) { workbook.write(os); } catch (FileNotFoundException fe) { LOG.error(fe); } catch (IOException ioe) { LOG.error(ioe); } finally { if (workbook != null) { if (workbook instanceof SXSSFWorkbook) { ((SXSSFWorkbook) workbook).dispose(); } else { workbook = null; } } } }