List of usage examples for org.apache.poi.ss.usermodel Row setZeroHeight
void setZeroHeight(boolean zHeight);
From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.SummaryReportGenerator.java
License:Apache License
/** * Creates Monthly Sheet//from w w w .j a v a 2s . co m */ private void createMonthlySheet(Workbook p_workbook, Sheet p_sheet, ReportSearchOptions p_options, Map<String, ReportWordCount> p_wordCounts) throws Exception { List<String> searchMonths = p_options.getMonths(); CellStyle style = getHeaderStyle(p_workbook); CellStyle style1 = getHeaderStyle(p_workbook, null, null, null, null); CellStyle styleTB = getHeaderStyle(p_workbook, CellStyle.BORDER_THIN, null, CellStyle.BORDER_THIN, null); CellStyle styleTB2 = getHeaderStyle(p_workbook, CellStyle.BORDER_THIN, null, CellStyle.BORDER_THIN, null); styleTB2.setAlignment(CellStyle.ALIGN_RIGHT); CellStyle styleLR = getHeaderStyle(p_workbook, null, CellStyle.BORDER_THIN, null, CellStyle.BORDER_THIN); int row = ROWNUMBER, column = 0; p_sheet.setColumnWidth(0, 12 * 256); Cell cell_A_Header = getCell(getRow(p_sheet, row), column++); cell_A_Header.setCellValue(bundle.getString("lb_sumOfTotal")); cell_A_Header.setCellStyle(style); p_sheet.addMergedRegion(new CellRangeAddress(row, row, column, column + searchMonths.size())); setRegionStyle(p_sheet, new CellRangeAddress(row, row, column, column + searchMonths.size()), style); Cell cell_B_Header = getCell(getRow(p_sheet, row), column); cell_B_Header.setCellValue(bundle.getString("lb_month")); cell_B_Header.setCellStyle(style); row++; column = 0; Cell cell_A = getCell(getRow(p_sheet, row), column++); cell_A.setCellValue(bundle.getString("lb_lang")); cell_A.setCellStyle(style); for (String yearAndMonth : searchMonths) { Cell cell_Month = getCell(getRow(p_sheet, row), column++); cell_Month.setCellValue(Double.valueOf(yearAndMonth.substring(4))); cell_Month.setCellStyle(styleTB); } p_sheet.setColumnWidth(column, 10 * 256); Cell cell_LocaleTotal = getCell(getRow(p_sheet, row), column++); cell_LocaleTotal.setCellValue(bundle.getString("lb_grandTotal")); cell_LocaleTotal.setCellStyle(style); // Adds a hidden column, for Excel Sum Check Error. Row hiddenRow = getRow(p_sheet, ++row); hiddenRow.setZeroHeight(isHidden); getRow(p_sheet, row - 1).setHeight(p_sheet.getDefaultRowHeight()); int dataRow = ++row; column = 0; double totalWordCount = 0; Set<String> locales = getLocals(p_wordCounts); for (String locale : locales) { Cell cell_A_Locale = getCell(getRow(p_sheet, row), column++); cell_A_Locale.setCellValue(locale); cell_A_Locale.setCellStyle(styleLR); for (String yearAndMonth : searchMonths) { ReportWordCount reportWordCount = p_wordCounts.get(getWordCountMapKey(locale, yearAndMonth)); if (reportWordCount != null) { totalWordCount = reportWordCount.getTradosTotalWordCount(); } addNumberCell(p_sheet, column++, row, totalWordCount, style1); totalWordCount = 0; } Cell cell_LocaleTotal_Month = getCell(getRow(p_sheet, row), column); cell_LocaleTotal_Month.setCellFormula(getSumOfRow(1, column - 1, row)); cell_LocaleTotal_Month.setCellStyle(styleLR); row++; column = 0; } if (row > (ROWNUMBER + 3)) { column = 0; Cell cell_GrandTotal = getCell(getRow(p_sheet, row), column++); cell_GrandTotal.setCellValue(bundle.getString("lb_grandTotal")); cell_GrandTotal.setCellStyle(style); for (int i = 0; i < searchMonths.size(); i++) { Cell cell_MonthTotal = getCell(getRow(p_sheet, row), column); cell_MonthTotal.setCellFormula(getSumOfColumn(dataRow, row - 1, column)); cell_MonthTotal.setCellStyle(styleTB); column++; } Cell cell_Total = getCell(getRow(p_sheet, row), column); cell_Total.setCellFormula(getSumOfColumn(dataRow, row - 1, column)); cell_Total.setCellStyle(style); } }
From source file:com.runwaysdk.dataaccess.io.excel.ErrorSheet.java
License:Open Source License
public void addRow(Row _row) { Row row = this.errorSheet.createRow(count++); row.setZeroHeight(_row.getZeroHeight()); row.setHeight(_row.getHeight());/*from w w w . ja va 2 s. c o m*/ CellStyle style = _row.getRowStyle(); if (style != null) { Workbook workbook = row.getSheet().getWorkbook(); CellStyle clone = workbook.createCellStyle(); clone.cloneStyleFrom(style); row.setRowStyle(clone); } Iterator<Cell> cellIterator = _row.cellIterator(); while (cellIterator.hasNext()) { Cell oldCell = cellIterator.next(); Cell newCell = row.createCell(oldCell.getColumnIndex()); int cellType = oldCell.getCellType(); if (cellType == Cell.CELL_TYPE_FORMULA) { cellType = oldCell.getCachedFormulaResultType(); } switch (cellType) { case Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getRichStringCellValue()); break; } } }
From source file:com.runwaysdk.dataaccess.io.ExcelExportSheet.java
License:Open Source License
/** * Prepares a new sheet (which represents a type) in the workbook. Fills in all necessary information for the sheet. * //www. j av a 2 s .c o m * @return */ public Sheet createSheet(Workbook workbook, CellStyle boldStyle) { CreationHelper helper = workbook.getCreationHelper(); String sheetName = this.getFormattedSheetName(); Sheet sheet = workbook.createSheet(sheetName); Drawing drawing = sheet.createDrawingPatriarch(); Row typeRow = sheet.createRow(0); typeRow.setZeroHeight(true); Row nameRow = sheet.createRow(1); nameRow.setZeroHeight(true); Row labelRow = sheet.createRow(2); int i = 0; for (ExcelColumn column : this.getExpectedColumns()) { writeHeader(sheet, drawing, nameRow, labelRow, i++, column, boldStyle); } for (ExcelColumn column : this.getExtraColumns()) { writeHeader(sheet, drawing, nameRow, labelRow, i++, column, boldStyle); } typeRow.createCell(0).setCellValue(helper.createRichTextString(this.getType())); this.writeRows(sheet); return sheet; }
From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java
License:Open Source License
/** * Hides or shows the given row, see {@link Row#setZeroHeight(boolean)}. * //from w w w . ja v a 2 s . c o m * @param rowIndex * Index of the target row, 0-based * @param hidden * True to hide the target row, false to show it. */ public void setRowHidden(int rowIndex, boolean hidden) { final Sheet activeSheet = getActiveSheet(); Row row = activeSheet.getRow(rowIndex); if (row == null) { row = activeSheet.createRow(rowIndex); } row.setZeroHeight(hidden); if (hidden && !getState().hiddenRowIndexes.contains(rowIndex + 1)) { getState().hiddenRowIndexes.add(rowIndex + 1); getState().rowH[rowIndex] = 0.0F; } else if (!hidden && getState().hiddenRowIndexes.contains(rowIndex + 1)) { getState().hiddenRowIndexes.remove(getState().hiddenRowIndexes.indexOf(rowIndex + 1)); getState().rowH[rowIndex] = row.getHeightInPoints(); } if (hasSheetOverlays()) { reloadImageSizesFromPOI = true; loadOrUpdateOverlays(); } }
From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java
License:Open Source License
/** * Sets the row height for currently active sheet. Updates both POI model * and the visible sheet.// w w w . j av a 2 s. c o m * * @param index * Index of target row, 0-based * @param height * New row height in points */ public void setRowHeight(int index, float height) { if (height == 0.0F) { setRowHidden(index, true); } else { Row row = getActiveSheet().getRow(index); if (getState().hiddenRowIndexes.contains(Integer.valueOf(index + 1))) { getState().hiddenRowIndexes.remove(Integer.valueOf(index + 1)); if (row != null && row.getZeroHeight()) { row.setZeroHeight(false); } } getState().rowH[index] = height; if (row == null) { row = getActiveSheet().createRow(index); } row.setHeightInPoints(height); } }
From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java
License:Apache License
@SuppressWarnings("unchecked") private static void write(boolean useTemplate, Workbook workbook, OutputStream outputStream, ExcelWriteSheetProcessor<?>... sheetProcessors) { for (@SuppressWarnings("rawtypes") ExcelWriteSheetProcessor sheetProcessor : sheetProcessors) { @SuppressWarnings("rawtypes") ExcelWriteContext context = new ExcelWriteContext(); try {/* ww w . ja v a 2 s. c o m*/ if (sheetProcessor == null) { continue; } String sheetName = sheetProcessor.getSheetName(); Integer sheetIndex = sheetProcessor.getSheetIndex(); Sheet sheet = null; if (sheetProcessor.getTemplateStartRowIndex() == null && sheetProcessor.getTemplateEndRowIndex() == null) { sheetProcessor.setTemplateRows(sheetProcessor.getStartRowIndex(), sheetProcessor.getStartRowIndex()); } // sheetName priority, if (useTemplate) { if (sheetName != null) { try { sheet = workbook.getSheet(sheetName); } catch (IllegalArgumentException e) { // ignore } if (sheet != null && sheetIndex != null && !sheetIndex.equals(workbook.getSheetIndex(sheet))) { throw new IllegalArgumentException( "sheetName[" + sheetName + "] and sheetIndex[" + sheetIndex + "] not match."); } } else if (sheetIndex != null) { try { sheet = workbook.getSheetAt(sheetIndex); } catch (IllegalArgumentException e) { // ignore } } else { throw new IllegalArgumentException("sheetName or sheetIndex can't be null"); } if (sheet == null) { ExcelWriteException e = new ExcelWriteException( "Sheet Not Found Exception. for sheet name:" + sheetName); e.setCode(ExcelWriteException.CODE_OF_SHEET_NOT_EXSIT); throw e; } } else { if (sheetName != null) { sheet = workbook.getSheet(sheetName); if (sheet != null) { if (sheetIndex != null && !sheetIndex.equals(workbook.getSheetIndex(sheet))) { throw new IllegalArgumentException("sheetName[" + sheetName + "] and sheetIndex[" + sheetIndex + "] not match."); } } else { sheet = workbook.createSheet(sheetName); if (sheetIndex != null) { workbook.setSheetOrder(sheetName, sheetIndex); } } } else if (sheetIndex != null) { sheet = workbook.createSheet(); workbook.setSheetOrder(sheet.getSheetName(), sheetIndex); } else { throw new IllegalArgumentException("sheetName or sheetIndex can't be null"); } } if (sheetIndex == null) { sheetIndex = workbook.getSheetIndex(sheet); } if (sheetName == null) { sheetName = sheet.getSheetName(); } // proc sheet context.setCurSheet(sheet); context.setCurSheetIndex(sheetIndex); context.setCurSheetName(sheet.getSheetName()); context.setCurRow(null); context.setCurRowIndex(null); context.setCurCell(null); context.setCurColIndex(null); // beforeProcess sheetProcessor.beforeProcess(context); // write head writeHead(useTemplate, sheet, sheetProcessor); // sheet ExcelProcessControllerImpl controller = new ExcelProcessControllerImpl(); int writeRowIndex = sheetProcessor.getStartRowIndex(); boolean isBreak = false; Map<Integer, InnerRow> cacheForTemplateRow = new HashMap<Integer, InnerRow>(); List<?> dataList = sheetProcessor.getDataList(); // if (dataList != null && !dataList.isEmpty()) { for (Object rowData : dataList) { // proc row Row row = sheet.getRow(writeRowIndex); if (row == null) { row = sheet.createRow(writeRowIndex); } InnerRow templateRow = getTemplateRow(cacheForTemplateRow, sheet, sheetProcessor, writeRowIndex); if (templateRow != null) { row.setHeight(templateRow.getHeight()); row.setHeightInPoints(templateRow.getHeightInPoints()); row.setRowStyle(templateRow.getRowStyle()); row.setZeroHeight(templateRow.isZeroHeight()); } context.setCurRow(row); context.setCurRowIndex(writeRowIndex); context.setCurColIndex(null); context.setCurCell(null); // try { controller.reset(); if (sheetProcessor.getRowProcessor() != null) { sheetProcessor.getRowProcessor().process(controller, context, rowData, row); } if (!controller.isDoSkip()) { writeRow(context, templateRow, row, rowData, sheetProcessor); writeRowIndex++; } if (controller.isDoBreak()) { isBreak = true; break; } } catch (RuntimeException e) { if (e instanceof ExcelWriteException) { ExcelWriteException ewe = (ExcelWriteException) e; // ef.setColIndex(null); user may want to set this value, ewe.setRowIndex(writeRowIndex); throw ewe; } else { ExcelWriteException ewe = new ExcelWriteException(e); ewe.setColIndex(null); ewe.setCode(ExcelWriteException.CODE_OF_PROCESS_EXCEPTION); ewe.setRowIndex(writeRowIndex); throw ewe; } } } if (isBreak) { break; } } if (sheetProcessor.getTemplateStartRowIndex() != null && sheetProcessor.getTemplateEndRowIndex() != null) { writeDataValidations(sheet, sheetProcessor); writeStyleAfterFinish(useTemplate, sheet, sheetProcessor); } } catch (RuntimeException e) { sheetProcessor.onException(context, e); } finally { sheetProcessor.afterProcess(context); } } try { workbook.write(outputStream); } catch (IOException e) { throw new RuntimeException(e); } }