Example usage for org.apache.poi.hssf.usermodel HSSFRow getHeight

List of usage examples for org.apache.poi.hssf.usermodel HSSFRow getHeight

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFRow getHeight.

Prototype


@Override
public short getHeight() 

Source Link

Document

get the row's height or ff (-1) for undefined/default-height in twips (1/20th of a point)

Usage

From source file:org.jxstar.report.util.ReportXlsUtil.java

/**
 * ?PageSize?//from   ww  w. j  a va2  s.  c  o m
 * @param sheet -- ?
 * @param startRow -- ???PageSize
 * @param rows -- ?
 * @return
 */
public static HSSFSheet insertSheetRow(HSSFSheet sheet, int startRow, int rows) {
    if (sheet == null)
        return null;
    sheet.shiftRows(startRow, sheet.getLastRowNum(), rows, true, false);

    HSSFCell sourcell = null, descell = null;
    HSSFRow sourow = sheet.getRow(startRow - 1);

    for (int i = 0; i < rows; i++) {
        HSSFRow descrow = sheet.createRow(startRow + i);

        descrow.setHeight(sourow.getHeight());
        descrow.setHeightInPoints(sourow.getHeightInPoints());

        java.util.Iterator<Cell> iter = sourow.cellIterator();
        while (iter.hasNext()) {
            sourcell = (HSSFCell) iter.next();
            int column = sourcell.getColumnIndex();
            descell = descrow.createCell(column);

            descell.setCellType(sourcell.getCellType());
            descell.setCellStyle(sourcell.getCellStyle());
        }
    }
    //??
    insertSheetRegions(sheet, startRow, rows);

    return sheet;
}

From source file:org.sharegov.cirm.utils.ExcelExportUtil.java

License:Apache License

public void setHeaderColumnStyle(HSSFRow row, HSSFCell cell, HSSFCellStyle boldStyle, String columnValue,
        int columnNo) {
    setColumnWidth(columnValue, columnNo);
    // Calculate what the column width should be.
    // Increase if the current width is smaller than the calculated width.
    int width = columnValue.length() * 325;
    String[] splitHead = Pattern.compile(" ").split(columnValue);
    int wordCnt = splitHead.length;
    for (int q = 0; q < splitHead.length; q++) {
        if (splitHead[q].length() * 325 > width)
            width = splitHead[q].length() * 325;
        sheet.setColumnWidth(columnNo, width);
    }//  w ww  . j  av  a2 s  .  c om
    // Determine the height of the column head
    int height = wordCnt * 275;
    if (row.getHeight() < height)
        row.setHeight((short) height);
    // Set Cell to boldStyle
    cell.setCellStyle(boldStyle);
}

From source file:ro.nextreports.engine.exporter.util.XlsUtil.java

License:Apache License

/**
 * Copy a row from a sheet to another sheet
 * /* ww w.  ja va2 s. com*/
 * 
 * @param srcSheet the sheet to copy
 * @param destSheet the sheet to copy into
 * @param parentSheetRow the row inside destSheet where we start to copy
 * @param parentSheetColumn the column inside destSheet where we start to copy
 * @param srcRow the row to copy
 * @param destRow the row to create
 * @param styleMap style map
 *       
 */
public static void copyRow(HSSFSheet srcSheet, HSSFSheet destSheet, int parentSheetRow, int parentSheetColumn,
        HSSFRow srcRow, HSSFRow destRow, Map<Integer, HSSFCellStyle> styleMap) {
    // manage a list of merged zone in order to not insert two times a
    // merged zone
    Set<CellRangeAddressWrapper> mergedRegions = new TreeSet<CellRangeAddressWrapper>();
    destRow.setHeight(srcRow.getHeight());
    // pour chaque row
    for (int j = srcRow.getFirstCellNum(); j <= srcRow.getLastCellNum(); j++) {
        HSSFCell oldCell = srcRow.getCell(j); // ancienne cell         
        if (oldCell != null) {
            HSSFCell newCell = destRow.createCell(parentSheetColumn + j);
            copyCell(oldCell, newCell, styleMap);

            CellRangeAddress mergedRegion = getMergedRegion(srcSheet, srcRow.getRowNum(),
                    (short) oldCell.getColumnIndex());

            if (mergedRegion != null) {

                CellRangeAddress newMergedRegion = new CellRangeAddress(
                        parentSheetRow + mergedRegion.getFirstRow(), parentSheetRow + mergedRegion.getLastRow(),
                        parentSheetColumn + mergedRegion.getFirstColumn(),
                        parentSheetColumn + mergedRegion.getLastColumn());

                CellRangeAddressWrapper wrapper = new CellRangeAddressWrapper(newMergedRegion);
                if (isNewMergedRegion(wrapper, mergedRegions)) {
                    mergedRegions.add(wrapper);
                    destSheet.addMergedRegion(wrapper.range);
                }
            }
        }
    }

}