Example usage for org.apache.poi.hssf.usermodel HSSFFont setFontHeightInPoints

List of usage examples for org.apache.poi.hssf.usermodel HSSFFont setFontHeightInPoints

Introduction

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

Prototype


public void setFontHeightInPoints(short height) 

Source Link

Document

set the font height

Usage

From source file:domain.Excel.java

public void reporteSesionPeso() {
        //        cargarLogo();

        sheet.addMergedRegion(CellRangeAddress.valueOf("A1:E1"));
        sheet.addMergedRegion(CellRangeAddress.valueOf("A2:E2"));
        sheet.addMergedRegion(CellRangeAddress.valueOf("A3:E4"));

        /*Name REPORT*/
        HSSFFont FontNameReport = wb.createFont();
        FontNameReport.setFontName("Calibri");
        FontNameReport.setFontHeightInPoints((short) 11);
        FontNameReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        FontNameReport.setColor(HSSFColor.DARK_RED.index);

        HSSFCellStyle styleNameReport = wb.createCellStyle();
        styleNameReport.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleNameReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleNameReport.setFont(FontNameReport);

        Row row = sheet.createRow(0);/*from www. j a v  a2s .  c o m*/
        Cell cell = row.createCell(0);
        cell.setCellValue("REPORTE DE SESIONES POR PESOS");
        cell.setCellStyle(styleNameReport);
        /**/

        /*DATE REPORT*/
        HSSFFont FontDateReport = wb.createFont();
        FontDateReport.setFontName("Calibri");
        FontDateReport.setFontHeightInPoints((short) 10);
        FontDateReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        FontDateReport.setColor(HSSFColor.BLACK.index);

        HSSFCellStyle styleDateReport = wb.createCellStyle();
        styleDateReport.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleDateReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleDateReport.setFont(FontDateReport);

        row = sheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue("FECHA DE REPORTE: " + formatoDateTime.format(new Date()));
        cell.setCellStyle(styleDateReport);

        /*Etiqueta parametro*/
        HSSFFont FontParametroReport = wb.createFont();
        FontParametroReport.setFontName("Calibri");
        FontParametroReport.setFontHeightInPoints((short) 9);
        FontParametroReport.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
        FontParametroReport.setColor(HSSFColor.BLACK.index);

        HSSFCellStyle styleParamReport = wb.createCellStyle();
        styleParamReport.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleParamReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleParamReport.setFont(FontParametroReport);

        row = sheet.createRow(2);
        cell = row.createCell(0);
        String etiqueta_parametro = "";

        switch (tipo) {
        case 1:
            etiqueta_parametro = "Sesion de dia " + formatoDate.format(fecha_ini);
            break;
        case 2:
            etiqueta_parametro = "Sesiones del " + formatoDate.format(fecha_ini) + " al "
                    + formatoDate.format(fecha_fin);
            break;
        case 3:
            etiqueta_parametro = "Sesiones del animal " + animal.arete_visual;
            break;
        }

        cell.setCellValue(etiqueta_parametro);
        cell.setCellStyle(styleParamReport);

        /**/
        sheet.createRow(5).createCell(0).setCellValue("Arete Visual");
        sheet.getRow(5).createCell(1).setCellValue("Arete Electronico");
        sheet.getRow(5).createCell(2).setCellValue("Fecha");
        sheet.getRow(5).createCell(3).setCellValue("Peso");
        sheet.getRow(5).createCell(4).setCellValue("Corral");

        sheet.setColumnWidth(0, 16 * Unidad);
        sheet.setColumnWidth(1, 16 * Unidad);
        sheet.setColumnWidth(2, 16 * Unidad);
        sheet.setColumnWidth(3, 16 * Unidad);
        sheet.setColumnWidth(4, 16 * Unidad);

        SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();

        //Condition 1: Cell Value Is   greater than  70   (Blue Fill)
        ConditionalFormattingRule rule1 = sheetCF
                .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.GT, "1000");
        PatternFormatting fill1 = rule1.createPatternFormatting();
        fill1.setFillBackgroundColor(IndexedColors.DARK_RED.index);
        fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

        //Condition 2: Cell Value Is  less than      50   (Green Fill)
        ConditionalFormattingRule rule2 = sheetCF
                .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.LT, "50");
        PatternFormatting fill2 = rule2.createPatternFormatting();
        fill2.setFillBackgroundColor(IndexedColors.DARK_RED.index);
        fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

        FontFormatting font = rule1.createFontFormatting();
        font.setFontStyle(false, true);
        font.setFontColorIndex(IndexedColors.WHITE.index);

        CellRangeAddress[] regions = { CellRangeAddress.valueOf("A6:E6") };

        sheetCF.addConditionalFormatting(regions, rule1, rule2);

        Integer fila_inicial = 6;

        for (int i = 0; i < this.t_tabla.getRowCount(); i++) {

            sheet.createRow(fila_inicial + i).createCell(0).setCellValue(t_tabla.getValueAt(i, 1).toString());
            sheet.getRow(fila_inicial + i).getCell(0).setCellStyle(styleCenter);

            for (int j = 1; j < 5; j++) {
                sheet.getRow(fila_inicial + i).createCell(j).setCellValue(t_tabla.getValueAt(i, j + 1).toString());
                sheet.getRow(fila_inicial + i).getCell(j).setCellStyle(styleCenter);
            }

            sheet.getRow(fila_inicial + i).getCell(3)
                    .setCellValue(Double.parseDouble(t_tabla.getValueAt(i, 4).toString()));
            sheet.getRow(fila_inicial + i).getCell(3).setCellStyle(styleRight);

        }
        cargarLogo();
    }

From source file:domain.Excel.java

private void reporteSesionMedicina() {
        sheet.addMergedRegion(CellRangeAddress.valueOf("A1:I1"));
        sheet.addMergedRegion(CellRangeAddress.valueOf("A2:I2"));
        sheet.addMergedRegion(CellRangeAddress.valueOf("A3:I4"));

        /*Name REPORT*/
        HSSFFont FontNameReport = wb.createFont();
        FontNameReport.setFontName("Calibri");
        FontNameReport.setFontHeightInPoints((short) 11);
        FontNameReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        FontNameReport.setColor(HSSFColor.DARK_RED.index);

        HSSFCellStyle styleNameReport = wb.createCellStyle();
        styleNameReport.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleNameReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleNameReport.setFont(FontNameReport);

        Row row = sheet.createRow(0);/*from w  w  w. j  av  a  2 s.c om*/
        Cell cell = row.createCell(0);
        cell.setCellValue("REPORTE DE SESIONES POR MEDICAMENTOS");
        cell.setCellStyle(styleNameReport);
        /**/

        /*DATE REPORT*/
        HSSFFont FontDateReport = wb.createFont();
        FontDateReport.setFontName("Calibri");
        FontDateReport.setFontHeightInPoints((short) 10);
        FontDateReport.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        FontDateReport.setColor(HSSFColor.BLACK.index);

        HSSFCellStyle styleDateReport = wb.createCellStyle();
        styleDateReport.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleDateReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleDateReport.setFont(FontDateReport);

        row = sheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue("FECHA DE REPORTE: " + formatoDateTime.format(new Date()));
        cell.setCellStyle(styleDateReport);

        /*Etiqueta parametro*/
        HSSFFont FontParametroReport = wb.createFont();
        FontParametroReport.setFontName("Calibri");
        FontParametroReport.setFontHeightInPoints((short) 9);
        FontParametroReport.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
        FontParametroReport.setColor(HSSFColor.BLACK.index);

        HSSFCellStyle styleParamReport = wb.createCellStyle();
        styleParamReport.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        styleParamReport.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        styleParamReport.setFont(FontParametroReport);

        row = sheet.createRow(2);
        cell = row.createCell(0);
        String etiqueta_parametro = "";

        switch (tipo) {
        case 1:
            etiqueta_parametro = "Sesion de dia " + formatoDate.format(fecha_ini);
            break;
        case 2:
            etiqueta_parametro = "Sesiones del " + formatoDate.format(fecha_ini) + " al "
                    + formatoDate.format(fecha_fin);
            break;
        case 3:
            etiqueta_parametro = "Sesiones del animal " + animal.arete_visual;
            break;
        }

        cell.setCellValue(etiqueta_parametro);
        cell.setCellStyle(styleParamReport);

        /**/
        sheet.createRow(5).createCell(0).setCellValue("Arete Visual");
        sheet.getRow(5).createCell(1).setCellValue("Arete Electronico");
        sheet.getRow(5).createCell(2).setCellValue("Codigo");
        sheet.getRow(5).createCell(3).setCellValue("Medicamento");
        sheet.getRow(5).createCell(4).setCellValue("Fecha");
        sheet.getRow(5).createCell(5).setCellValue("Corral");
        sheet.getRow(5).createCell(6).setCellValue("Dosis");
        sheet.getRow(5).createCell(7).setCellValue("Costo");
        sheet.getRow(5).createCell(8).setCellValue("Importe");

        sheet.setColumnWidth(0, 15 * Unidad);
        sheet.setColumnWidth(1, 20 * Unidad);
        sheet.setColumnWidth(2, 15 * Unidad);
        sheet.setColumnWidth(3, 20 * Unidad);
        sheet.setColumnWidth(4, 20 * Unidad);
        sheet.setColumnWidth(5, 20 * Unidad);
        sheet.setColumnWidth(6, 15 * Unidad);
        sheet.setColumnWidth(7, 15 * Unidad);
        sheet.setColumnWidth(8, 15 * Unidad);

        SheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();

        //Condition 1: Cell Value Is   greater than  70   (Blue Fill)
        ConditionalFormattingRule rule1 = sheetCF
                .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.GT, "1000");
        PatternFormatting fill1 = rule1.createPatternFormatting();
        fill1.setFillBackgroundColor(IndexedColors.DARK_RED.index);
        fill1.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

        //Condition 2: Cell Value Is  less than      50   (Green Fill)
        ConditionalFormattingRule rule2 = sheetCF
                .createConditionalFormattingRule(CFRuleRecord.ComparisonOperator.LT, "50");
        PatternFormatting fill2 = rule2.createPatternFormatting();
        fill2.setFillBackgroundColor(IndexedColors.DARK_RED.index);
        fill2.setFillPattern(PatternFormatting.SOLID_FOREGROUND);

        FontFormatting font = rule1.createFontFormatting();
        font.setFontStyle(false, true);
        font.setFontColorIndex(IndexedColors.WHITE.index);

        CellRangeAddress[] regions = { CellRangeAddress.valueOf("A6:I6") };

        sheetCF.addConditionalFormatting(regions, rule1, rule2);
        Integer fila_inicial = 6;

        for (int i = 0; i < this.t_tabla.getRowCount(); i++) {
            agregarValor(fila_inicial + i, 0, t_tabla.getValueAt(i, 1).toString(), styleCenter);

            for (int j = 0; j < 9; j++) {
                agregarValor(fila_inicial + i, j, t_tabla.getValueAt(i, j + 1).toString(), styleCenter);
            }
        }
        cargarLogo();
    }

From source file:edu.duke.cabig.c3pr.service.Summary3ReportServiceTest.java

License:BSD License

public void testGenerateEXCEL() throws Exception {
    HealthcareSite hcs = healthcareSiteDao.getById(1100);

    DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
    Date startDate = (Date) format.parse("01/11/1990");
    Date endDate = (Date) format.parse("01/01/2007");
    String grantNumber = "GRANT-NO 1232";

    Summary3Report summary3Report = new Summary3Report(hcs, grantNumber, startDate, endDate);
    String reportingSource = healthcareSiteDao.getById(1000).getName();
    summary3Report.setReportingSource(reportingSource);

    summaryReportService.buildSummary3Report(summary3Report);

    String xmlString = summaryReportService.generateXML(summary3Report);
    File file = new File("testReport.xml");

    FileWriter fileWriter = new FileWriter(file);
    fileWriter.write(xmlString);/*from ww  w  .j ava 2s. co  m*/
    fileWriter.flush();
    fileWriter.close();
    System.out.println(xmlString);

    // creating the workbook and the spreadsheet

    try {

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();

        InputStream inputStream = new FileInputStream(file);
        Document document = builder.parse(inputStream);

        HSSFWorkbook wb = new HSSFWorkbook();

        HSSFSheet spreadSheet = wb.createSheet("Sumary 3 Report");

        PrintSetup printSetup = spreadSheet.getPrintSetup();
        printSetup.setLandscape(true);
        spreadSheet.setFitToPage(true);
        spreadSheet.setHorizontallyCenter(true);

        spreadSheet.setColumnWidth((short) 0, (short) (60 * 256));
        spreadSheet.setColumnWidth((short) 1, (short) (15 * 256));
        spreadSheet.setColumnWidth((short) 2, (short) (30 * 256));

        HSSFRow titleRow = spreadSheet.createRow(0);
        HSSFCell titleCell = titleRow.createCell((short) 0);
        titleRow.setHeightInPoints(40);

        HSSFCellStyle titleCellStyle = wb.createCellStyle();
        titleCellStyle.setAlignment(titleCellStyle.ALIGN_CENTER_SELECTION);
        titleCellStyle.setVerticalAlignment(titleCellStyle.VERTICAL_CENTER);
        titleCell.setCellStyle(titleCellStyle);

        String nullSafeGrantNumber = (document.getElementsByTagName("grantNumber").item(0) != null
                && document.getElementsByTagName("grantNumber").item(0).getFirstChild() != null)
                        ? (document.getElementsByTagName("grantNumber")).item(0).getFirstChild().getNodeValue()
                        : "";
        titleCell.setCellValue("Summary 3: Reportable Patients/Participation " + "in Therapeutic Protocols"
                + "                      " + nullSafeGrantNumber);

        HSSFRow orgRow = spreadSheet.createRow(1);
        orgRow.setHeightInPoints(30);
        HSSFCell organizationCell = orgRow.createCell((short) 0);

        HSSFCellStyle orgCellStyle = wb.createCellStyle();
        orgCellStyle.setAlignment(titleCellStyle.ALIGN_CENTER_SELECTION);
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        orgCellStyle.setFont(font);
        organizationCell.setCellStyle(orgCellStyle);
        organizationCell
                .setCellValue(((Element) (document.getElementsByTagName("reportingOrganization").item(0)))
                        .getElementsByTagName("name").item(0).getFirstChild().getNodeValue());

        HSSFRow reportingPeriodRow = spreadSheet.createRow(2);
        HSSFFont reportingPeriodFont = wb.createFont();
        reportingPeriodFont.setFontHeightInPoints((short) 9);
        HSSFCellStyle reportingPeriodStyle = wb.createCellStyle();
        reportingPeriodStyle.setFont(reportingPeriodFont);

        reportingPeriodRow.setHeightInPoints(20);
        HSSFCell reportingPeriodCell = reportingPeriodRow.createCell((short) 0);
        reportingPeriodCell.setCellStyle(titleCellStyle);

        reportingPeriodCell.setCellValue("Reporting Period "
                + (document.getElementsByTagName("startDate").item(0).getFirstChild().getNodeValue()) + " - "
                + (document.getElementsByTagName("endDate").item(0).getFirstChild().getNodeValue()));

        // creating the first row of table the table header
        HSSFRow row = spreadSheet.createRow(3);
        HSSFCell tableHeaderCell1 = row.createCell((short) 0);
        HSSFCellStyle tableHeaderCellStyle1 = wb.createCellStyle();
        tableHeaderCellStyle1.setWrapText(true);

        tableHeaderCellStyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle1.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle1.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        tableHeaderCellStyle1.setFont(font);
        tableHeaderCell1.setCellStyle(tableHeaderCellStyle1);
        tableHeaderCell1.setCellValue("Disease Site");

        // creating table header 2nd & 3rd cells

        HSSFCell tableHeaderCell2 = row.createCell((short) 1);
        HSSFCellStyle tableHeaderCellStyle2 = wb.createCellStyle();

        tableHeaderCellStyle2.setBorderRight(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle2.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle2.setWrapText(true);

        tableHeaderCell2.setCellStyle(tableHeaderCellStyle2);
        tableHeaderCell2.setCellValue("Newly Registered Patients");

        HSSFCell tableHeaderCell3 = row.createCell((short) 2);

        HSSFCellStyle tableHeaderCellStyle3 = wb.createCellStyle();

        tableHeaderCellStyle3.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle3.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle3.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle3.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle3.setWrapText(true);
        tableHeaderCell3.setCellStyle(tableHeaderCellStyle3);
        tableHeaderCell3.setCellValue("Total patients newly enrolled in therapeutic protocols");

        NodeList nodeList = document.getElementsByTagName("reportData");

        HSSFCellStyle tableCellStyle = wb.createCellStyle();
        tableCellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        tableCellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        tableCellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        tableCellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);

        spreadSheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$C$1"));
        spreadSheet.addMergedRegion(CellRangeAddress.valueOf("$A$2:$C$2"));
        spreadSheet.addMergedRegion(CellRangeAddress.valueOf("$A$3:$C$3"));
        for (int i = 4; i < nodeList.getLength() + 4; i++) {

            row = spreadSheet.createRow(i);
            HSSFCell cell = row.createCell((short) 0);
            if (i == (4 + nodeList.getLength() - 1)) {
                HSSFCellStyle totalCellStyle = wb.createCellStyle();
                totalCellStyle.setFont(font);
                totalCellStyle.setRightBorderColor((short) 10);
                totalCellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
                tableCellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
                totalCellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
                totalCellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
                cell.setCellStyle(totalCellStyle);
            } else {
                cell.setCellStyle(tableCellStyle);
            }
            cell.setCellValue(((Element) ((Element) (nodeList.item(i - 4))).getElementsByTagName("key").item(0))
                    .getAttribute("name"));

            cell = row.createCell((short) 1);
            cell.setCellStyle(tableCellStyle);

            cell.setCellValue("");

            cell = row.createCell((short) 2);
            cell.setCellStyle(tableCellStyle);

            cell.setCellValue(
                    ((Element) (((Element) (nodeList.item(i - 4))).getElementsByTagName("value").item(3)))
                            .getFirstChild().getNodeValue());
        }
        File outputFile = new File(System.getProperty("user.home") + File.separator + "Summary3Report.xls");
        FileOutputStream output = new FileOutputStream(outputFile);
        wb.write(output);
        output.flush();
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }

}

From source file:edu.duke.cabig.c3pr.xml.Summary3ReportGenerator.java

License:BSD License

public void generateExcel(String summary3ReportXml, String file) throws Exception {

    // creating the workbook and the spreadsheet
    try {/*from   w ww  . j a  v a  2s .co m*/

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();

        String fileName = "";

        fileName = file;

        InputStream inputStream = new FileInputStream((fileName + ".xml"));
        Document document = builder.parse(inputStream);

        HSSFWorkbook wb = new HSSFWorkbook();

        HSSFSheet spreadSheet = wb.createSheet("Sumary 3 Report");

        PrintSetup printSetup = spreadSheet.getPrintSetup();
        printSetup.setLandscape(true);
        spreadSheet.setFitToPage(true);
        spreadSheet.setHorizontallyCenter(true);

        spreadSheet.setColumnWidth((short) 0, (short) (60 * 256));
        spreadSheet.setColumnWidth((short) 1, (short) (15 * 256));
        spreadSheet.setColumnWidth((short) 2, (short) (30 * 256));

        HSSFRow titleRow = spreadSheet.createRow(0);
        HSSFCell titleCell = titleRow.createCell((short) 0);
        titleRow.setHeightInPoints(40);

        HSSFCellStyle titleCellStyle = wb.createCellStyle();
        titleCellStyle.setAlignment(titleCellStyle.ALIGN_CENTER_SELECTION);
        titleCellStyle.setVerticalAlignment(titleCellStyle.VERTICAL_CENTER);
        titleCell.setCellStyle(titleCellStyle);

        String nullSafeGrantNumber = (document.getElementsByTagName("grantNumber").item(0) != null
                && document.getElementsByTagName("grantNumber").item(0).getFirstChild() != null)
                        ? (document.getElementsByTagName("grantNumber")).item(0).getFirstChild().getNodeValue()
                        : "";
        titleCell.setCellValue("Summary 3: Reportable Patients/Participation " + "in Therapeutic Protocols"
                + "                      " + nullSafeGrantNumber);

        HSSFRow orgRow = spreadSheet.createRow(1);
        orgRow.setHeightInPoints(30);
        HSSFCell organizationCell = orgRow.createCell((short) 0);

        HSSFCellStyle orgCellStyle = wb.createCellStyle();
        orgCellStyle.setAlignment(titleCellStyle.ALIGN_CENTER_SELECTION);
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        orgCellStyle.setFont(font);
        organizationCell.setCellStyle(orgCellStyle);
        organizationCell
                .setCellValue(((Element) (document.getElementsByTagName("reportingOrganization").item(0)))
                        .getElementsByTagName("name").item(0).getFirstChild().getNodeValue());

        HSSFRow reportingPeriodRow = spreadSheet.createRow(2);
        HSSFFont reportingPeriodFont = wb.createFont();
        reportingPeriodFont.setFontHeightInPoints((short) 9);
        HSSFCellStyle reportingPeriodStyle = wb.createCellStyle();
        reportingPeriodStyle.setFont(reportingPeriodFont);

        reportingPeriodRow.setHeightInPoints(20);
        HSSFCell reportingPeriodCell = reportingPeriodRow.createCell((short) 0);
        reportingPeriodCell.setCellStyle(titleCellStyle);

        reportingPeriodCell.setCellValue("Reporting Period "
                + (document.getElementsByTagName("startDate").item(0).getFirstChild().getNodeValue()) + " - "
                + (document.getElementsByTagName("endDate").item(0).getFirstChild().getNodeValue()));

        // creating the first row of table the table header
        HSSFRow row = spreadSheet.createRow(3);
        HSSFCell tableHeaderCell1 = row.createCell((short) 0);
        HSSFCellStyle tableHeaderCellStyle1 = wb.createCellStyle();
        tableHeaderCellStyle1.setWrapText(true);

        tableHeaderCellStyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle1.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle1.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        tableHeaderCellStyle1.setFont(font);
        tableHeaderCell1.setCellStyle(tableHeaderCellStyle1);
        tableHeaderCell1.setCellValue("Disease Site");

        // creating table header 2nd & 3rd cells

        HSSFCell tableHeaderCell2 = row.createCell((short) 1);
        HSSFCellStyle tableHeaderCellStyle2 = wb.createCellStyle();

        tableHeaderCellStyle2.setBorderRight(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle2.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle2.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle2.setWrapText(true);

        tableHeaderCell2.setCellStyle(tableHeaderCellStyle2);
        tableHeaderCell2.setCellValue("Newly Registered Patients");

        HSSFCell tableHeaderCell3 = row.createCell((short) 2);

        HSSFCellStyle tableHeaderCellStyle3 = wb.createCellStyle();

        tableHeaderCellStyle3.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle3.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        tableHeaderCellStyle3.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle3.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        tableHeaderCellStyle3.setWrapText(true);
        tableHeaderCell3.setCellStyle(tableHeaderCellStyle3);
        tableHeaderCell3.setCellValue("Total patients newly enrolled in therapeutic protocols");

        NodeList nodeList = document.getElementsByTagName("reportData");

        HSSFCellStyle tableCellStyle = wb.createCellStyle();
        tableCellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
        tableCellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
        tableCellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
        tableCellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);

        spreadSheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$C$1"));
        spreadSheet.addMergedRegion(CellRangeAddress.valueOf("$A$2:$C$2"));
        spreadSheet.addMergedRegion(CellRangeAddress.valueOf("$A$3:$C$3"));
        for (int i = 4; i < nodeList.getLength() + 4; i++) {

            row = spreadSheet.createRow(i);
            HSSFCell cell = row.createCell((short) 0);
            if (i == (4 + nodeList.getLength() - 1)) {
                HSSFCellStyle totalCellStyle = wb.createCellStyle();
                totalCellStyle.setFont(font);
                totalCellStyle.setRightBorderColor((short) 10);
                totalCellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
                tableCellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
                totalCellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
                totalCellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
                cell.setCellStyle(totalCellStyle);
            } else {
                cell.setCellStyle(tableCellStyle);
            }
            cell.setCellValue(((Element) ((Element) (nodeList.item(i - 4))).getElementsByTagName("key").item(0))
                    .getAttribute("name"));

            cell = row.createCell((short) 1);
            cell.setCellStyle(tableCellStyle);

            cell.setCellValue("");

            cell = row.createCell((short) 2);
            cell.setCellStyle(tableCellStyle);

            cell.setCellValue(
                    ((Element) (((Element) (nodeList.item(i - 4))).getElementsByTagName("value").item(3)))
                            .getFirstChild().getNodeValue());
        }
        FileOutputStream output = new FileOutputStream(new File(addExtension(file, "Excel")));
        wb.write(output);
        output.flush();
        output.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }
}

From source file:edu.ku.brc.dbsupport.TableModel2Excel.java

License:Open Source License

/**
 * Converts a tableModel to an Excel Spreadsheet.
 * @param toFile the file object to write it to.
 * @param title the title of the spreadsheet.
 * @param tableModel the table model// w  w  w  . jav  a  2  s  .c  o  m
 * @return a file to a spreadsheet
 */
public static File convertToExcel(final File toFile, final String title, final TableModel tableModel) {
    if (toFile == null) {
        UIRegistry.showLocalizedMsg("WARNING", "FILE_NO_EXISTS",
                toFile != null ? toFile.getAbsolutePath() : "");
        return null;
    }

    if (tableModel != null && tableModel.getRowCount() > 0) {
        try {
            // create a new file
            FileOutputStream out;
            try {
                out = new FileOutputStream(toFile);

            } catch (FileNotFoundException ex) {
                UIRegistry.showLocalizedMsg("WARNING", "FILE_NO_WRITE",
                        toFile != null ? toFile.getAbsolutePath() : "");
                return null;
            }

            // create a new workbook
            HSSFWorkbook wb = new HSSFWorkbook();

            // create a new sheet
            HSSFSheet sheet = wb.createSheet();
            // declare a row object reference

            // Header Captions
            HSSFFont headerFont = wb.createFont();
            headerFont.setFontHeightInPoints((short) 12);
            headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

            // create a style for the header cell
            HSSFCellStyle headerStyle = wb.createCellStyle();
            headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            headerStyle.setFont(headerFont);
            setBordersOnStyle(headerStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN);

            short numColumns = (short) tableModel.getColumnCount();

            HSSFRow headerRow = sheet.createRow(0);
            for (int i = 0; i < numColumns; i++) {
                HSSFCell headerCell = headerRow.createCell((short) i);
                headerCell.setCellStyle(headerStyle);

                //add the date to the header cell
                headerCell.setCellValue(tableModel.getColumnName(i));
                sheet.setColumnWidth((short) i, (short) (30 * 256));
            }

            //--------------------------
            // done header
            //--------------------------

            // create 3 cell styles
            HSSFCellStyle oddCellStyle = wb.createCellStyle();
            HSSFCellStyle evenCellStyle = wb.createCellStyle();

            setBordersOnStyle(oddCellStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN);
            setBordersOnStyle(evenCellStyle, HSSFColor.GREY_25_PERCENT.index, HSSFCellStyle.BORDER_THIN);

            // create 2 fonts objects
            HSSFFont cellFont = wb.createFont();
            //set font 1 to 12 point type
            cellFont.setFontHeightInPoints((short) 11);
            oddCellStyle.setFont(cellFont);
            evenCellStyle.setFont(cellFont);

            evenCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            oddCellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

            oddCellStyle.setFillForegroundColor(HSSFColor.WHITE.index);
            evenCellStyle.setFillForegroundColor(HSSFColor.LIGHT_CORNFLOWER_BLUE.index);

            oddCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            evenCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);

            // set the sheet name to HSSF Test
            wb.setSheetName(0, title);

            for (short rownum = 0; rownum < (short) tableModel.getRowCount(); rownum++) {
                // create a row
                HSSFRow row = sheet.createRow(rownum + 1);

                for (short cellnum = (short) 0; cellnum < numColumns; cellnum++) {
                    // create a numeric cell
                    HSSFCell cell = row.createCell(cellnum);

                    Object dataVal = tableModel.getValueAt(rownum, cellnum);
                    cell.setCellValue(dataVal != null ? dataVal.toString() : "");

                    // on every other row
                    cell.setCellStyle((rownum % 2) == 0 ? evenCellStyle : oddCellStyle);
                }
            }

            // write the workbook to the output stream
            // close our file (don't blow out our file handles
            wb.write(out);
            out.close();

        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TableModel2Excel.class, ex);
            log.error("convertToExcel", ex); //$NON-NLS-1$
        }
    }
    return toFile;
}

From source file:eionet.gdem.conversion.excel.writer.ExcelConversionHandler.java

License:Mozilla Public License

/**
 * Adds style to workbook./*from w  ww.  ja  v a  2  s  .co m*/
 * @param style Style
 */
private void addStyleToWorkbook(ExcelStyleIF style) {
    HSSFFont font = wb.createFont();
    // Font Size eg.12
    short height = style.getFontSize();
    if (height > 0) {
        font.setFontHeightInPoints(height);
    }
    // Font Name eg.Arial
    String font_name = style.getFontName();
    if (font_name != null) {
        font.setFontName(font_name);
    }
    // Italic
    font.setItalic(style.getItalic());
    // Font Weight eg.bold
    short weight = style.getFontWeight();
    font.setBoldweight(weight);

    // Fonts are set into a style so create a new one to use.
    HSSFCellStyle HSSFStyle = wb.createCellStyle();
    HSSFStyle.setFont(font);
    // Text alignment eg.center
    short align = style.getTextAlign();
    HSSFStyle.setAlignment(align);

    style.setWorkbookIndex(HSSFStyle.getIndex());

}

From source file:es.jamisoft.comun.io.excel.ExcelGenerator.java

License:Apache License

/**
 * Este mtodo asigna el formato a los caracteres.
 *
 * @param wb Objeto Excel./*from   w  ww  . ja v a 2 s  . co m*/
 * @param cellStyle Estilo de celda para crearl formato a los caracteres.
 * @param fillFontColor Color que se asignara a los cartares.
 */
private void createFontCell(HSSFWorkbook wb, HSSFCellStyle cellStyle, short fillFontColor) {

    // create instance of HSSFCellStyle
    HSSFFont fontHead = wb.createFont();

    // Create Font Header
    fontHead.setFontHeightInPoints(ep.getSizeFont());

    if (ep.getFontName() != null) {
        fontHead.setFontName(ep.getFontName());
    }

    fontHead.setColor(fillFontColor);

    // Fonts are set into a style so create a new one to use.
    cellStyle.setFont(fontHead);
}

From source file:excel.PoiWriteExcelFile.java

public static int generarReporte() {

    //Calendar cal=Calendar.getInstance();
    Calendar cal = WorkMonitorUI.instante;

    try {//from w  ww . j  a v a 2 s  .c  o m
        FileOutputStream fileOut = new FileOutputStream("HH_"
                + instante.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.getDefault())
                        .toUpperCase()
                + "_" + persona.getNombre().toUpperCase().charAt(0) + "." + persona.getApellido().toUpperCase()
                + "_" + instante.get(Calendar.YEAR) + ".xls");
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet(
                cal.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.getDefault()).toUpperCase()
                        + "-" + cal.get(Calendar.YEAR));

        HSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFillForegroundColor(HSSFColor.YELLOW.index);
        cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        HSSFFont font = workbook.createFont();
        font.setFontHeightInPoints((short) 12);
        font.setFontName("Calibri");
        font.setItalic(false);
        font.setBold(true);
        font.setColor(HSSFColor.BLACK.index);
        cellStyle.setFont(font);
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        HSSFCellStyle diasStyle = workbook.createCellStyle();
        diasStyle.setFillForegroundColor(HSSFColor.SEA_GREEN.index);
        diasStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        font = workbook.createFont();
        font.setFontHeightInPoints((short) 11);
        font.setFontName("Calibri");
        font.setItalic(false);
        font.setBold(true);
        font.setColor(HSSFColor.WHITE.index);
        diasStyle.setFont(font);
        diasStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        diasStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        diasStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        diasStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        diasStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        diasStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        HSSFCellStyle schedStyle = workbook.createCellStyle();
        schedStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
        schedStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        HSSFFont font3 = workbook.createFont();
        font3.setFontHeightInPoints((short) 11);
        font3.setFontName("Calibri");
        font3.setItalic(false);
        font3.setColor(HSSFColor.BLACK.index);
        schedStyle.setFont(font3);
        schedStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        schedStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        schedStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        schedStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        schedStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        schedStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        HSSFCellStyle workdayStyle = workbook.createCellStyle();
        //workdayStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);                        
        workdayStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        workdayStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        workdayStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        workdayStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        workdayStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        workdayStyle.setWrapText(true);
        HSSFFont font2 = workbook.createFont();
        font2.setFontHeightInPoints((short) 8);
        font2.setFontName("Serif");
        font2.setItalic(false);
        //font2.setColor(HSSFColor.YELLOW.index);
        workdayStyle.setFont(font2);
        workdayStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        HSSFCellStyle weekendStyle = workbook.createCellStyle();
        weekendStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
        weekendStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        weekendStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        weekendStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        weekendStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        weekendStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        weekendStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        weekendStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);

        HSSFCellStyle horarioStyle = workbook.createCellStyle();
        horarioStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
        horarioStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        horarioStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        horarioStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        horarioStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        horarioStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        horarioStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        horarioStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        HSSFFont font4 = workbook.createFont();
        font4.setFontHeightInPoints((short) 10);
        font4.setFontName("Serif");
        font4.setItalic(false);
        font4.setBold(true);
        //font2.setColor(HSSFColor.YELLOW.index);
        horarioStyle.setFont(font4);

        // index from 0,0... cell A1 is cell(0,0)
        HSSFRow row1 = worksheet.createRow((short) 0);
        row1.setHeight((short) 500);

        //System.out.println("cal.get(Calendar.YEAR)="+cal.get(Calendar.YEAR));

        HSSFCell cellA1 = row1.createCell((short) 0);
        cellA1.setCellValue(
                cal.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.getDefault()).toUpperCase()
                        + "-" + cal.get(Calendar.YEAR));
        cellA1.setCellStyle(cellStyle);

        HSSFRow row2 = worksheet.createRow((short) 1);
        HSSFCell cellA4 = row2.createCell((short) 0);
        cellA4.setCellValue("Horario");
        cellA4.setCellStyle(horarioStyle);
        //row2.setHeight((short)500);

        HSSFRow row3 = worksheet.createRow((short) 2);
        HSSFCell cellA3 = row3.createCell((short) 0);
        cellA3.setCellValue("Inicio - Trmino");
        cellA3.setCellStyle(diasStyle);

        Calendar hora = Calendar.getInstance();

        hora.set(Calendar.HOUR_OF_DAY, 9);
        hora.set(Calendar.MINUTE, 0);
        hora.set(Calendar.SECOND, 0);

        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");

        HSSFCell cellXn;

        for (int i = 0; i < 29; ++i) {
            HSSFRow row = worksheet.createRow((short) i + 3);
            row.setHeight((short) 500);

            cellXn = row.createCell((short) 0);
            String horaIni = sdf.format(hora.getTime());
            hora.add(Calendar.MINUTE, 30);
            String horaFin = sdf.format(hora.getTime());
            cellXn.setCellValue(horaIni + " - " + horaFin);
            cellXn.setCellStyle(schedStyle);
        }

        System.out.println("cal.get(Calendar.MONTH)1=" + cal.get(Calendar.MONTH));

        cal.add(Calendar.DAY_OF_MONTH, -cal.get(Calendar.DAY_OF_MONTH) + 1);

        int diasMes = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

        System.out.println("cal.get(Calendar.MONTH)2=" + cal.get(Calendar.MONTH));

        sdf = new SimpleDateFormat("EEEE d");

        System.out.println(
                "cal.getActualMaximum(Calendar.DAY_OF_MONTH)1=" + cal.getActualMaximum(Calendar.DAY_OF_MONTH));

        for (int i = 0; i < diasMes; ++i) {
            cellXn = row2.createCell((short) i + 1);
            String dia = sdf.format(cal.getTime());
            dia = Character.toUpperCase(dia.charAt(0)) + dia.substring(1);
            cellXn.setCellValue(dia);
            cellXn.setCellStyle(horarioStyle);
            //System.out.println("cal.get(Calendar.DAY_OF_MONTH)="+cal.get(Calendar.DAY_OF_MONTH));
            cal.add(Calendar.DAY_OF_MONTH, 1);
        }

        for (int i = 0; i < diasMes; ++i) {
            cellXn = row3.createCell((short) i + 1);
            cellXn.setCellValue("Descripcin");
            cellXn.setCellStyle(diasStyle);
        }

        System.out.println(
                "cal.getActualMaximum(Calendar.DAY_OF_MONTH)2=" + cal.getActualMaximum(Calendar.DAY_OF_MONTH));

        // Retroceder mes para que quede como estaba
        cal.add(Calendar.MONTH, -1);
        //cal.add(Calendar.DAY_OF_MONTH, -1);    

        System.out.println(
                "cal.getActualMaximum(Calendar.DAY_OF_MONTH)3=" + cal.getActualMaximum(Calendar.DAY_OF_MONTH));

        HhDao hhDao = new HhDao();
        Object[][] hh = new Object[29][cal.getActualMaximum(Calendar.DAY_OF_MONTH)];

        hh = hhDao.getByMes(WorkMonitorUI.persona.getId(), cal.getTime());

        cal.set(Calendar.DAY_OF_MONTH, 1);

        Sheet sheet = workbook.getSheetAt(0);

        sdf = new SimpleDateFormat("EEEE");

        HSSFPatriarch _drawing = (HSSFPatriarch) sheet.createDrawingPatriarch();
        CreationHelper factory = workbook.getCreationHelper();

        for (int i = 0; i < 29; ++i) {
            Row r = sheet.getRow(i + 3);
            for (int j = 0; j < diasMes; ++j) {
                if (hh[i][j].toString() != "") {
                    cellXn = (HSSFCell) r.createCell((short) j + 1);
                    Hh _hh = (Hh) hh[i][j];
                    cellXn.setCellValue(
                            _hh.getTarea().getNombre().trim() + ": " + _hh.getActividad().getNombre().trim());

                    HSSFAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5);
                    org.apache.poi.ss.usermodel.Comment comment = _drawing.createComment(anchor);
                    String comentario = _hh.getTarea().getComentario().toLowerCase();
                    if (_hh.getComentario() != null)
                        comentario = comentario + _hh.getComentario().toLowerCase();
                    RichTextString str = factory.createRichTextString(comentario);

                    comment.setString(str);

                    cellXn.setCellComment(comment);
                } else {
                    cellXn = (HSSFCell) r.createCell((short) j + 1);
                    cellXn.setCellValue("");
                }
                //System.out.println("sdf.format(cal.getTime())="+sdf.format(cal.getTime()));
                if (Arrays.asList("sbado", "domingo").contains(sdf.format(cal.getTime())))
                    cellXn.setCellStyle(weekendStyle);
                else
                    cellXn.setCellStyle(workdayStyle);
                sheet.setColumnWidth(j, 5000);

                cal.add(Calendar.DAY_OF_MONTH, 1);
                //sheet.autoSizeColumn(j);
            }
            // Retroceder mes para que quede como estaba                
            cal.add(Calendar.MONTH, -1);
            System.out.println("cal.get(Calendar.MONTH)3=" + cal.get(Calendar.MONTH));
            cal.set(Calendar.DAY_OF_MONTH, 1);
        }
        sheet.setColumnWidth(diasMes, 5000);

        WorkMonitorUI.instante = Calendar.getInstance();
        sheet.setColumnWidth(0, 5000);
        sheet.createFreezePane(1, 3);
        // Freeze just one row
        //sheet.createFreezePane( 0, 1, 0, 1 );

        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return -1;
    } catch (IOException e) {
        e.printStackTrace();
        return -2;
    }
    return 1;
}

From source file:FILING.cboreport.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*ww w.  j a  v  a  2s.  c o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException {
    response.setContentType("text/html;charset=UTF-8");
    //        PrintWriter out = response.getWriter();
    try {
        dbConn conn = new dbConn("1");
        String District[];
        String Year = "";
        District = request.getParameterValues("District");
        Year = request.getParameter("Year");
        String FirstName = "";
        String MiddleName = "";
        String Surname = "";
        String ovcid1 = "";
        String ovcid2 = "";
        int value0 = 0;
        int value1 = 0;
        String Districtid = "";
        String cboid = "";
        String doc = "";
        String docname = "";
        String cboname = "";
        String districtname = "";
        String distval = "";
        int activeOVC = 0;
        int activeHH = 0;
        float activeovc = 0;
        float activehh = 0;
        float percent = 0;
        //             ^^^^^^^^^^^^^CREATE STATIC AND WRITE STATIC DATA TO THE EXCELL^^^^^^^^^^^^
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet shet1 = wb.createSheet();

        //%%%%%%%%%%%%%%%%HEADER FONTS AND COLORATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        // style header with font color yello 

        HSSFFont font_header = wb.createFont();
        font_header.setFontHeightInPoints((short) 10);
        font_header.setFontName("Arial Black");
        font_header.setItalic(true);
        font_header.setBoldweight((short) 05);
        font_header.setColor(HSSFColor.BLACK.index);
        CellStyle style_header = wb.createCellStyle();
        style_header.setFont(font_header);
        style_header.setWrapText(true);
        style_header.setFillForegroundColor(HSSFColor.YELLOW.index);
        style_header.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style_header.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style_header.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style_header.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style_header.setAlignment(CellStyle.ALIGN_CENTER);
        style_header.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        // stylex with font color blue  and backgound grey
        HSSFCellStyle stylex = wb.createCellStyle();
        stylex.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
        stylex.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        HSSFFont fontx = wb.createFont();
        fontx.setColor(HSSFColor.DARK_BLUE.index);
        stylex.setFont(fontx);
        stylex.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        stylex.setBorderTop(HSSFCellStyle.BORDER_THIN);
        stylex.setBorderRight(HSSFCellStyle.BORDER_THIN);
        stylex.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        stylex.setAlignment(CellStyle.ALIGN_CENTER);

        // gold bg color -style
        HSSFFont font = wb.createFont();
        font.setFontHeightInPoints((short) 12);
        font.setFontName("Cambria");
        font.setItalic(true);
        font.setBoldweight((short) 02);
        font.setColor(HSSFColor.BLACK.index);
        CellStyle style = wb.createCellStyle();
        style.setFont(font);
        style.setWrapText(true);
        style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);

        // for border with no font color
        CellStyle style_border = wb.createCellStyle();
        style_border.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style_border.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style_border.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style_border.setBorderLeft(HSSFCellStyle.BORDER_THIN);

        HSSFFont font1 = wb.createFont();
        font1.setFontHeightInPoints((short) 18);
        font1.setFontName("Cambria");
        font1.setBoldweight((short) 7);
        font1.setColor(HSSFColor.BLACK.index);

        CellStyle style_border1 = wb.createCellStyle();
        style_border1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style_border1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style_border1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style_border1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style_border1.setFont(font);
        style_border1.setAlignment(CellStyle.ALIGN_CENTER);
        style_border1.setVerticalAlignment(CellStyle.ALIGN_LEFT);

        HSSFRow rw1 = shet1.createRow(1);
        rw1.setHeightInPoints(30);
        for (int y = 0; y < 11; ++y) {
            HSSFCell cell = rw1.createCell(y);
            cell.setCellStyle(stylex);

            if (y == 0) {
                cell.setCellValue("CBO FILING TRACKER REPORT" + "( " + Year + ")");

            }
        }
        shet1.addMergedRegion(new CellRangeAddress(1, 1, 0, 11));

        shet1.setColumnWidth(0, 4500);
        shet1.setColumnWidth(1, 8500);
        shet1.setColumnWidth(2, 5000);
        shet1.setColumnWidth(3, 5000);
        shet1.setColumnWidth(4, 5000);
        shet1.setColumnWidth(5, 5000);
        shet1.setColumnWidth(6, 5000);
        shet1.setColumnWidth(7, 5000);
        shet1.setColumnWidth(8, 5000);
        shet1.setColumnWidth(9, 5000);
        shet1.setColumnWidth(10, 5000);
        shet1.setColumnWidth(11, 5000);
        shet1.setColumnWidth(12, 5000);
        shet1.setColumnWidth(13, 5000);
        shet1.setColumnWidth(14, 5000);
        shet1.setColumnWidth(15, 5000);
        shet1.setColumnWidth(16, 5000);
        shet1.setColumnWidth(17, 4000);
        shet1.setColumnWidth(18, 4000);
        shet1.setColumnWidth(19, 4200);
        shet1.setColumnWidth(20, 4200);
        shet1.setColumnWidth(21, 4200);
        shet1.setColumnWidth(22, 4200);

        //  Merge the cells
        //  shet1.addMergedRegion(new CellRangeAddress(1,1,1,3));

        HSSFRow rw4 = shet1.createRow(2);
        rw4.setHeightInPoints(40);
        HSSFRow rw6 = shet1.createRow(3);
        rw6.setHeightInPoints(25);
        //    rw4.setRowStyle(style);
        //    
        //  
        //    rw6.setRowStyle(style);
        // 

        // rw4.createCell(1).setCellValue("Number");
        HSSFCell cell1, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, cell10, cell11, cell12, cell13,
                cell14, cell15, cell16;
        // cells fo row 2 
        cell1 = rw4.createCell(0);
        cell2 = rw4.createCell(1);

        cell4 = rw4.createCell(3);

        cell1.setCellValue("DISTRICT");
        cell1.setCellStyle(style);
        cell2.setCellValue("CBO");
        cell2.setCellStyle(style);

        cell6 = rw6.createCell(0);
        cell6.setCellValue("Status");
        cell6.setCellStyle(style);
        cell7 = rw6.createCell(1);
        cell7.setCellValue("");
        cell7.setCellStyle(style);
        shet1.addMergedRegion(new CellRangeAddress(3, 3, 0, 1));
        int rowcount = 3;
        int doccounter = 4;
        int doccounter1 = 4;
        int columcounter = 3;
        String cboids = "";
        int mergecounter = 2;

        cell3 = rw4.createCell(2);
        cell3.setCellValue("ACTIVE OVC");
        cell3.setCellStyle(style);
        cell3 = rw4.createCell(3);
        cell3.setCellValue("ACTIVE HH");
        cell3.setCellStyle(style);

        cell6 = rw6.createCell(2);
        cell6.setCellValue("");
        cell6.setCellStyle(stylex);
        cell6 = rw6.createCell(3);
        cell6.setCellValue("");
        cell6.setCellStyle(stylex);
        ArrayList docidarray = new ArrayList();
        String getdocname = "select * from ovcdocuments WHERE DocumentName!=''";
        conn.rs3 = conn.state3.executeQuery(getdocname);
        while (conn.rs3.next()) {
            docidarray.add(conn.rs3.getString(1));
            System.out.println(conn.rs3.getString(2));
            docname = conn.rs3.getString(2);
            cell3 = rw4.createCell(doccounter1);
            cell3.setCellValue(docname);
            cell3.setCellStyle(style);

            cell6 = rw6.createCell(doccounter1);
            cell6.setCellValue("Available");
            cell6.setCellStyle(stylex);

            //           cell5=rw6.createCell(doccounter1);
            //          cell5.setCellValue("Not Available"); 
            //          cell5.setCellStyle(stylex);
            doccounter1++;

            System.out.println("mergecounter b4" + mergecounter);
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,2,3));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,4,5));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,6,7));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,8,9));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,10,11));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,12,13));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,14,15));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,16,17));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,18,19));
            //      shet1.addMergedRegion(new CellRangeAddress(2,2,20,21));

            System.out.println("mergecounter after" + mergecounter);
            // mergecounter++;

            //shet1.addMergedRegion(new CellRangeAddress(2,2,doccounter1,doccounter1++));
        }

        System.out.println("lll " + doccounter1);
        int rowcounter = 4;
        int counter = 0;
        int countercopy = 4;
        HSSFRow rw5 = null;
        for (int j = 0; j < District.length; j++) {
            String getcboCOUNT = "select * from CBO where DistrictID='" + District[j]
                    + "' Order by DistrictID ";
            conn.rs2 = conn.state2.executeQuery(getcboCOUNT);
            while (conn.rs2.next()) {

                counter++;
                rowcount++;
                rw5 = shet1.createRow(rowcount);
                for (int i = 2; i < doccounter1; i++) {
                    System.out.println("mm " + i);
                    cell5 = rw5.createCell(i);
                    cell5.setCellValue("");
                    cell5.setCellStyle(style_border1);

                }

                cell2 = rw5.createCell(1);
                cell2.setCellValue(conn.rs2.getString(2));
                cell2.setCellStyle(style_border);

                //            cell5=rw5.createCell(rowcount);
                //        cell6=rw5.createCell(rowcounter++);
                //        cell5.setCellValue("x"); 
                //        cell6.setCellValue("y");
                System.out.println("rowcount " + rowcount + " lll   " + counter + " rowcounter " + rowcounter);

                rw5.setHeightInPoints(25);

                //   cell3=rw5.createCell(2);
                String getDistrict = "select * from District where DistrictID='" + District[j]
                        + "' Order by DistrictID ";
                conn.rs4 = conn.state4.executeQuery(getDistrict);
                while (conn.rs4.next()) {
                    districtname = conn.rs4.getString("District");
                    cell1 = rw5.createCell(0);
                    cell1.setCellValue(districtname);
                    cell1.setCellStyle(style_border1);

                }
                doccounter = 4;
                System.out.println("doccount " + doccounter);

                String getdocname1 = "select * from ovcdocuments";
                //          conn.rs3 = conn.state.executeQuery(getdocname1);
                //          while(conn.rs3.next()){
                String getData = "select " + "SUM(CASE WHEN ovcfiling.value='1' THEN 1 ELSE 0 END) AS COUNT1, "
                        + "SUM(CASE WHEN ovcfiling.value='0' THEN 1 ELSE 0 END) AS COUNT0,"
                        + "Clientdetails.Cbo," + "ovcfiling.ovcdocid,Clientdetails.District,"
                        + "count(Clientdetails.OVCID)," + "count(DISTINCT(Clientdetails.HouseHoldheadID))"
                        + " from ovcfiling,Clientdetails  " + "WHERE Clientdetails.District ='" + District[j]
                        + "' and " + "Clientdetails.Cbo='" + conn.rs2.getString(1)
                        + "' and Clientdetails.Exited='1' and  " + " (Year='" + Year
                        + "' OR Year='') AND  Clientdetails.OVCID = ovcfiling.ovcid "
                        + "group by ovcfiling.ovcdocid,Clientdetails.Cbo,Clientdetails.District  Order by  ovcfiling.ovcdocid,District ";
                System.out.println("aaaaa  " + getData);
                conn.rs = conn.state.executeQuery(getData);
                while (conn.rs.next()) {

                    value1 = conn.rs.getInt(1);
                    value0 = conn.rs.getInt(2);
                    cboid = conn.rs.getString(3);
                    doc = conn.rs.getString(4);
                    Districtid = conn.rs.getString(5);
                    activeOVC = conn.rs.getInt(6);
                    activeHH = conn.rs.getInt(7);

                    int a = 0;
                    for (int i = 0; i < docidarray.size(); i++) {
                        System.out.println("hh " + docidarray.get(i) + "  " + doc);

                        if (docidarray.get(i).equals(doc)) {
                            System.out.println(doc + "lll" + docidarray.get(i));
                            int cellcount = i + 2;
                            activeovc = activeOVC;
                            activehh = activeHH;

                            if (doc.equals("8")) {
                                percent = value1 / activehh * 100;
                            } else {
                                percent = value1 / activeovc * 100;
                            }
                            cell7 = rw5.createCell(2);
                            cell8 = rw5.createCell(3);

                            cell5 = rw5.createCell(doccounter);
                            //                             cell6=rw5.createCell(doccounter);
                            cell5.setCellValue(Math.round(percent) + "%");
                            //                              cell6.setCellValue(value0); 

                            //FOR ACTICE OVCs
                            cell7.setCellValue(activeOVC);
                            cell7.setCellStyle(style_border);
                            //FOR ACTICE hhs
                            cell8.setCellValue(activeHH);
                            cell8.setCellStyle(style_border);

                            cell5.setCellStyle(style_border);

                            cell6.setCellStyle(style_border);
                            System.out.println("****a  " + doc + " " + doccounter);

                            if (doc.equals("2")) {

                                // System.out.println("****i  "+doc +" "+doccounter);
                                doccounter++;
                                //                                 doccounter++; 
                                System.out.println("am in2");
                                System.out.println("****b  " + doc + " " + doccounter);
                            }
                            if (doc.equals("3")) {

                                doccounter--;
                                //  doccounter--; 
                                //                                doccounter--; 
                                System.out.println("****f  " + doc + " " + doccounter);
                                cell5 = rw5.createCell(doccounter++);
                                cell5.setCellStyle(style_border);
                                cell5.setCellValue(Math.round(percent) + "%");
                                cell6 = rw5.createCell(doccounter);
                                //                                   cell6.setCellStyle(style_border); 
                                //                                cell6.setCellValue(value0);
                                System.out.println("****b  " + doc + " " + doccounter);

                                doccounter--;
                            }
                            //                           else if(!doc.equals("4") && !docidarray.get(i).equals("4")){
                            //                                doccounter++; 
                            //                                 doccounter++; 
                            //                            System.out.println("****c  "+doc +" "+doccounter);
                            //                           }

                            doccounter++;
                        }

                    }

                }
                doccounter = 2;
                //               String getcbo= "select * from CBO where cboid='"+cboid+"'";
                //                      conn.rs2 = conn.state2.executeQuery(getcbo);
                //                      while(conn.rs2.next()){
                //                    
                //                            cell2=rw5.createCell(1);
                //                             cell2.setCellValue(conn.rs2.getString(2));
                //                          
                //                                   System.out.println("rowcount "+rowcount );
                //                                     
                //                      }

                //}

                System.out.println("aaaaaa   " + districtname + "__" + cboname + "____" + docname + "___"
                        + value1 + "__" + value0);

            }
            //}
            // end of while loop
            if (distval.equals("")) {
                //     totalvalue= countercopy+counter;
                System.out.println(countercopy + " counter " + counter + "  " + rowcount);
                distval = districtname;
                System.out.println(countercopy + " nnnn " + counter + " " + rowcount);

                if (counter > countercopy) {

                    shet1.addMergedRegion(new CellRangeAddress(countercopy, rowcount, 0, 0));
                    countercopy = rowcount;
                    //cell1.setCellValue(districtname);
                }

                System.out.println(countercopy + " nnn " + counter + " " + rowcount + "  " + distval);
            }
            // cell1.setCellValue(districtname);

            if (!distval.equals(districtname) && !distval.equals("")) {
                distval = districtname;
                //  cell1.setCellValue(districtname);    
                shet1.addMergedRegion(new CellRangeAddress(countercopy + 1, rowcount, 0, 0));
                countercopy = rowcount;

                //

                System.out.println(counter + "@@@@1 " + rowcount + "__" + countercopy);
                System.out.println(distval + "@@@@1 " + districtname);
            }
            System.out.println(counter + "@@@@ " + rowcount);
            //shet1.addMergedRegion(new CellRangeAddress(counter,rowcount,0,0));
            System.out.println(distval + "@@@@ " + districtname);

        } // end of for loop 

        //                      int totalvalue=countercopy+counter;
        // System.out.println(counter+" hhhh "+countercopy);
        //                      if(counter>countercopy){
        //                 shet1.addMergedRegion(new CellRangeAddress(countercopy,totalvalue-1,0,0));
        //               
        //                 countercopy=counter;
        //             }
        // System.out.println("aaaaaannnn   "+districtname+"__"+ cboname +"____"+ doc +"___"+value1 +"__"+value0 ); 

        // write it as an excel attachment
        ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
        wb.write(outByteStream);
        byte[] outArray = outByteStream.toByteArray();
        response.setContentType("application/ms-excel");
        response.setContentLength(outArray.length);
        response.setHeader("Expires:", "0"); // eliminates browser caching
        response.setHeader("Content-Disposition",
                "attachment; filename=CBO_FILING_TRACKER_REPORT_FOR_" + Year + ".xls");
        OutputStream outStream = response.getOutputStream();
        outStream.write(outArray);
        outStream.flush();
    } finally {
        //            out.close();
    }
}

From source file:FILING.childdetailsreport.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  w  w .ja  va2  s .c o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException {
    response.setContentType("text/html;charset=UTF-8");
    //        PrintWriter out = response.getWriter();
    try {
        dbConn conn = new dbConn("1");
        String District = "";
        District = request.getParameter("District");
        String Year = "";
        Year = request.getParameter("Year");
        String chw = "";
        String FirstName = "";
        String MiddleName = "";
        String Surname = "";
        String ovcid1 = "";
        String ovcid2 = "";
        int value0 = 0;
        int value1 = 0;
        String Districtid = "";
        String cboid = "";
        String doc = "";
        String docname = "";
        String cboname = "";
        String districtname = "";
        String chwval = "";
        String docid = "";
        //             ^^^^^^^^^^^^^CREATE STATIC AND WRITE STATIC DATA TO THE EXCELL^^^^^^^^^^^^
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet shet1 = wb.createSheet();
        int cbocount = 3;
        //%%%%%%%%%%%%%%%%HEADER FONTS AND COLORATION%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

        // style header with font color yello 

        HSSFFont font_header = wb.createFont();
        font_header.setFontHeightInPoints((short) 10);
        font_header.setFontName("Arial Black");
        font_header.setItalic(true);
        font_header.setBoldweight((short) 05);
        font_header.setColor(HSSFColor.BLACK.index);
        CellStyle style_header = wb.createCellStyle();
        style_header.setFont(font_header);
        style_header.setWrapText(true);
        style_header.setFillForegroundColor(HSSFColor.YELLOW.index);
        style_header.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style_header.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style_header.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style_header.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style_header.setAlignment(CellStyle.ALIGN_CENTER);
        style_header.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        // stylex with font color blue  and backgound grey
        HSSFCellStyle stylex = wb.createCellStyle();
        stylex.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
        stylex.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        HSSFFont fontx = wb.createFont();
        fontx.setColor(HSSFColor.DARK_BLUE.index);
        stylex.setFont(fontx);
        stylex.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        stylex.setBorderTop(HSSFCellStyle.BORDER_THIN);
        stylex.setBorderRight(HSSFCellStyle.BORDER_THIN);
        stylex.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        stylex.setAlignment(CellStyle.ALIGN_CENTER);

        // gold bg color -style
        HSSFFont font = wb.createFont();
        font.setFontHeightInPoints((short) 12);
        font.setFontName("Cambria");
        font.setItalic(true);
        font.setBoldweight((short) 02);
        font.setColor(HSSFColor.BLACK.index);
        CellStyle style = wb.createCellStyle();
        style.setFont(font);
        style.setWrapText(true);
        style.setFillForegroundColor(HSSFColor.GREY_40_PERCENT.index);
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style.setBorderLeft(HSSFCellStyle.BORDER_THIN);

        // for border with no font color
        CellStyle style_border = wb.createCellStyle();
        style_border.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style_border.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style_border.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style_border.setBorderLeft(HSSFCellStyle.BORDER_THIN);

        HSSFFont font1 = wb.createFont();
        font1.setFontHeightInPoints((short) 18);
        font1.setFontName("Cambria");
        font1.setBoldweight((short) 7);
        font1.setColor(HSSFColor.BLACK.index);

        CellStyle style_border1 = wb.createCellStyle();
        style_border1.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        style_border1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        style_border1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        style_border1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        style_border1.setFont(font);
        style_border1.setAlignment(CellStyle.ALIGN_CENTER);
        style_border1.setVerticalAlignment(CellStyle.ALIGN_LEFT);

        HSSFRow rw1 = shet1.createRow(1);
        rw1.setHeightInPoints(30);
        for (int y = 0; y < 11; ++y) {
            HSSFCell cell = rw1.createCell(y);
            cell.setCellStyle(stylex);

            if (y == 0) {
                cell.setCellValue("OVC DOCUMENT DETAILS REPORT");

            }
        }
        shet1.addMergedRegion(new CellRangeAddress(1, 1, 0, 11));

        shet1.setColumnWidth(0, 9000);
        shet1.setColumnWidth(1, 9000);
        shet1.setColumnWidth(2, 9000);
        shet1.setColumnWidth(3, 9000);
        shet1.setColumnWidth(4, 5000);
        shet1.setColumnWidth(5, 5000);
        shet1.setColumnWidth(6, 5000);
        shet1.setColumnWidth(7, 5000);
        shet1.setColumnWidth(8, 5000);
        shet1.setColumnWidth(9, 5000);
        shet1.setColumnWidth(10, 5000);
        shet1.setColumnWidth(11, 5000);
        shet1.setColumnWidth(12, 5000);
        shet1.setColumnWidth(13, 5000);

        //  Merge the cells
        //  shet1.addMergedRegion(new CellRangeAddress(1,1,1,3));

        HSSFRow rw4 = shet1.createRow(2);
        rw4.setHeightInPoints(50);
        HSSFRow rw6 = shet1.createRow(3);
        rw6.setHeightInPoints(25);
        //    rw4.setRowStyle(style);
        //    
        //  
        //    rw6.setRowStyle(style);
        // 

        // rw4.createCell(1).setCellValue("Number");
        HSSFCell cell1, cell0, cell2, cell3, cell4, cell5, cell6, cell7, cell8, cell9, cell10, cell11, cell12,
                cell13, cell14, cell15, cell16;
        // cells fo row 2 
        cell0 = rw4.createCell(0);
        cell1 = rw4.createCell(1);
        cell2 = rw4.createCell(2);

        cell4 = rw4.createCell(3);

        cell0.setCellValue("CBO");
        cell0.setCellStyle(style);

        cell1.setCellValue("CHW");
        cell1.setCellStyle(style);

        cell2.setCellValue("OVCID");
        cell2.setCellStyle(style);

        cell4.setCellValue("FULLNAME");
        cell4.setCellStyle(style);

        ArrayList docidarray = new ArrayList();
        int rowcount = 3;
        int doccounter = 3;
        int doccounter1 = 4;
        int columcounter = 3;
        String cboids = "";
        int mergecounter = 2;
        String getdocname = "select * from ovcdocuments WHERE DocumentName!=''";
        conn.rs3 = conn.state3.executeQuery(getdocname);
        while (conn.rs3.next()) {

            System.out.println(conn.rs3.getString(2));
            docname = conn.rs3.getString(2);
            cell3 = rw4.createCell(doccounter1);
            cell3.setCellValue(docname);
            cell3.setCellStyle(style);
            docidarray.add(conn.rs3.getString(1));
            doccounter1++;
        }

        System.out.println("lll " + doccounter1);
        int rowcounter = 4;
        int counter = 0;
        int countercopy = 3;
        int countercopy1 = 3;
        HSSFRow rw5 = null;

        String getcboCOUNT = "select * from CBO where DistrictID='" + District + "' Order by DistrictID ";
        conn.rs2 = conn.state2.executeQuery(getcboCOUNT);
        while (conn.rs2.next()) {
            counter++;
            System.out.println("bb b " + conn.rs2.getString(2));
            System.out.println("rowcount " + rowcount + " lll   " + counter + " rowcounter " + rowcounter);

            System.out.println("doccount " + doccounter);

            String getData = "select "
                    + "ovcfiling.value,Clientdetails.FirstName, Middlename,SurName,ovcfiling.OVCID"
                    + " , Clientdetails.Cbo,"
                    + "ovcfiling.ovcdocid,Clientdetails.District,Clientdetails.Volunteerid "
                    + " from ovcfiling,Clientdetails  " + "WHERE Clientdetails.District ='" + District
                    + "' and Clientdetails.Cbo='" + conn.rs2.getString(1) + "' "
                    + "and Clientdetails.OVCID = ovcfiling.ovcid and (Year='" + Year + "' OR Year='') "
                    + "group by Clientdetails.FirstName, Middlename,Surname,ovcfiling.OVCID,Clientdetails.Volunteerid,ovcfiling.value,ovcfiling.ovcdocid,Clientdetails.Cbo,Clientdetails.District  "
                    + "Order by  Clientdetails.Volunteerid,ovcfiling.OVCID,ovcfiling.ovcdocid";
            System.out.println("aaaaa  " + getData);
            conn.rs = conn.state.executeQuery(getData);
            while (conn.rs.next()) {

                value1 = conn.rs.getInt(1);
                FirstName = conn.rs.getString(2);
                MiddleName = conn.rs.getString(3);
                Surname = conn.rs.getString(4);
                ovcid1 = conn.rs.getString(5);
                //                String getcbo= "select * from CBO where CBOID='"+cboid+"' ";
                //                System.out.println("aaa "+getcbo);
                //                conn.rs_1= conn.state4.executeQuery(getcbo);
                //                while(conn.rs_1.next()){
                ////                   
                //                    cbocount++;
                //                cboname=conn.rs_1.getString("CBO");
                //                System.out.println("aaab  "+cboname);
                //                }
                cboname = conn.rs2.getString(2);
                cboid = conn.rs.getString(6);
                docid = conn.rs.getString(7);
                String getchw = "select * from CHW where CHWID='" + conn.rs.getString(9) + "' ";
                conn.rs3 = conn.state3.executeQuery(getchw);
                while (conn.rs3.next()) {
                    chw = conn.rs3.getString("FirstName") + " " + conn.rs3.getString("MiddleName") + " "
                            + conn.rs3.getString("Surname") + " " + conn.rs3.getString("CBOID");
                }

                // fro holding ovc id 

                // to create rows         
                if (docid.equals("1")) {
                    rw5 = shet1.createRow(rowcount);
                    rw5.setHeightInPoints(25);

                    for (int i = 2; i < doccounter1; i++) {
                        System.out.println("mm " + i);
                        cell5 = rw5.createCell(i);
                        cell5.setCellValue("");
                        cell5.setCellStyle(style_border1);

                    }
                    rowcount++;
                    cbocount++;
                }

                cell1 = rw5.createCell(0);
                cell1.setCellValue(cboname);
                cell1.setCellStyle(style_border1);
                cell1 = rw5.createCell(1);
                cell1.setCellValue(chw);
                cell1.setCellStyle(style_border1);
                cell1 = rw5.createCell(2);
                cell1.setCellValue(ovcid1);
                cell1.setCellStyle(style_border1);
                cell1 = rw5.createCell(3);
                cell1.setCellValue(FirstName + " " + MiddleName + " " + Surname);
                cell1.setCellStyle(style_border1);

                for (int i = 0; i < docidarray.size(); i++) {
                    System.out.println("hh " + docidarray.get(i));
                    if (rw5 == null) {
                        rw5 = shet1.createRow(rowcount);
                    }
                    if (docidarray.get(i).equals(docid)) {
                        int cellcount = i + 4;
                        cell2 = rw5.createCell(cellcount);
                        cell2.setCellValue(value1);
                        cell2.setCellStyle(style_border1);

                        //                    if( docid.equals("3") ) {
                        //                           System.out.println("am in2");
                        //                           System.out.println("****a  "+docid +" "+cellcount);
                        //                           cellcount++; 
                        //                           } 
                        System.out.println("****b  " + docid + " " + cellcount);
                    }
                }
                //                      cell3=rw5.createCell(2);
                //                      cell3.setCellValue(docid);
                //                      cell3.setCellStyle(style_border1);

                System.out.println(
                        FirstName + " " + ovcid1 + "  " + value1 + "___" + doccounter + "_____" + rowcount);
                if (docid.equals("10")) {
                    //     rowcount++;
                    doccounter = 2;
                }
                if (chwval.equals("")) {
                    chwval = chw;

                    System.out.println(countercopy + " nnnna " + rowcount);
                    //                                        shet1.addMergedRegion(new CellRangeAddress(countercopy,rowcount-1,0,0));
                    //                                        countercopy=rowcount; 
                    System.out.println(countercopy + " nnnnb " + rowcount + "  " + chwval);
                }

                if (!chwval.equals(chw) && !chwval.equals("")) {
                    chwval = chw;

                    System.out.println(countercopy + " nnna" + rowcount + "  " + chwval);

                    shet1.addMergedRegion(new CellRangeAddress(countercopy, rowcount - 2, 1, 1));
                    countercopy = rowcount - 1;
                    System.out.println(countercopy + " nnnb  " + rowcount + "  " + chwval);

                }
                String cboval = "";
                if (cboval.equals("")) {
                    cboval = cboname;

                    //                shet1.addMergedRegion(new CellRangeAddress(countercopy1,cbocount-1,0,0));
                    //                countercopy1=cbocount;

                }
                if (!cboval.equals(cboname) && !cboval.equals("")) {
                    cboval = cboname;

                    System.out.println(countercopy1 + " nnna" + cbocount + "  " + chwval);

                    shet1.addMergedRegion(new CellRangeAddress(countercopy1, cbocount - 2, 0, 0));
                    countercopy1 = cbocount - 1;
                    System.out.println(countercopy1 + " nnnb  " + rowcount + "  " + cboval);

                }
                //             
                //              if(monthval.equals("")){
                //              monthval= months;
                //              System.out.println("88"+monthval +"___"+months);
                //                System.out.println("88"+monthcopy1);
                //                System.out.println("88"+counter1);
                //                cell31.setCellValue(""+months+ " ("+conn.rs3.getInt(5)+")");
                //                shet2.addMergedRegion(new CellRangeAddress(monthcopy_1,counter1-1,1,1));
                //                monthcopy1=counter1;
                //            
                //            }
                //          if(!monthval.equals("") && !monthval.equals(months)){
                //                 monthval= months;
                //                System.out.println("!!!"+monthval +"___"+months);
                //                System.out.println("!!!"+monthcopy_1);
                //                System.out.println("!!!!"+counter1);
                ////                cell31.setCellValue(months);
                ////              shet1.addMergedRegion(new CellRangeAddress(monthcopy,counter-1,1,1));
                //                monthcopy_1=counter1;
                //               
                //            }

                //       if(rowcount>countercopy)  {      
                //       
                //         shet1.addMergedRegion(new CellRangeAddress(countercopy,rowcount-1,0,0));
                //                              countercopy=rowcount;
                //       }  
            }
            if (rowcount > countercopy) {
                shet1.addMergedRegion(new CellRangeAddress(countercopy, rowcount - 1, 1, 1));
                countercopy = rowcount;
            }
            if (cbocount > countercopy1) {
                shet1.addMergedRegion(new CellRangeAddress(countercopy1, cbocount - 1, 0, 0));
                countercopy1 = cbocount;
            }
            //}

            System.out.println("aaaaaa   " + districtname + "__" + cboname + "____" + docname + "___" + value1
                    + "__" + value0);

        }
        //   // end of while loop

        ByteArrayOutputStream outByteStream = new ByteArrayOutputStream();
        wb.write(outByteStream);
        byte[] outArray = outByteStream.toByteArray();
        response.setContentType("application/ms-excel");
        response.setContentLength(outArray.length);
        response.setHeader("Expires:", "0"); // eliminates browser caching
        response.setHeader("Content-Disposition", "attachment; filename=CBO_Details_Report_" + Year + ".xls");
        OutputStream outStream = response.getOutputStream();
        outStream.write(outArray);
        outStream.flush();
    } finally {
        //            out.close();
    }
}