List of usage examples for org.apache.poi.xssf.streaming SXSSFSheet trackColumnForAutoSizing
public void trackColumnForAutoSizing(int column)
From source file:org.apache.tika.eval.reports.Report.java
License:Apache License
private void dumpReportToWorkbook(Statement st, SXSSFWorkbook wb) throws IOException, SQLException { ResultSet rs = st.executeQuery(sql); SXSSFSheet sheet = wb.createSheet("tika-eval Report"); sheet.trackColumnForAutoSizing(0); int rowCount = 0; ResultSetMetaData meta = rs.getMetaData(); Set<String> colNames = new HashSet<>(); Row xssfRow = sheet.createRow(rowCount++); //write headers and cache them to check against styles for (int i = 1; i <= meta.getColumnCount(); i++) { Cell cell = xssfRow.createCell(i - 1); cell.setCellValue(meta.getColumnLabel(i)); colNames.add(meta.getColumnLabel(i)); }/*from w ww .jav a 2 s . c om*/ ResultSetMetaData resultSetMetaData = rs.getMetaData(); while (rs.next()) { xssfRow = sheet.createRow(rowCount++); for (int i = 1; i <= meta.getColumnCount(); i++) { Cell cell = xssfRow.createCell(i - 1); XSLXCellFormatter formatter = cellFormatters.get(meta.getColumnLabel(i)); if (formatter == null) { formatter = getDefaultFormatter(resultSetMetaData.getColumnType(i)); } if (formatter != null) { formatter.applyStyleAndValue(i, rs, cell); } else { writeCell(meta, i, rs, cell); } } } sheet.autoSizeColumn(0); if (!includeSql) { return; } SXSSFSheet sqlSheet = wb.createSheet("tika-eval SQL"); sqlSheet.setColumnWidth(0, 100 * 250); Row sqlRow = sqlSheet.createRow(0); short height = 5000; sqlRow.setHeight(height); Cell cell = sqlRow.createCell(0); cell.setCellStyle(sqlCellStyle); cell.setCellValue(sql.trim());//.replaceAll("[\r\n]+", "\r\n")); }
From source file:org.jkiss.dbeaver.data.office.export.DataExporterXLSX.java
License:Apache License
private void printHeader(Worksheet wsh) { boolean hasDescription = false; if (showDescription) { for (DBDAttributeBinding column : columns) { if (!CommonUtils.isEmpty(column.getDescription())) { hasDescription = true;//from w ww .j a va 2 s . c o m break; } } } SXSSFSheet sh = (SXSSFSheet) wsh.getSh(); Row row = sh.createRow(wsh.getCurrentRow()); int startCol = rowNumber ? 1 : 0; for (int i = 0, columnsSize = columns.size(); i < columnsSize; i++) { sh.trackColumnForAutoSizing(i); DBDAttributeBinding column = columns.get(i); String colName = column.getLabel(); if (CommonUtils.isEmpty(colName)) { colName = column.getName(); } Cell cell = row.createCell(i + startCol, CellType.STRING); cell.setCellValue(colName); cell.setCellStyle(styleHeader); } if (hasDescription) { wsh.incRow(); Row descRow = sh.createRow(wsh.getCurrentRow()); for (int i = 0, columnsSize = columns.size(); i < columnsSize; i++) { Cell descCell = descRow.createCell(i + startCol, CellType.STRING); String description = columns.get(i).getDescription(); if (CommonUtils.isEmpty(description)) { description = ""; } descCell.setCellValue(description); descCell.setCellStyle(styleHeader); } } for (int i = 0, columnsSize = columns.size(); i < columnsSize; i++) { sh.autoSizeColumn(i); } wsh.incRow(); }