Example usage for org.apache.poi.ss.usermodel Row setHeightInPoints

List of usage examples for org.apache.poi.ss.usermodel Row setHeightInPoints

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Row setHeightInPoints.

Prototype

void setHeightInPoints(float height);

Source Link

Document

Set the row's height in points.

Usage

From source file:vistas.reportes.procesos.rptVacacionesExcel.java

public void crearExcel(List<Empleado> empleados, Date fechaInicio, Date fechaFin)
        throws FileNotFoundException, IOException {
    Workbook wb;//from   w w w  .ja va 2s  . c om
    wb = new XSSFWorkbook();
    Map<String, CellStyle> styles = createStyles(wb);

    Sheet sheet = wb.createSheet("Vacaciones");
    PrintSetup printSetup = sheet.getPrintSetup();
    printSetup.setLandscape(true);
    sheet.setFitToPage(true);
    sheet.setHorizontallyCenter(true);

    //title row
    Row titleRow = sheet.createRow(0);
    titleRow.setHeightInPoints(45);
    Cell titleCell = titleRow.createCell(0);
    SimpleDateFormat formateador = new SimpleDateFormat("dd/MM/yyyy");
    titleCell.setCellValue(
            "VACACIONES MINEDU " + formateador.format(fechaInicio) + " - " + formateador.format(fechaFin));
    titleCell.setCellStyle(styles.get("title"));
    sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$D$1"));

    //header row
    Row headerRow = sheet.createRow(1);
    headerRow.setHeightInPoints(40);
    Cell headerCell;
    for (int i = 0; i < titles.length; i++) {
        headerCell = headerRow.createCell(i);
        headerCell.setCellValue(titles[i]);
        headerCell.setCellStyle(styles.get("header"));
    }

    int rownum = 2;
    for (int i = 0; i < empleados.size(); i++) {
        Row row = sheet.createRow(rownum++);
        for (int j = 0; j < titles.length; j++) {
            Cell cell = row.createCell(j);
            cell.setCellStyle(styles.get("cell"));

        }
    }
    for (int i = 0; i < empleados.size(); i++) {
        Row row = sheet.getRow(2 + i);
        row.getCell(0).setCellValue(empleados.get(i).getNroDocumento());
        row.getCell(1).setCellValue(empleados.get(i).getNombre() + " " + empleados.get(i).getApellidoPaterno());
        row.getCell(2).setCellValue("Departamento");
        Vacacion vacaciones = vc.buscarXDia(empleados.get(i).getNroDocumento(), fechaInicio);
        if (vacaciones != null) {
            row.getCell(3).setCellValue(formateador.format(vacaciones.getFechaInicio()) + " al "
                    + formateador.format(vacaciones.getFechaFin()));
        } else {
            row.getCell(3).setCellValue("No tiene vacaciones");
        }

    }

    sheet.setColumnWidth(0, 10 * 256);
    sheet.setColumnWidth(1, 30 * 256);
    sheet.setColumnWidth(2, 30 * 256);
    sheet.setColumnWidth(3, 25 * 256);
    //Write the output to a file
    String file = "rptVacaciones.xls";
    if (wb instanceof XSSFWorkbook)
        file += "x";
    FileOutputStream out = new FileOutputStream(file);
    wb.write(out);
    out.close();
    try {
        File path = new File(file);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:wtw.ui.ExprotXlsAction.java

public String export() {
    HSSFWorkbook myWorkBook = new HSSFWorkbook();
    HSSFSheet mySheet = myWorkBook.createSheet();
    try {//from  w  ww .  ja v  a2 s  .c  om
        Calendar calendar = Calendar.getInstance();
        List<ReportEntity> listF = fetchList();
        reportFile = "Report " + calendar.get(Calendar.YEAR) + "".concat(".xls");
        Row headerRow = mySheet.createRow(0);
        headerRow.setHeightInPoints(50);
        Cell titleCell = headerRow.createCell(0);
        titleCell.setCellValue("Report" + calendar.get(Calendar.YEAR) + "");
        setStudentAllInfo(mySheet, listF);
        try {
            ByteArrayOutputStream boas = new ByteArrayOutputStream();
            myWorkBook.write(boas);
            setInputStream(new ByteArrayInputStream(boas.toByteArray()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return SUCCESS;
}