org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(193)

本文整理了Java中org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn()方法的一些代码示例,展示了HSSFSheet.autoSizeColumn()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFSheet.autoSizeColumn()方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFSheet
类名称:HSSFSheet
方法名:autoSizeColumn

HSSFSheet.autoSizeColumn介绍

[英]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.
[中]调整列宽以适应内容。在大型工作表上,此过程可能相对较慢,因此通常在处理结束时,每列只调用一次。

代码示例

代码示例来源:origin: org.apache.poi/poi

/**
 * 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);
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * 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);
}

代码示例来源:origin: com.haulmont.thirdparty/poi

/**
 * 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);
}

代码示例来源:origin: stackoverflow.com

int colMaxLength = workbook.getActiveSheetIndex().getRow(0).getLastCellNum();
HSSFSheet activeSheet = workbook.getSheetAt(workbook.getActiveSheetIndex());
for(int i = 0 ; i < colMaxLength ; i++){
  activeSheet.autoSizeColumn(i);
}

代码示例来源:origin: displaytag/displaytag-export-poi

/**
   * @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++);
    }
  }
}

代码示例来源:origin: com.github.hazendaz/displaytag

/**
 * @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++);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * 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);
}

代码示例来源:origin: stackoverflow.com

//
// 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));     
}

代码示例来源:origin: com.jalalkiswani/jk-util

/**
 */
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));
    }
  }
}

代码示例来源:origin: com.haulmont.yarg/yarg

@Override
  public void apply() {
    for (DataObject dataObject : data) {
      dataObject.resultCell.getSheet().autoSizeColumn(dataObject.resultCell.getColumnIndex());
    }
  }
}

代码示例来源:origin: cuba-platform/yarg

@Override
  public void apply() {
    for (DataObject dataObject : data) {
      dataObject.resultCell.getSheet().autoSizeColumn(dataObject.resultCell.getColumnIndex());
    }
  }
}

代码示例来源:origin: qcadoo/mes

@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);
}

代码示例来源:origin: stackoverflow.com

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;

代码示例来源:origin: paypal/SeLion

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();
}

代码示例来源:origin: stackoverflow.com

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);
    }

代码示例来源:origin: qcadoo/mes

@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);
  }
}

代码示例来源:origin: com.github.hazendaz/displaytag

/**
 * 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);
  }
}

代码示例来源:origin: riotfamily/riot

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));			
}

代码示例来源:origin: qcadoo/mes

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);
  }
}

代码示例来源:origin: riotfamily/riot

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);
}

相关文章

微信公众号

最新文章

更多

HSSFSheet类方法