public static double getRowHeightInPixels(Sheet sheet, int rowNum) { Row r = sheet.getRow(rowNum); double points = (r == null) ? sheet.getDefaultRowHeightInPoints() : r.getHeightInPoints(); return Units.toEMU(points)/(double)EMU_PER_PIXEL; } }
private float getRowHeightInPixels(int rowIndex) { // THE FOLLOWING THREE LINES ARE THE MAIN CHANGE compared to the non-streaming version: use the SXSSF sheet, // not the XSSF sheet (which never contais rows when using SXSSF) XSSFSheet xssfSheet = getSheet(); SXSSFSheet sheet = _wb.getSXSSFSheet(xssfSheet); Row row = sheet.getRow(rowIndex); float height = row != null ? row.getHeightInPoints() : sheet.getDefaultRowHeightInPoints(); return height * Units.PIXEL_DPI / Units.POINT_DPI; } /**
public static double getRowHeightInPixels(Sheet sheet, int rowNum) { Row r = sheet.getRow(rowNum); double points = (r == null) ? sheet.getDefaultRowHeightInPoints() : r.getHeightInPoints(); return Units.toEMU(points)/(double)EMU_PER_PIXEL; } }
/** * Define row height as follows: * - row height set explicitly by user: value defined by user; * - multiline output and no row height defined: default height * number of lines; * - otherwise: auto row height (by setting height to a magic value of #ROW_HEIGHT_AUTOMATIC); */ private void assignRowHeight(int rowHeightMultiplier) { if (rowHeightMultiplier > 1 && rowHeight == ROW_HEIGHT_AUTOMATIC) { row.setHeightInPoints(row.getHeightInPoints() * rowHeightMultiplier); } else { row.setHeight(rowHeight); } }
private float getRowHeightInPixels(int rowIndex) { // THE FOLLOWING THREE LINES ARE THE MAIN CHANGE compared to the non-streaming version: use the SXSSF sheet, // not the XSSF sheet (which never contais rows when using SXSSF) XSSFSheet xssfSheet = getSheet(); SXSSFSheet sheet = _wb.getSXSSFSheet(xssfSheet); Row row = sheet.getRow(rowIndex); float height = row != null ? row.getHeightInPoints() : sheet.getDefaultRowHeightInPoints(); return height * Units.PIXEL_DPI / Units.POINT_DPI; } /**
/** * 设置所有单元格,自适应列宽,单元格最大支持字符长度255 */ private void setTdOfTable(Table table, Sheet sheet) { maxTdHeightMap = new HashMap<>(); Map<Integer, Integer> colMaxWidthMap = this.getColMaxWidthMap(table); for (int i = 0, size = table.getTrList().size(); i < size; i++) { Tr tr = table.getTrList().get(i); tr.getTdList().forEach(td -> this.setCell(td, sheet)); // 设置行高,最小12 Row row = sheet.getRow(tr.getIndex()); if (Objects.isNull(maxTdHeightMap.get(row.getRowNum()))) { row.setHeightInPoints(row.getHeightInPoints() + 5); } else { row.setHeightInPoints((short) (maxTdHeightMap.get(row.getRowNum()) + 5)); maxTdHeightMap.remove(row.getRowNum()); } table.getTrList().set(i, null); } colMaxWidthMap.forEach((key, value) -> { int contentLength = value << 1; if (contentLength > 255) { contentLength = 255; } sheet.setColumnWidth(key, contentLength << 8); }); }
findData = true; defaultStyle = c.getCellStyle(); rowHeight = row.getHeightInPoints(); initStyles(); break;
rowHeightMM = row.getHeightInPoints() / ConvertImageUnits.POINTS_PER_MILLIMETRE; totalRowHeightMM += rowHeightMM;
rowHeightMM = row.getHeightInPoints() / ConvertImageUnits.POINTS_PER_MILLIMETRE;
@Override public void nextRow(Cell cell) { if (nowRow == null) { //首次渲染行,则将表达式所在行替换为数据行 nowRow = cell.getRow(); } else { //创建下一行 int rowNum = nowRow.getRowNum() + 1; //将最后一行移动到当前行,以实现插入行效果 sheet.shiftRows(rowNum,sheet.getLastRowNum(),1,true,false); Row tmp = sheet.createRow(rowNum); tmp.setHeight(nowRow.getHeight()); tmp.setHeightInPoints(nowRow.getHeightInPoints()); nowRow = tmp; } }
@Override public void nextRow(Cell cell) { if (nowRow == null) { //首次渲染行,则将表达式所在行替换为数据行 nowRow = cell.getRow(); } else { //创建下一行 int rowNum = nowRow.getRowNum() + 1; //将最后一行移动到当前行,以实现插入行效果 sheet.shiftRows(rowNum,sheet.getLastRowNum(),1,true,false); Row tmp = sheet.createRow(rowNum); tmp.setHeight(nowRow.getHeight()); tmp.setHeightInPoints(nowRow.getHeightInPoints()); nowRow = tmp; } }
templateRow = new InnerRow(); templateRow.setHeight(tempRow.getHeight()); templateRow.setHeightInPoints(tempRow.getHeightInPoints()); templateRow.setRowStyle(tempRow.getRowStyle()); templateRow.setZeroHeight(tempRow.getZeroHeight());
pdfpCell.setPhrase(getPhrase(cell)); pdfpCell.setMinimumHeight(this.getPixelHeight(row.getHeightInPoints()));