List of usage examples for org.apache.poi.xssf.usermodel XSSFCell setCellValue
@Override public void setCellValue(boolean value)
From source file:org.obiba.mica.dataset.search.rest.harmonization.ExcelContingencyWriter.java
License:Open Source License
private <T extends Number> void writeTable(XSSFSheet sheet, List<List<T>> tmp, String title, List<String> headers, List<String> values, boolean isContinuous) { writeTableHeaders(sheet, title, headers); ArrayList<String> rowHeaders = Lists.newArrayList(values); if (!isContinuous) rowHeaders.add("Total"); int counter = 0; int rownum = 4; for (String k : rowHeaders) { int cellnum = 0; XSSFRow row = sheet.createRow(rownum++); XSSFCell cell = row.createCell(cellnum++); cell.setCellValue(k); cell.setCellStyle(headerStyle);/*w ww . j ava2s. c o m*/ for (T obj : tmp.get(counter)) { cell = row.createCell(cellnum++); cell.setCellStyle(tableStyle); if (obj instanceof Integer) cell.setCellValue((Integer) obj); else if (obj instanceof Float) cell.setCellValue((Float) obj); else cell.setCellValue(String.valueOf(obj)); } counter++; } sheet.autoSizeColumn(0); }
From source file:org.optapconf.plannerbenchmark.ConferenceFileIO.java
License:Apache License
@Override public void write(Solution solution, File outputSolutionFile) { Conference conference = (Conference) solution; XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet("Conference"); XSSFRow headerRow = sheet.createRow(0); int x = 1;//from ww w. j a va 2 s.c o m Map<Room, Integer> roomXMap = new HashMap<>(conference.getRoomList().size()); for (Room room : conference.getRoomList()) { XSSFCell cell = headerRow.createCell(x); cell.setCellValue(room.getName()); roomXMap.put(room, x); x++; } int y = 1; Map<Timeslot, XSSFRow> timeslotRowMap = new HashMap<>(conference.getTimeslotList().size()); for (Timeslot timeslot : conference.getTimeslotList()) { XSSFRow row = sheet.createRow(y); XSSFCell cell = row.createCell(0); cell.setCellValue(timeslot.getDay().getName() + " - " + timeslot.getName()); timeslotRowMap.put(timeslot, row); y++; } for (Talk talk : conference.getTalkList()) { Timeslot timeslot = talk.getTimeslot(); Room room = talk.getRoom(); if (timeslot != null && room != null) { XSSFCell cell = timeslotRowMap.get(timeslot).createCell(roomXMap.get(room)); cell.setCellValue(talk.getTitle()); } else { XSSFCell unassignedCell = sheet.createRow(y).createCell(1); unassignedCell.setCellValue(talk.getTitle()); y++; } } try { try (OutputStream out = new FileOutputStream(outputSolutionFile)) { workbook.write(out); workbook.close(); } } catch (IOException e) { throw new IllegalStateException("Problem writing outputSolutionFile (" + outputSolutionFile + ").", e); } }
From source file:org.rapidpm.data.table.export.Table2XLSX.java
License:Apache License
@Override public ByteArrayOutputStream export(final Table table) { final XSSFWorkbook workbook = new XSSFWorkbook(); final XSSFSheet xssfSheet = workbook.createSheet(table.getTableName()); final Collection<ColumnInformation> infoList = table.getColumnInfoList(); final XSSFRow xssfHeaderRow = xssfSheet.createRow(0); for (final ColumnInformation information : infoList) { if (information.isExportable()) { final XSSFCell xssfCell = xssfHeaderRow.createCell(information.getSpaltenNr()); xssfCell.setCellValue(information.getSpaltenName()); xssfCell.setCellType(XSSFCell.CELL_TYPE_STRING); } else {/*from ww w. j ava 2 s . c om*/ if (logger.isDebugEnabled()) { logger.debug("ColInfo not exportable " + information.getSpaltenName()); } } } final List<Row> tableRowList = table.getRowList(); for (final Row row : tableRowList) { final XSSFRow xssfRow = xssfSheet.createRow(row.getRowNr() + 1); final List<Cell> cellList = row.getCells(); for (final Cell cell : cellList) { if (cell.getColInfo().isExportable()) { final XSSFCell xssfCell = xssfRow.createCell(cell.getColInfo().getSpaltenNr()); final CellTypeEnum cellType = cell.getCellType(); if (cellType.equals(CellTypeEnum.RawData)) { xssfCell.setCellValue(cell.getFormattedValue()); xssfCell.setCellType(XSSFCell.CELL_TYPE_STRING); //JIRA MOD-32 CellType in Abhngigkeit der ValueClass z.B. Number } else if (cellType.equals(CellTypeEnum.RawLink)) { final XSSFCreationHelper helper = workbook.getCreationHelper(); final XSSFHyperlink xssfHyperlink = helper.createHyperlink(Hyperlink.LINK_URL); xssfHyperlink.setAddress(cell.getFormattedValue()); xssfHyperlink.setLabel(cell.getLabel()); xssfCell.setCellValue(cell.getLabel()); xssfCell.setHyperlink(xssfHyperlink); final CellStyle hlink_style = createHyperLinkStyle(workbook); xssfCell.setCellStyle(hlink_style); } else { } } else { if (logger.isDebugEnabled()) { logger.debug("Cell not exportable "); } } } } final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { workbook.write(outputStream); } catch (IOException e) { logger.error(e); } return outputStream; }
From source file:org.rapidpm.modul.javafx.tableview.filtered.contextmenue.FilteredTableContextMenu.java
License:Apache License
private byte[] convertTable2Xls() throws IOException { //konvertiere final XSSFWorkbook workbook = new XSSFWorkbook(); final XSSFSheet xssfSheet = workbook.createSheet("ExcelExport_" + sdf.format(new Date())); final XSSFRow xssfHeaderRow = xssfSheet.createRow(0); final ObservableList<TableColumn> columns = filteredTableView.getColumns(); int colNr = 0; for (final TableColumn column : columns) { final String columnText = column.getText(); final XSSFCell xssfCell = xssfHeaderRow.createCell(colNr); colNr = colNr + 1;// w ww. j av a 2 s .c om xssfCell.setCellValue(columnText); xssfCell.setCellType(XSSFCell.CELL_TYPE_STRING); } final ObservableList<FilteredTableDataRow> rowList = filteredTableView.getItems(); int rowNr = 0; for (final FilteredTableDataRow row : rowList) { final XSSFRow xssfRow = xssfSheet.createRow(rowNr); rowNr = rowNr + 1; final String csvRow = row.convertToCSV(); final String[] split = csvRow.split(";"); int cellNr = 0; for (final String s : split) { final XSSFCell xssfCell = xssfRow.createCell(cellNr); cellNr = cellNr + 1; xssfCell.setCellValue(s); xssfCell.setCellType(XSSFCell.CELL_TYPE_STRING); } } final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { workbook.write(outputStream); } catch (IOException e) { logger.error(e); } return outputStream.toByteArray(); }
From source file:org.structr.excel.ToExcelFunction.java
License:Open Source License
public Workbook writeExcel(final List list, final String propertyView, final List<String> properties, final boolean includeHeader, final boolean localizeHeader, final String headerLocalizationDomain, final Locale locale, final Integer maxCellLength, final String overflowMode) throws IOException { final Workbook workbook = new XSSFWorkbook(); final CreationHelper factory = workbook.getCreationHelper(); final XSSFSheet sheet = (XSSFSheet) workbook.createSheet(); final Drawing drawing = sheet.createDrawingPatriarch(); int rowCount = 0; int cellCount = 0; XSSFRow currentRow = null;/*from w w w . j a va 2 s .com*/ XSSFCell cell = null; if (includeHeader) { currentRow = (XSSFRow) sheet.createRow(rowCount++); cellCount = 0; if (propertyView != null) { final Object obj = list.get(0); if (obj instanceof GraphObject) { for (PropertyKey key : ((GraphObject) obj).getPropertyKeys(propertyView)) { cell = (XSSFCell) currentRow.createCell(cellCount++); String value = key.dbName(); if (localizeHeader) { try { value = LocalizeFunction.getLocalization(locale, value, headerLocalizationDomain); } catch (FrameworkException fex) { logger.warn("to_excel(): Exception", fex); } } cell.setCellValue(value); } } else { cell = (XSSFCell) currentRow.createCell(cellCount++); cell.setCellValue( "Error: Object is not of type GraphObject, can not determine properties of view for header row"); } } else if (properties != null) { for (final String colName : properties) { cell = (XSSFCell) currentRow.createCell(cellCount++); String value = colName; if (localizeHeader) { try { value = LocalizeFunction.getLocalization(locale, value, headerLocalizationDomain); } catch (FrameworkException fex) { logger.warn("to_excel(): Exception", fex); } } cell.setCellValue(value); } } } for (final Object obj : list) { currentRow = (XSSFRow) sheet.createRow(rowCount++); cellCount = 0; if (propertyView != null) { if (obj instanceof GraphObject) { for (PropertyKey key : ((GraphObject) obj).getPropertyKeys(propertyView)) { final Object value = ((GraphObject) obj).getProperty(key); cell = (XSSFCell) currentRow.createCell(cellCount++); writeToCell(factory, drawing, cell, value, maxCellLength, overflowMode); } } else { cell = (XSSFCell) currentRow.createCell(cellCount++); cell.setCellValue( "Error: Object is not of type GraphObject, can not determine properties of object"); } } else if (properties != null) { if (obj instanceof GraphObject) { final GraphObject castedObj = (GraphObject) obj; for (final String colName : properties) { final PropertyKey key = StructrApp.key(obj.getClass(), colName); final Object value = castedObj.getProperty(key); cell = (XSSFCell) currentRow.createCell(cellCount++); writeToCell(factory, drawing, cell, value, maxCellLength, overflowMode); } } else if (obj instanceof Map) { final Map castedObj = (Map) obj; for (final String colName : properties) { final Object value = castedObj.get(colName); cell = (XSSFCell) currentRow.createCell(cellCount++); writeToCell(factory, drawing, cell, value, maxCellLength, overflowMode); } } } } return workbook; }
From source file:org.structr.excel.ToExcelFunction.java
License:Open Source License
public void writeToCell(final CreationHelper factory, final Drawing drawing, final XSSFCell cell, final Object value, final Integer maxCellLength, final String overflowMode) { final String cellValue = escapeForExcel(value); if (cellValue.length() <= maxCellLength) { cell.setCellValue(cellValue); } else {/*from www. j a v a 2s. co m*/ cell.setCellValue(cellValue.substring(0, maxCellLength)); if (!overflowMode.equals("t")) { final Comment comment = drawing.createCellComment(factory.createClientAnchor()); if (overflowMode.equals("o")) { final String overflow = cellValue.substring(maxCellLength, Math.min(maxCellLength + 32767, cellValue.length())); comment.setString(factory.createRichTextString(overflow)); } else { comment.setString(factory.createRichTextString(overflowMode)); } cell.setCellComment(comment); } } }
From source file:org.talend.mdm.webapp.browserecords.server.servlet.DownloadData.java
License:Open Source License
protected void fillHeader(XSSFRow row) { for (int i = 0; i < headerArray.length; i++) { XSSFCell cell = row.createCell((short) i); cell.setCellValue(headerArray[i]); cell.setCellStyle(cs);/*from w ww .j a v a 2s .c o m*/ } }
From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase.java
License:Open Source License
/** * ????/*from www .jav a2 s .c o m*/ * @param cell * @param value * @return */ protected XSSFCell setCellValue(XSSFCell cell, String value) { if (value != null) { cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(value); } else { cell.setCellType(XSSFCell.CELL_TYPE_BLANK); } return cell; }
From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase.java
License:Open Source License
/** * ????/* w ww.j a v a2 s . c o m*/ * @param cell * @param value * @return */ protected XSSFCell setCellValue(XSSFCell cell, Integer value) { if (value != null) { cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(value); } else { cell.setCellType(XSSFCell.CELL_TYPE_BLANK); } return cell; }
From source file:org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase.java
License:Open Source License
/** * ????/*w w w.ja v a 2 s . c om*/ * @param cell * @param value * @return */ protected XSSFCell setCellValue(XSSFCell cell, Date value) { if (value != null) { cell.setCellType(XSSFCell.CELL_TYPE_STRING); cell.setCellValue(new SimpleDateFormat("yyyy/MM/dd").format(value)); } else { cell.setCellType(XSSFCell.CELL_TYPE_BLANK); } return cell; }