Example usage for org.apache.poi.hssf.usermodel HSSFSheet setDefaultRowHeightInPoints

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet setDefaultRowHeightInPoints

Introduction

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

Prototype

@Override
public void setDefaultRowHeightInPoints(float height) 

Source Link

Document

set the default row height for the sheet (if the rows do not define their own height) in points

Usage

From source file:com.claim.controller.ThaiMedicineController.java

public ProgrameStatus tmdActSummary(OppReport report) {
    int col_last = 18;
    int row_start = 6; // index row
    int col_freeze = 3;
    int row_freeze = 6;
    int row_formula_start = row_start + 1;
    ProgrameStatus programeStatus = new ProgrameStatus();
    List<ObjRptTmdActSummary> listData = new ArrayList<ObjRptTmdActSummary>();
    String stmp = StringOpUtil.removeNull(report.getYearMonth()) + "-" + report.getNo();
    String pathDirectory = report.getPathFile() + "" + File.separator + "" + stmp + "" + File.separator + "";
    try {/*  ww  w . java2 s.  c  om*/
        connection = new DBManage().open();
        ThaiMedicineDao tmdDao = new ThaiMedicineDao();
        tmdDao.setConnection(connection);

        file = new FileInputStream(new File("." + File.separator + "xls" + File.separator + "TMD_ACT_SUM.xls"));

        // Top Excell Sheet1
        EXCELL_HEADER1 = report.getTitle1().replace("{No.}", subNoStrStmp(stmp));
        report.setTmdTableName(TABLE_RPT_ACT);
        EXCELL_HEADER2 = new DateUtil().convertStmpToString(report.getStmp()) + getTitleDateOpd(report);

        HSSFWorkbook wbTmd = new HSSFWorkbook(file);
        this.setFontFamily("Arial");
        this.setFontSize(7);
        this.setColorCell(HSSFColor.LIGHT_GREEN.index);
        this.setFontHeaderSize(8);
        this.loadStyle(wbTmd);

        HSSFSheet sheet = workbookBase.getSheetAt(0);
        sheet.setDefaultRowHeightInPoints(100);
        //sheet.createFreezePane(col_freeze, row_freeze);

        // row 0 Header
        row = sheet.createRow(0);
        row.setHeight((short) 390);
        cell = row.createCell(0);
        cell.setCellValue(EXCELL_HEADER1);
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, col_last));
        cell.setCellStyle(csHead);

        //            // row 2 Header
        //            row = sheet.createRow(1);
        //            row.setHeight((short) 390);
        //            cell = row.createCell(0);
        //            cell.setCellValue(EXCELL_HEADER2);
        //            sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, col_last));
        //            cell.setCellStyle(csHead);
        int curRow = row_start;
        double sumTotalSumPay = 0.00;
        int i = 1;
        listData = tmdDao.getListSummaryTmdAct(report);
        System.out.println("listData.size() :" + listData.size());
        for (int j = 0; j < listData.size(); j++) {
            ObjRptTmdActSummary objData = listData.get(j);

            row = sheet.createRow(curRow);
            row.setHeight((short) 360);
            cell = row.createCell(0);
            cell.setCellValue(i);
            cell.setCellStyle(csNum4);

            cell = row.createCell(1);
            cell.setCellValue(objData.getHcode());
            cell.setCellStyle(csString2Center);

            cell = row.createCell(2);
            cell.setCellValue(objData.getHcodename());
            cell.setCellStyle(csStringLeft);

            /*
             1
             */
            cell = row.createCell(3);
            cell.setCellValue(objData.getCount_dis_txid1());
            cell.setCellStyle(csNum4R);

            cell = row.createCell(4);
            cell.setCellValue(objData.getSum_point1());
            cell.setCellStyle(csDouble2);

            cell = row.createCell(5);
            cell.setCellValue(objData.getSum_totalpay1());
            cell.setCellStyle(csDouble2);

            /*
             2
             */
            cell = row.createCell(6);
            cell.setCellValue(objData.getCount_dis_txid2());
            cell.setCellStyle(csNum4R);

            cell = row.createCell(7);
            cell.setCellValue(objData.getSum_point2());
            cell.setCellStyle(csDouble2);

            cell = row.createCell(8);
            cell.setCellValue(objData.getSum_totalpay2());
            cell.setCellStyle(csDouble2);

            /*
             3
             */
            cell = row.createCell(9);
            cell.setCellValue(objData.getCount_dis_txid3());
            cell.setCellStyle(csNum4R);

            cell = row.createCell(10);
            cell.setCellValue(objData.getSum_point3());
            cell.setCellStyle(csDouble2);

            cell = row.createCell(11);
            cell.setCellValue(objData.getSum_totalpay3());
            cell.setCellStyle(csDouble2);

            /*
             4
             */
            cell = row.createCell(12);
            cell.setCellValue(objData.getCount_dis_txid4());
            cell.setCellStyle(csNum4R);

            cell = row.createCell(13);
            cell.setCellValue(objData.getSum_point4());
            cell.setCellStyle(csDouble2);

            cell = row.createCell(14);
            cell.setCellValue(objData.getSum_totalpay4());
            cell.setCellStyle(csDouble2);
            /*
             5
             */
            cell = row.createCell(15);
            cell.setCellValue(objData.getCount_dis_txid5());
            cell.setCellStyle(csNum4R);

            cell = row.createCell(16);
            cell.setCellValue(objData.getSum_point5());
            cell.setCellStyle(csDouble2);

            cell = row.createCell(17);
            cell.setCellValue(objData.getSum_totalpay5());
            cell.setCellStyle(csDouble2);

            cell = row.createCell(18);
            cell.setCellValue(objData.getSum_totalpay_all());
            cell.setCellStyle(csDouble2);
            sumTotalSumPay += objData.getSum_totalpay_all();
            curRow++;
            i++;
        }

        /**
         * footer summary total
         */
        row = sheet.createRow(curRow);
        row.setHeight((short) 450);
        cell = row.createCell(0);
        cell.setCellValue("");
        sheet.addMergedRegion(new CellRangeAddress(curRow, curRow, 0, 2));
        cell.setCellStyle(csNum4B);

        row.createCell(1).setCellStyle(csHeadTab);
        row.createCell(2).setCellStyle(csHeadTab);

        cell = row.createCell(3);
        cell.setCellFormula(builderFormulaSum(3, row_formula_start, curRow));
        cell.setCellStyle(csNum3B);
        cell = row.createCell(4);
        cell.setCellFormula(builderFormulaSum(4, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(5);
        cell.setCellFormula(builderFormulaSum(5, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(6);
        cell.setCellFormula(builderFormulaSum(6, row_formula_start, curRow));
        cell.setCellStyle(csNum3B);
        cell = row.createCell(7);
        cell.setCellFormula(builderFormulaSum(7, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(8);
        cell.setCellFormula(builderFormulaSum(8, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(9);
        cell.setCellFormula(builderFormulaSum(9, row_formula_start, curRow));
        cell.setCellStyle(csNum3B);
        cell = row.createCell(10);
        cell.setCellFormula(builderFormulaSum(10, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(11);
        cell.setCellFormula(builderFormulaSum(11, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(12);
        cell.setCellFormula(builderFormulaSum(12, row_formula_start, curRow));
        cell.setCellStyle(csNum3B);
        cell = row.createCell(13);
        cell.setCellFormula(builderFormulaSum(13, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(14);
        cell.setCellFormula(builderFormulaSum(14, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(15);
        cell.setCellFormula(builderFormulaSum(15, row_formula_start, curRow));
        cell.setCellStyle(csNum3B);
        cell = row.createCell(16);
        cell.setCellFormula(builderFormulaSum(16, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(17);
        cell.setCellFormula(builderFormulaSum(17, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);
        cell = row.createCell(18);
        cell.setCellFormula(builderFormulaSum(18, row_formula_start, curRow));
        cell.setCellStyle(csDouble2B);

        /*
         ############ ? ###############
         */
        int rowDateTimeCurrent = curRow + 1;
        // BathText
        row = sheet.createRow((rowDateTimeCurrent));
        cell = row.createCell(0);
        cell.setCellValue("? _"
                + new DateUtil().getDateTimeCurrent());
        sheet.addMergedRegion(new CellRangeAddress(rowDateTimeCurrent, rowDateTimeCurrent, 0, 10));
        cell.setCellStyle(csStringB);

        /*
         ############ ? ###############
         */

        /*
         ################# bathTaxt #####################
         */
        /*System.out.println("(curRow+1) ::=="+(curRow+1));
         CellReference cellReference = new CellReference("S"+(curRow+1)); 
         Row row = sheet.getRow(cellReference.getRow());
         Cell cell = row.getCell(cellReference.getCol());             
         System.out.println("cell.getCellFormula() ::=="+cell.getCellFormula());
         double totalPay = cell.getNumericCellValue();
         int rowBathText = curRow + 1;
         // BathText
         row = sheet.createRow((rowBathText));
         cell = row.createCell(0);
         cell.setCellValue(new UtilDao().getThaiBath(Double.parseDouble(new NumberUtil().numberDigiit(sumTotalSumPay, 2))));
         sheet.addMergedRegion(new CellRangeAddress(rowBathText, rowBathText, 0, 18));
         cell.setCellStyle(csNum4B_R);
         */
        /*
         ################# bathTaxt #####################
         */
        new FileUtil().mkdirMutiDirectory(pathDirectory);

        //write file Excell
        out = new FileOutputStream(pathDirectory + "" + File.separator + "tmdact_summary_"
                + report.getYearMonth() + "-" + report.getNo() + ".xls");
        workbookBase.write(out);
        out.close();
        file.close();
        Console.LOG(
                " ???? ???",
                1);

        programeStatus.setMessage(ConstantMessage.MSG_REPORT_SUCCESS);
        programeStatus.setTitle(ConstantMessage.MSG_REPORT_COMPLETE);
        programeStatus.setProcessStatus(true);

    } catch (Exception e) {
        e.printStackTrace();
        Console.LOG(e.getMessage(), 0);
        programeStatus.setMessage(ConstantMessage.MSG_PROCESS_FAILS + e.toString());
        programeStatus.setTitle(ConstantMessage.MSG_CONTACT_ADMIN);
        programeStatus.setProcessStatus(false);
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    return programeStatus;
}

From source file:com.eryansky.core.excelTools.ExcelUtils.java

License:Apache License

public static void copySheetStyle(HSSFWorkbook destwb, HSSFSheet dest, HSSFWorkbook srcwb, HSSFSheet src) {
    if (src == null || dest == null)
        return;//  w w  w  . ja  v a2  s.  co  m

    dest.setAlternativeExpression(src.getAlternateExpression());
    dest.setAlternativeFormula(src.getAlternateFormula());
    dest.setAutobreaks(src.getAutobreaks());
    dest.setDialog(src.getDialog());
    if (src.getColumnBreaks() != null) {
        for (int col : src.getColumnBreaks()) {
            dest.setColumnBreak(col);
        }
    }
    dest.setDefaultColumnWidth(src.getDefaultColumnWidth());
    dest.setDefaultRowHeight(src.getDefaultRowHeight());
    dest.setDefaultRowHeightInPoints(src.getDefaultRowHeightInPoints());
    dest.setDisplayGuts(src.getDisplayGuts());
    dest.setFitToPage(src.getFitToPage());
    dest.setHorizontallyCenter(src.getHorizontallyCenter());
    dest.setDisplayFormulas(src.isDisplayFormulas());
    dest.setDisplayGridlines(src.isDisplayGridlines());
    dest.setDisplayRowColHeadings(src.isDisplayRowColHeadings());
    dest.setGridsPrinted(src.isGridsPrinted());
    dest.setPrintGridlines(src.isPrintGridlines());

    for (int i = 0; i < src.getNumMergedRegions(); i++) {
        CellRangeAddress r = src.getMergedRegion(i);
        dest.addMergedRegion(r);
    }

    if (src.getRowBreaks() != null) {
        for (int row : src.getRowBreaks()) {
            dest.setRowBreak(row);
        }
    }
    dest.setRowSumsBelow(src.getRowSumsBelow());
    dest.setRowSumsRight(src.getRowSumsRight());

    int maxcol = 0;
    for (int i = 0; i <= src.getLastRowNum(); i++) {
        HSSFRow row = src.getRow(i);
        if (row != null) {
            if (maxcol < row.getLastCellNum())
                maxcol = row.getLastCellNum();
        }
    }
    for (int col = 0; col <= maxcol; col++) {
        if (src.getColumnWidth(col) != src.getDefaultColumnWidth())
            dest.setColumnWidth(col, src.getColumnWidth(col));
        dest.setColumnHidden(col, src.isColumnHidden(col));
    }
}

From source file:org.jfree.workbook.io.XLWriter.java

License:Open Source License

/**
 * Creates a new sheet in the HSSFWorkbook, based on the supplied worksheet.
 * /*from  www .  j a va 2 s .  co m*/
 * @param hssfWorkbook  the workbook.
 * @param worksheet  the worksheet.
 */
private void createHSSFWorksheet(HSSFWorkbook hssfWorkbook, Worksheet worksheet) {

    HSSFSheet hssfSheet = hssfWorkbook.createSheet(worksheet.getName());

    Iterator iterator = worksheet.getCells().getRowsIterator();
    while (iterator.hasNext()) {

        Row row = (Row) iterator.next();
        createHSSFRow(hssfWorkbook, hssfSheet, worksheet, row);

    }

    ColumnAttributesManager attributes = worksheet.getColumnAttributesManager();

    // default column width (pts as double) : convert it to chars as short...
    short w = (short) (attributes.getDefaultColumnWidth() / 4.0);
    hssfSheet.setDefaultColumnWidth(w);

    RowAttributesManager rowAttrs = worksheet.getRowAttributesManager();

    // default row height ...
    hssfSheet.setDefaultRowHeightInPoints((float) rowAttrs.getDefaultRowHeight());

    // now define the individual column widths...
    iterator = attributes.getAttributesIterator();
    while (iterator.hasNext()) {
        ColumnAttributes ca = (ColumnAttributes) iterator.next();
        for (int c = ca.getStartColumn(); c <= ca.getEndColumn(); c++) {

            hssfSheet.setColumnWidth((short) c, (short) (ca.getWidth() * 64));

        }
    }

}