/** * Adjusts the column width to fit the contents.<p> * * This process can be relatively slow on large sheets, so this should * normally only be called once per column, at the end of your * processing. * * @param column the column index */ @Override public void autoSizeColumn(int column) { autoSizeColumn(column, false); }
/** * Adjusts the column width to fit the contents. * * This process can be relatively slow on large sheets, so this should * normally only be called once per column, at the end of your * processing. * * @param column the column index */ public void autoSizeColumn(int column) { autoSizeColumn(column, false); }
/** * Adjusts the column width to fit the contents. * <p/> * This process can be relatively slow on large sheets, so this should * normally only be called once per column, at the end of your * processing. * * @param column the column index */ public void autoSizeColumn(int column) { autoSizeColumn(column, false); }
int colMaxLength = workbook.getActiveSheetIndex().getRow(0).getLastCellNum(); HSSFSheet activeSheet = workbook.getSheetAt(workbook.getActiveSheetIndex()); for(int i = 0 ; i < colMaxLength ; i++){ activeSheet.autoSizeColumn(i); }
/** * @see org.displaytag.render.TableWriterAdapter#writeBottomBanner(org.displaytag.model.TableModel) */ protected void writeBottomBanner(TableModel model) throws Exception { // adjust the column widths int colCount = 0; while (colCount <= colNum) { sheet.autoSizeColumn((short) colCount++); } } }
/** * @see org.displaytag.render.TableWriterAdapter#writeBottomBanner(org.displaytag.model.TableModel) */ @Override protected void writeBottomBanner(TableModel model) throws Exception { // adjust the column widths int colCount = 0; while (colCount <= this.colNum) { this.sheet.autoSizeColumn((short) colCount++); } }
/** * Adjusts the column width to fit the contents.<p> * * This process can be relatively slow on large sheets, so this should * normally only be called once per column, at the end of your * processing. * * @param column the column index */ @Override public void autoSizeColumn(int column) { autoSizeColumn(column, false); }
// // Create an instance of workbook and sheet // HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.createSheet(); sheet.setAutobreaks(true); . .//code in which you create actual rows and cells HERE . //auto formating to fit the page for(int i=0; i<repModel.getReportHeaders().length;i++){ sheet.autoSizeColumn((short) (i+1)); }
/** */ protected void setColumnsWidth() { int counter = 1; for (int i = 0; i < this.model.getColumnCount(); i++) { if (this.model.isVisible(i)) { this.sheet.autoSizeColumn(counter++); // sheet.setColumnWidth((short) i, (short) // (model.getColunmWidth(i) * 255)); } } }
@Override public void apply() { for (DataObject dataObject : data) { dataObject.resultCell.getSheet().autoSizeColumn(dataObject.resultCell.getColumnIndex()); } } }
@Override public void apply() { for (DataObject dataObject : data) { dataObject.resultCell.getSheet().autoSizeColumn(dataObject.resultCell.getColumnIndex()); } } }
@Override protected void addSeries(final HSSFSheet sheet, final Entity materialsInLocation) { Map<Entity, BigDecimal> reportData = materialFlowService.calculateMaterialQuantitiesInLocation(materialsInLocation); int rowNum = 1; for (Map.Entry<Entity, BigDecimal> data : reportData.entrySet()) { HSSFRow row = sheet.createRow(rowNum++); row.createCell(0).setCellValue(data.getKey().getStringField(NUMBER)); row.createCell(1).setCellValue(data.getKey().getStringField(NAME)); row.createCell(2).setCellValue(numberService.format(data.getValue())); row.createCell(3).setCellValue(data.getKey().getStringField(UNIT)); } sheet.autoSizeColumn((short) 0); sheet.autoSizeColumn((short) 1); sheet.autoSizeColumn((short) 2); sheet.autoSizeColumn((short) 3); }
HSSFWorkbook workbook = new HSSFWorkbook(); Iterator<E> iterator = elementList.iterator(); for (int wsNum = 0; wsNum <= (totalNumberOfElements / 65536); wsNum++) { HSSFSheet worksheet = workbook.createSheet("Name of worksheet " + wsNum); for (long i = wsNum * 65536; i < ((wsNum + 1) * 65536); i++) { int ii = ((Long) (i % 65536)).intValue(); if (!iterator.hasNext()) { break; } HSSFRow row = worksheet.createRow(ii); E e = iterator.next(); for(int columnNum = 0; columnNum < maxColumnNum; columnNum++) { HSSFCell cell = row.createCell(columnNum); cell.setCellValue(e.getProperty(columnNum)); //figure out something smart for this one } } } for(int columnNum = 0; columnNum < maxColumnNum; columnNum++) worksheet.autoSizeColumn(columnNum); } return workbook;
private void createTitles(HSSFSheet sheet, int rowNum, int iColStart, HSSFCellStyle style) { logger.entering(new Object[] { sheet, rowNum, iColStart, style }); HSSFRow row = sheet.createRow(rowNum); HSSFCell newCell; int colStart = iColStart; for (int iTitle = 0; iTitle < this.colTitles.size(); iTitle++) { newCell = row.createCell(colStart); newCell.setCellValue(colTitles.get(iTitle)); newCell.setCellStyle(style); sheet.autoSizeColumn(colStart++); } logger.exiting(); }
private void createCellAndSetValue(HSSFRow row1, int i, String value,HSSFSheet sheet,HSSFCellStyle style) { HSSFCell cell=row1.createCell(i); setCellValue(cell, value); sheet.autoSizeColumn(i); setCellStyle(cell, style); style.setWrapText(true); } for (int i = 0; i < list.Size(); i++) { HSSFRow row = sheet.createRow(count); createCellAndSetValue(row,1,list.get(i),sheet,style); createCellAndSetValue(row,2,listOne.get(i),sheet,style); }
@Override protected void addSeries(final HSSFSheet sheet, final Entity assignmentToShiftReport) { List<DateTime> days = assignmentToShiftXlsHelper.getDaysBetweenGivenDates(assignmentToShiftReport); if (days != null) { int rowNum = 5; List<Entity> occupationTypesWithoutTechnicalCode = getOccupationTypeDictionaryWithoutTechnicalCode(); List<Entity> productionlines = assignmentToShiftXlsHelper.getProductionLines(); if (!productionlines.isEmpty()) { rowNum = fillColumnWithStaffForWorkOnLine(sheet, rowNum, assignmentToShiftReport, days, productionlines, getDictionaryItemWithProductionOnLine()); } for (Entity dictionaryItem : occupationTypesWithoutTechnicalCode) { rowNum = fillColumnWithStaffForOtherTypes(sheet, rowNum, assignmentToShiftReport, days, dictionaryItem); } fillColumnWithStaffForOtherTypes(sheet, rowNum, assignmentToShiftReport, days, getDictionaryItemWithOtherCase()); sheet.autoSizeColumn(0); } }
/** * Uses POI Autosizing. WARNING. This has been known to cause performance problems and various exceptions. use at * your own risk! Overriding this method is suggested. From POI HSSF documentation for autoSizeColumn: "To calculate * column width HSSFSheet.autoSizeColumn uses Java2D classes that throw exception if graphical environment is not * available. In case if graphical environment is not available, you must tell Java that you are running in headless * mode and set the following system property: java.awt.headless=true." */ protected void autosizeColumns() { for (int i = 0; i < getModel().getNumberOfColumns(); i++) { getSheet().autoSizeColumn((short) i); // since this usually creates column widths that are just too short, adjust here! // gives column width an extra character int width = getSheet().getColumnWidth(i); width += 256; getSheet().setColumnWidth(i, (short) width); } }
private void createRows(Collection<?> items) { int i = 1; for (Object item : items) { MessageBundleEntry entry = (MessageBundleEntry) item; HSSFRow row = sheet.createRow(i++); addCell(row, 0, getCategory(entry), editable); addCell(row, 1, entry.getCode(), locked); addCell(row, 2, entry.getDefaultText(), locked); addCell(row, 3, entry.getComment(), editable); } sheet.autoSizeColumn(0); sheet.setColumnWidth(1, (25 * 256)); sheet.setColumnWidth(2, (50 * 256)); sheet.setColumnWidth(3, (50 * 256)); }
private void createProducedQuantitiesSheet(HSSFSheet sheet, List<Long> ordersIds, StylesContainer stylesContainer) { List<ProducedQuantity> producedQuantities = productionBalanceRepository.getProducedQuantities(ordersIds); int rowIndex = 1; for (ProducedQuantity producedQuantity : producedQuantities) { HSSFRow row = sheet.createRow(rowIndex); createRegularCell(stylesContainer, row, 0, producedQuantity.getOrderNumber()); createRegularCell(stylesContainer, row, 1, producedQuantity.getProductNumber()); createRegularCell(stylesContainer, row, 2, producedQuantity.getProductName()); createNumericCell(stylesContainer, row, 3, producedQuantity.getPlannedQuantity(), false); createNumericCell(stylesContainer, row, 4, producedQuantity.getProducedQuantity(), true); createNumericCell(stylesContainer, row, 5, producedQuantity.getWastesQuantity(), false); createNumericCell(stylesContainer, row, 6, producedQuantity.getProducedWastes(), false); createNumericCell(stylesContainer, row, 7, producedQuantity.getDeviation(), false); createRegularCell(stylesContainer, row, 8, producedQuantity.getProductUnit()); rowIndex++; } for (int i = 0; i < PRODUCTION_QUANTITIES_HEADERS.size(); i++) { sheet.autoSizeColumn(i, false); } }
private void createRows(Collection<?> items, Locale locale) { int i = 1; for (Object item : items) { Message message = (Message) item; String translation = null; if (message.getLocale().equals(locale)) { translation = message.getText(); } HSSFRow row = sheet.createRow(i++); addCell(row, 0, getCategory(message), editable); addCell(row, 1, message.getEntry().getCode(), locked); addCell(row, 2, message.getEntry().getDefaultText(), locked); addCell(row, 3, translation, editable); addCell(row, 4, message.getEntry().getComment(), editable); addCell(row, 5, message.getText(), hidden); } sheet.autoSizeColumn(0); sheet.setColumnWidth(1, (25 * 256)); sheet.setColumnWidth(2, (50 * 256)); sheet.setColumnWidth(3, (50 * 256)); sheet.setColumnWidth(4, (50 * 256)); sheet.setColumnHidden(5, true); }