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

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

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

Row.setHeight介绍

[英]Set the row's height or set to ff (-1) for undefined/default-height. Set the height in "twips" or 1/20th of a point.
[中]设置行的高度,或将未定义/默认高度设置为ff(-1)。以“twips”或1/20点为单位设置高度。

代码示例

代码示例来源:origin: apache/tika

Row sqlRow = sqlSheet.createRow(0);
short height = 5000;
sqlRow.setHeight(height);
Cell cell = sqlRow.createCell(0);
cell.setCellStyle(sqlCellStyle);

代码示例来源:origin: subtlelib/poi

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

代码示例来源:origin: Vatavuk/excel-io

@Override
  public void accept(final Row row) {
    row.setHeight(this.value);
  }
}

代码示例来源: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

static void copyPositiveRowHeight(Sheet sheet, int startRow,
    int endRow, int shiftNum, short[] rowHeights) {
  for (int i = startRow; i <= endRow; i++) {
    org.apache.poi.ss.usermodel.Row destRow = sheet.getRow(i + shiftNum);
    if (destRow != null && rowHeights[i - startRow] >= 0) {
      destRow.setHeight(rowHeights[i - startRow]);
    }
    // Row srcRow = sheet.getRow(i);
    // if( srcRow != null && destRow != null ){
    // if( srcRow.getHeight() >= 0 ){
    // destRow.setHeight( srcRow.getHeight() );
    // }
    // }
  }
}

代码示例来源: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: youseries/ureport

row.setHeight((short)UnitUtils.pointToTwip(r.getHeight()));
  rowNumber++;                    
row.setHeight((short)UnitUtils.pointToTwip(r.getRealHeight()));
rowNumber++;

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

static void copyPositiveRowHeight(Sheet sheet, int startRow,
    int endRow, int shiftNum, short[] rowHeights) {
  for (int i = startRow; i <= endRow; i++) {
    org.apache.poi.ss.usermodel.Row destRow = sheet.getRow(i + shiftNum);
    if (destRow != null && rowHeights[i - startRow] >= 0) {
      destRow.setHeight(rowHeights[i - startRow]);
    }
    // Row srcRow = sheet.getRow(i);
    // if( srcRow != null && destRow != null ){
    // if( srcRow.getHeight() >= 0 ){
    // destRow.setHeight( srcRow.getHeight() );
    // }
    // }
  }
}

代码示例来源:origin: hyberbin/J-Excel

/***
 * 将本次导出数据的hash密码写在Excel上
 * @param sheet
 * @param hashCode
 */
public  static void setHashVal(Sheet sheet,long hashCode){
  Row sheetRow = sheet.getRow(HASH_ROW);
  Cell cell = sheetRow.createCell(0);
  cell.setCellValue(hashCode);
  sheetRow.setHeight(Short.valueOf("0"));
}

代码示例来源:origin: youseries/ureport

row.setHeight((short)UnitUtils.pointToTwip(r.getHeight()));
rowNumber++;

代码示例来源:origin: youseries/ureport

row.setHeight((short)UnitUtils.pointToTwip(r.getRealHeight()));
rowNumber++;

代码示例来源:origin: hyberbin/J-Excel

/**
 * 生成表头
 */
private void createHead(){
  log.debug("生成表头");
  Row hashRow = sheet.createRow(HASH_ROW);
  addTitle(sheet, TITLE_ROW, fieldNames.length, language.translate(title));
  Row row = createRow(sheet, HIDDEN_FIELD_HEAD, fieldNames.length);
  List<String> columns=new ArrayList(fieldNames.length);
  for (String fieldName : fieldNames) {
    columns.add(language.translate(fieldName));
  }
  addRow(sheet, COLUMN_ROW, columns.toArray(new String[]{}));
  hashRow.setHeight(Short.valueOf("0"));
  row.setHeight(Short.valueOf("0"));
  log.debug("表头生成完毕");
}

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

Workbook wb = new HSSFWorkbook();
 FileOutputStream fileOut = new FileOutputStream("workbook.xls");
 CreationHelper createHelper = wb.getCreationHelper();
 Sheet sheet = wb.createSheet("new sheet");
 Row row = sheet.createRow((short) 0);
 row.setHeight((short) (2*sheet.getDefaultRowHeight()));
 CellStyle cs = wb.createCellStyle();
 cs.setWrapText(true);
 Cell cell = row.createCell(0);
 cell.setCellStyle(cs);
 cell.setCellValue(
 createHelper.createRichTextString("This is \n a string"));
 wb.write(fileOut);
 fileOut.close();

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

@Override
  public void updateRowHeight(String srcSheetName, int srcRowNum, String targetSheetName, int targetRowNum) {
    if (isSXSSF) return;
    SheetData sheetData = sheetMap.get(srcSheetName);
    RowData rowData = sheetData.getRowData(srcRowNum);
    Sheet sheet = workbook.getSheet(targetSheetName);
    if (sheet == null) {
      sheet = workbook.createSheet(targetSheetName);
    }
    Row targetRow = sheet.getRow(targetRowNum);
    if (targetRow == null) {
      targetRow = sheet.createRow(targetRowNum);
    }
    short srcHeight = rowData != null ? (short) rowData.getHeight() : sheet.getDefaultRowHeight();
    targetRow.setHeight(srcHeight);
  }
}

代码示例来源: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: pl.edu.icm.synat/synat-console-core

private void setHeightsAndWidths(Sheet reportSheet, ReportType type) {
  reportSheet.setColumnWidth(0, 15000);
  reportSheet.setColumnWidth(1, 3000);
  reportSheet.setColumnWidth(2, 3000);
  reportSheet.setColumnWidth(3, 3000);
  reportSheet.setColumnWidth(4, 7000);
  reportSheet.setColumnWidth(5, 4000);
  reportSheet.setColumnWidth(6, 4000);
  for (int i = 7; i < 15; i++) {
    reportSheet.setColumnWidth(i, 3000);
  }
  reportSheet.getRow(7).setHeight((short) 1000);
}

代码示例来源: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: com.github.fartherp/framework-poi

public ExcelWrite<T> list(List<T> list) {
  // 当前总数
  excelWrite.setTotal(excelWrite.getTotal() + list.size());
  createSheet(list, true);
  for (T t : list) {
    createSheet(list, false);
    // 创建一行
    Row dataRow = excelWrite.getCurrentSheet().createRow(excelWrite.getCurrentRow());
    dataRow.setHeight(excelWrite.getDeal().setHeight());
    // 得到要插入的每一条记录
    String [] data = excelWrite.getDeal().dealBean(t);
    for (int k = 0; k < data.length; k++) {
      // 在一行内循环
      Cell cell = dataRow.createCell(k);
      cell.setCellValue(setRichTextString(excelWrite.getLargeDataMode(), excelWrite.getType(), data[k]));
      cell.setCellStyle(noColor);
    }
    excelWrite.setCurrentRow(excelWrite.getCurrentRow() + 1);
  }
  return this;
}

代码示例来源: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)));
  }
}

相关文章