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

x33g5p2x  于2022-01-28 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(157)

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

Row.getHeight介绍

[英]Get the row's height measured in twips (1/20th of a point). If the height is not set, the default worksheet value is returned, See Sheet#getDefaultRowHeightInPoints()
[中]以twips(1/20点)为单位测量行的高度。如果未设置高度,则返回默认工作表值,请参见工作表#getDefaultRowHeightInPoints()

代码示例

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

setHeight(srcRow.getHeight());

代码示例来源:origin: org.hswebframework/hsweb-expands-office

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

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

private static short[] getRowHeights(Sheet sheet, int startRow,
    int endRow) {
  if (endRow - startRow + 1 < 0) {
    return new short[0];
  }
  short[] rowHeights = new short[endRow - startRow + 1];
  for (int i = startRow; i <= endRow; i++) {
    org.apache.poi.ss.usermodel.Row row = sheet.getRow(i);
    if (row != null) {
      rowHeights[i - startRow] = row.getHeight();
    } else {
      rowHeights[i - startRow] = -1;
    }
  }
  return rowHeights;
}

代码示例来源:origin: hs-web/hsweb-expands

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

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

private static short[] getRowHeights(Sheet sheet, int startRow,
    int endRow) {
  if (endRow - startRow + 1 < 0) {
    return new short[0];
  }
  short[] rowHeights = new short[endRow - startRow + 1];
  for (int i = startRow; i <= endRow; i++) {
    org.apache.poi.ss.usermodel.Row row = sheet.getRow(i);
    if (row != null) {
      rowHeights[i - startRow] = row.getHeight();
    } else {
      rowHeights[i - startRow] = -1;
    }
  }
  return rowHeights;
}

代码示例来源:origin: hellojavaer/poi-excel-utils

if (tempRow != null) {
  templateRow = new InnerRow();
  templateRow.setHeight(tempRow.getHeight());
  templateRow.setHeightInPoints(tempRow.getHeightInPoints());
  templateRow.setRowStyle(tempRow.getRowStyle());

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

short getRowHeight(Row row, String cellValue, Font font, float cellWidth) {
  if(cellValue.isEmpty())
    return row.getHeight();
  // Create Font object with Font attribute (e.g. Font family, Font size, etc) for calculation
  int style = java.awt.Font.PLAIN;
  if(font.getBoldweight() == Font.BOLDWEIGHT_BOLD)
    style = java.awt.Font.BOLD;
  java.awt.Font currFont = new java.awt.Font(font.getFontName(), style, font.getFontHeight());
  double requiredWidth = currFont.getStringBounds(cellValue, new FontRenderContext(currFont.getTransform(), false, false)).getBounds().getWidth();
  return (short) Math.ceil(font.getFontHeight() * requiredWidth / cellWidth);
  // The above solution doesn't handle the newline character, i.e. "\n", and only for row having merged cells.
}

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

@Override
public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) {
  if (StringUtils.isNoneBlank(style.getHeight())) {
    int height = Math.round(PoiCssUtils.getInt(style.getHeight()) * 255 / 12.75F);
    Row row = cell.getRow();
    if (height > row.getHeight()) {
      row.setHeight((short) height);
    }
  }
}

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

@Override
public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) {
  if (StringUtils.isNoneBlank(style.getHeight())) {
    int height = Math.round(PoiCssUtils.getInt(style.getHeight()) * 255 / 12.75F);
    Row row = cell.getRow();
    if (height > row.getHeight()) {
      row.setHeight((short) height);
    }
  }
}

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

while (rows.hasNext()) {
  Row row = rows.next();
  out.format("  <tr style='height:%spx;'>%n", row.getHeight() / 15);

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

public static void copyRow(Sheet srcSheet, Sheet destSheet,
    org.apache.poi.ss.usermodel.Row srcRow, org.apache.poi.ss.usermodel.Row destRow) {
  Set mergedRegions = new TreeSet();
  if (srcRow.getHeight() >= 0) {
    destRow.setHeight(srcRow.getHeight());

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

String expressionReplacement) {
Set mergedRegions = new HashSet();
if (srcRow.getHeight() >= 0) {
  destRow.setHeight(srcRow.getHeight());

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

destRow = sheet.createRow(i);
if (srcRow.getHeight() >= 0) {
  destRow.setHeight(srcRow.getHeight());

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

public static void copyRow(Sheet sheet, org.apache.poi.ss.usermodel.Row oldRow, org.apache.poi.ss.usermodel.Row newRow) {
  Set mergedRegions = new HashSet();
  if (oldRow.getHeight() >= 0) {
    newRow.setHeight(oldRow.getHeight());
  }
  if (oldRow.getFirstCellNum() >= 0 && oldRow.getLastCellNum() >= 0) {
    for (int j = oldRow.getFirstCellNum(), c = oldRow.getLastCellNum(); j <= c; j++) {
      org.apache.poi.ss.usermodel.Cell oldCell = oldRow.getCell(j);
      org.apache.poi.ss.usermodel.Cell newCell = newRow.getCell(j);
      if (oldCell != null) {
        if (newCell == null) {
          newCell = newRow.createCell(j);
        }
        copyCell(oldCell, newCell, true);
        CellRangeAddress mergedRegion = getMergedRegion(sheet, oldRow.getRowNum(), oldCell.getColumnIndex());
        if (mergedRegion != null) {
          CellRangeAddress newMergedRegion = new CellRangeAddress(
              newRow.getRowNum(), newRow.getRowNum()
              + mergedRegion.getLastRow()
              - mergedRegion.getFirstRow(), mergedRegion.getFirstColumn(), mergedRegion.getLastColumn());
          if (isNewMergedRegion(newMergedRegion, mergedRegions)) {
            mergedRegions.add(newMergedRegion);
            sheet.addMergedRegion(newMergedRegion);
          }
        }
      }
    }
  }
}

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

public static void copyRow(Sheet sheet, org.apache.poi.ss.usermodel.Row oldRow, org.apache.poi.ss.usermodel.Row newRow) {
  Set mergedRegions = new HashSet();
  if (oldRow.getHeight() >= 0) {
    newRow.setHeight(oldRow.getHeight());

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

// Create Font object with Font attribute (e.g. Font family, Font size, etc) for calculation
java.awt.Font currFont = new java.awt.Font(fontName, 0, fontSize);
AttributedString attrStr = new AttributedString(cellValue);
attrStr.addAttribute(TextAttribute.FONT, currFont);

// Use LineBreakMeasurer to count number of lines needed for the text
FontRenderContext frc = new FontRenderContext(null, true, true);
LineBreakMeasurer measurer = new LineBreakMeasurer(attrStr.getIterator(), frc);
int nextPos = 0;
int lineCnt = 0;
while (measurer.getPosition() < cellValue.length())
{
  nextPos = measurer.nextOffset(mergedCellWidth); // mergedCellWidth is the max width of each line
  lineCnt++;
  measurer.setPosition(nextPos);
}

Row currRow = currSht.getRow(rowNum);
currRow.setHeight((short)(currRow.getHeight() * lineCnt));

// The above solution doesn't handle the newline character, i.e. "\n", and only
// tested under horizontal merged cells.

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

name = name.trim();
ExcelForEachParams params = new ExcelForEachParams(name, cell.getCellStyle(),
  cell.getRow().getHeight());

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

name = name.trim();
ExcelForEachParams params = new ExcelForEachParams(name, cell.getCellStyle(),
    cell.getRow().getHeight());

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

public static RowData createRowData(Row row, PoiTransformer transformer){
  if( row == null ) return null;
  PoiRowData rowData = new PoiRowData();
  rowData.setTransformer( transformer );
  rowData.row = row;
  rowData.height = row.getHeight();
  int numberOfCells = row.getLastCellNum();
  for(int cellIndex = 0; cellIndex < numberOfCells; cellIndex++){
    org.apache.poi.ss.usermodel.Cell cell = row.getCell(cellIndex);
    if(cell != null ){
      CellData cellData = PoiCellData.createCellData(new CellRef(row.getSheet().getSheetName(), row.getRowNum(), cellIndex), cell);
      cellData.setTransformer(transformer);
      rowData.addCellData(cellData);
    }else{
      rowData.addCellData(null);
    }
  }
  return rowData;
}

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

/**
 * 图片类型的Cell
 */
public void createImageCell(Cell cell, double height,
              String imagePath, byte[] data) throws Exception {
  if (height > cell.getRow().getHeight()) {
    cell.getRow().setHeight((short) height);
  }
  ClientAnchor anchor;
  if (type.equals(ExcelType.HSSF)) {
    anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
        cell.getRow().getRowNum() + 1);
  } else {
    anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
        cell.getRow().getRowNum() + 1);
  }
  if (StringUtils.isNotEmpty(imagePath)) {
    data = ImageCache.getImage(imagePath);
  }
  if (data != null) {
    PoiExcelGraphDataUtil.getDrawingPatriarch(cell.getSheet()).createPicture(anchor,
        cell.getSheet().getWorkbook().addPicture(data, getImageType(data)));
  }
}

相关文章