org.apache.poi.ss.usermodel.Sheet.getColumnWidth()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(302)

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

Sheet.getColumnWidth介绍

[英]get the width (in units of 1/256th of a character width )

Character width is defined as the maximum digit width of the numbers 0, 1, 2, ... 9 as rendered using the default font (first font in the workbook)
[中]获取宽度(以字符宽度的1/256为单位)
字符宽度定义为使用默认字体(工作簿中的第一种字体)呈现的数字0, 1, 2, ... 9的最大数字宽度

代码示例

代码示例来源:origin: net.sf.jxls/jxls-core

static int getWidth(Sheet sheet, int col) {
  int width = sheet.getColumnWidth(col);
  if (width == sheet.getDefaultColumnWidth()) {
    width = (int) (width * 256);
  }
  return width;
}

代码示例来源:origin: zhangdaiscott/jeasypoi

private int getTableWidth(Sheet sheet) {
  ensureColumnBounds(sheet);
  int width = 0;
  for (int i = firstColumn; i < endColumn; i++) {
    width = width + (sheet.getColumnWidth(i) / 32);
  }
  return width;
}

代码示例来源:origin: org.jeecg/easypoi-base

private int getTableWidth(Sheet sheet) {
  ensureColumnBounds(sheet);
  int width = 0;
  for (int i = firstColumn; i < endColumn; i++) {
    width = width + (sheet.getColumnWidth(i) / 32);
  }
  return width;
}

代码示例来源:origin: cn.afterturn/easypoi-base

private int getTableWidth(Sheet sheet) {
  ensureColumnBounds(sheet);
  int width = 0;
  for (int i = firstColumn; i < endColumn; i++) {
    width = width + (sheet.getColumnWidth(i) / 32);
  }
  return width;
}

代码示例来源:origin: org.jeecg/easypoi-base

private void printCols(Sheet sheet) {
  //out.format("<col/>%n");
  ensureColumnBounds(sheet);
  for (int i = firstColumn; i < endColumn; i++) {
    out.format("<col style='width:%spx;' />%n", sheet.getColumnWidth(i) / 32);
  }
}

代码示例来源:origin: SheetJS/jxls

static int getWidth(Sheet sheet, int col) {
  int width = sheet.getColumnWidth(col);
  if (width == sheet.getDefaultColumnWidth()) {
    width = (int) (width * 256);
  }
  return width;
}

代码示例来源:origin: xiaolanglang/easypoi

private void printCols(Sheet sheet) {
  //out.format("<col/>%n");
  ensureColumnBounds(sheet);
  for (int i = firstColumn; i < endColumn; i++) {
    out.format("<col style='width:%spx;' />%n", sheet.getColumnWidth(i) / 32);
  }
}

代码示例来源:origin: openl-tablets/openl-tablets

/**
 * Some magic numbers here What is column width???
 */
public static int getColumnWidth(int col, Sheet sheet) {
  int w = sheet.getColumnWidth((short) col);
  if (w == sheet.getDefaultColumnWidth()) {
    return 79;
  }
  return w / 40;
}

代码示例来源:origin: cn.afterturn/easypoi-base

private void printCols(Sheet sheet) {
  //out.format("<col/>%n");
  ensureColumnBounds(sheet);
  for (int i = firstColumn; i < endColumn; i++) {
    out.format("<col style='width:%spx;' />%n", sheet.getColumnWidth(i) / 32);
  }
}

代码示例来源:origin: zhangdaiscott/jeasypoi

private void printCols(Sheet sheet) {
  // out.format("<col/>%n");
  ensureColumnBounds(sheet);
  for (int i = firstColumn; i < endColumn; i++) {
    out.format("<col style='width:%spx;' />%n", sheet.getColumnWidth(i) / 32);
  }
}

代码示例来源:origin: xiaolanglang/easypoi

private int getTableWidth(Sheet sheet) {
  ensureColumnBounds(sheet);
  int width = 0;
  for (int i = firstColumn; i < endColumn; i++) {
    width = width + (sheet.getColumnWidth(i) / 32);
  }
  return width;
}

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

private static final int WIDTH_ARROW_BUTTON = 1300;

private void autosizeColumnsFromSheet(final Sheet excelSheet, final int fromColumn, final int toColumn) {
    for (int i = fromColumn; i <= toColumn; i++) {
      excelSheet.autoSizeColumn(new Short(String.valueOf(i)));
      try {
        excelSheet.setColumnWidth(i, excelSheet.getColumnWidth(i) + WIDTH_ARROW_BUTTON);
      } catch (final Exception e) {
        // don't do anything - just let autosize handle it
      }
    }
  }

代码示例来源:origin: xiaopotian1990/SpringBootExcel

private static void autoSizeColumns(Sheet sheet, int columnNumber) {
  for (int i = 0; i < columnNumber; i++) {
    int orgWidth = sheet.getColumnWidth(i);
    sheet.autoSizeColumn(i, true);
    int newWidth = (int) (sheet.getColumnWidth(i) + 100);
    if (newWidth > orgWidth) {
      sheet.setColumnWidth(i, newWidth);
    } else {
      sheet.setColumnWidth(i, orgWidth);
    }
  }
}

代码示例来源:origin: asakusafw/asakusafw

private static void adjustColumnWidth(Sheet sheet, int lastColumn) {
  assert sheet != null;
  for (int i = 0; i <= lastColumn; i++) {
    sheet.autoSizeColumn(i);
    int width = sheet.getColumnWidth(i);
    if (width < MINIMUM_COLUMN_WIDTH) {
      sheet.setColumnWidth(i, MINIMUM_COLUMN_WIDTH);
    }
  }
}

代码示例来源:origin: Adobe-Consulting-Services/acs-aem-commons

void autosize(Sheet sheet, int lastColumnIndex) {
    for (int i = 0; i <= lastColumnIndex; i++) {
      try {
        sheet.autoSizeColumn(i);
      } catch (Exception e) {
        // autosize depends on AWT stuff and can fail, but it should not be fatal
        LOG.warn("autoSizeColumn(" + i + ") failed: " + e.getMessage());
      }
      int cw = sheet.getColumnWidth(i);
      // increase width to accommodate drop-down arrow in the header
      if (cw / 256 < 20) {
        sheet.setColumnWidth(i, 256 * 12);
      } else if (cw / 256 > 120) {
        sheet.setColumnWidth(i, 256 * 120);
      }
    }
  }
}

代码示例来源:origin: org.jeecg/easypoi-base

@Override
public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) {
  if (StringUtils.isNoneBlank(style.getWidth())) {
    int width = (int) Math.round(PoiCssUtils.getInt(style.getWidth()) * 2048 / 8.43F);
    Sheet sheet = cell.getSheet();
    int colIndex = cell.getColumnIndex();
    if (width > sheet.getColumnWidth(colIndex)) {
      if (width > 255 * 256) {
        width = 255 * 256;
      }
      sheet.setColumnWidth(colIndex, width);
    }
  }
}

代码示例来源:origin: cn.afterturn/easypoi-base

@Override
public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) {
  if (StringUtils.isNoneBlank(style.getWidth())) {
    int width = (int) Math.round(PoiCssUtils.getInt(style.getWidth()) * 2048 / 8.43F);
    Sheet sheet = cell.getSheet();
    int colIndex = cell.getColumnIndex();
    if (width > sheet.getColumnWidth(colIndex)) {
      if (width > 255 * 256) {
        width = 255 * 256;
      }
      sheet.setColumnWidth(colIndex, width);
    }
  }
}

代码示例来源:origin: net.sf.jxls/jxls-core

public static void copySheets(Sheet newSheet, Sheet sheet) {
  int maxColumnNum = 0;
  for (int i = sheet.getFirstRowNum(), c = sheet.getLastRowNum(); i <= c; i++) {
    org.apache.poi.ss.usermodel.Row srcRow = sheet.getRow(i);
    org.apache.poi.ss.usermodel.Row destRow = newSheet.createRow(i);
    if (srcRow != null) {
      Util.copyRow(sheet, newSheet, srcRow, destRow);
      if (srcRow.getLastCellNum() > maxColumnNum) {
        maxColumnNum = srcRow.getLastCellNum();
      }
    }
  }
  for (int i = 0; i <= maxColumnNum; i++) {
    newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
  }
}

代码示例来源:origin: SheetJS/jxls

public static void copySheets(Sheet newSheet, Sheet sheet) {
  int maxColumnNum = 0;
  for (int i = sheet.getFirstRowNum(), c = sheet.getLastRowNum(); i <= c; i++) {
    org.apache.poi.ss.usermodel.Row srcRow = sheet.getRow(i);
    org.apache.poi.ss.usermodel.Row destRow = newSheet.createRow(i);
    if (srcRow != null) {
      Util.copyRow(sheet, newSheet, srcRow, destRow);
      if (srcRow.getLastCellNum() > maxColumnNum) {
        maxColumnNum = srcRow.getLastCellNum();
      }
    }
  }
  for (int i = 0; i <= maxColumnNum; i++) {
    newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
  }
}

代码示例来源:origin: net.sf.jxls/jxls-core

public static void copySheets(Sheet newSheet, Sheet sheet,
    String expressionToReplace, String expressionReplacement) {
  int maxColumnNum = 0;
  for (int i = sheet.getFirstRowNum(), c = sheet.getLastRowNum(); i <= c; i++) {
    org.apache.poi.ss.usermodel.Row srcRow = sheet.getRow(i);
    org.apache.poi.ss.usermodel.Row destRow = newSheet.createRow(i);
    if (srcRow != null) {
      Util.copyRow(sheet, newSheet, srcRow, destRow,
          expressionToReplace, expressionReplacement);
      if (srcRow.getLastCellNum() > maxColumnNum) {
        maxColumnNum = srcRow.getLastCellNum();
      }
    }
  }
  for (int i = 0; i <= maxColumnNum; i++) {
    newSheet.setColumnWidth(i, sheet.getColumnWidth(i));
  }
}

相关文章

微信公众号

最新文章

更多