Example usage for org.apache.poi.xssf.streaming SXSSFWorkbook write

List of usage examples for org.apache.poi.xssf.streaming SXSSFWorkbook write

Introduction

In this page you can find the example usage for org.apache.poi.xssf.streaming SXSSFWorkbook write.

Prototype

@Override
public void write(OutputStream stream) throws IOException 

Source Link

Document

Write out this workbook to an OutputStream.

Usage

From source file:org.eclipse.sw360.exporter.ExcelExporter.java

License:Open Source License

public InputStream makeExcelExport(List<T> documents) throws IOException, SW360Exception {
    final SXSSFWorkbook workbook = new SXSSFWorkbook();
    final ByteArrayInputStream stream;
    try {/*  w  w w .  j  a v  a  2  s  . c om*/
        SXSSFSheet sheet = workbook.createSheet("Data");

        /** Adding styles to cells */
        CellStyle cellStyle = createCellStyle(workbook);
        CellStyle headerStyle = createHeaderStyle(workbook);

        /** Create header row */
        Row headerRow = sheet.createRow(0);
        List<String> headerNames = helper.getHeaders();
        fillRow(headerRow, headerNames, headerStyle);

        /** Create data rows */
        fillValues(sheet, documents, cellStyle);

        // removed autosizing of spreadsheet columns for performance reasons

        /** Copy the streams */
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        workbook.write(out);
        stream = new ByteArrayInputStream(out.toByteArray());
    } finally {
        workbook.dispose();
    }
    return stream;
}

From source file:org.jboss.dashboard.displayer.table.ExportTool.java

License:Apache License

public InputStream exportExcel(Table table) {
    // TODO?: Excel 2010 limits: 1,048,576 rows by 16,384 columns; row width 255 characters
    if (table == null)
        throw new IllegalArgumentException("Null table specified!");
    int columnCount = table.getColumnCount();
    int rowCount = table.getRowCount() + 1; //Include header row
    int row = 0;/*from   w w  w  . j av  a 2s  . co  m*/

    SXSSFWorkbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
    Map<String, CellStyle> styles = createStyles(wb);
    Sheet sh = wb.createSheet("Sheet 1");

    // General setup
    sh.setDisplayGridlines(true);
    sh.setPrintGridlines(false);
    sh.setFitToPage(true);
    sh.setHorizontallyCenter(true);
    PrintSetup printSetup = sh.getPrintSetup();
    printSetup.setLandscape(true);

    // Create header
    Row header = sh.createRow(row++);
    header.setHeightInPoints(20f);
    for (int i = 0; i < columnCount; i++) {
        Cell cell = header.createCell(i);
        cell.setCellStyle(styles.get("header"));
        cell.setCellValue(table.getColumnName(i));
    }

    // Create data rows
    for (; row < rowCount; row++) {
        Row _row = sh.createRow(row);
        for (int cellnum = 0; cellnum < columnCount; cellnum++) {
            Cell cell = _row.createCell(cellnum);
            Object value = table.getValueAt(row - 1, cellnum);
            if (value instanceof Short || value instanceof Long || value instanceof Integer
                    || value instanceof BigInteger) {
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                cell.setCellStyle(styles.get("integer_number_cell"));
                cell.setCellValue(((Number) value).doubleValue());
            } else if (value instanceof Float || value instanceof Double || value instanceof BigDecimal) {
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                cell.setCellStyle(styles.get("decimal_number_cell"));
                cell.setCellValue(((Number) value).doubleValue());
            } else if (value instanceof Date) {
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellStyle(styles.get("date_cell"));
                cell.setCellValue((Date) value);
            } else if (value instanceof Interval) {
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellStyle(styles.get("text_cell"));
                cell.setCellValue(((Interval) value).getDescription(LocaleManager.currentLocale()));
            } else if (value == null) {
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellStyle(styles.get("text_cell"));
                cell.setCellValue("");
            } else {
                cell.setCellType(Cell.CELL_TYPE_STRING);
                cell.setCellStyle(styles.get("text_cell"));
                cell.setCellValue(value.toString());
            }
        }
    }

    // Adjust column size
    for (int i = 0; i < columnCount; i++) {
        sh.autoSizeColumn(i);
    }

    ByteArrayInputStream bis = null;
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        wb.write(bos);
        bis = new ByteArrayInputStream(bos.toByteArray());
        bos.close();
    } catch (IOException e) {
        log.error("Data export error: ", e);
    }

    // Dispose of temporary files backing this workbook on disk
    if (!wb.dispose())
        log.warn("Could not dispose of temporary file associated to data export!");

    return bis;
}

From source file:org.ohdsi.whiteRabbit.scan.SourceDataScan.java

License:Apache License

private void generateReport(Map<String, List<FieldInfo>> tableToFieldInfos, String filename) {
    System.out.println("Generating scan report");
    removeEmptyTables(tableToFieldInfos);
    List<String> tables = new ArrayList<String>(tableToFieldInfos.keySet());
    Collections.sort(tables);//w w  w .  j a  va2  s .c  o m

    SXSSFWorkbook workbook = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk

    // Create overview sheet
    Sheet sheet = workbook.createSheet("Overview");
    if (!scanValues) {
        addRow(sheet, "Table", "Field", "Type", "N rows");
        for (String table : tables) {
            for (FieldInfo fieldInfo : tableToFieldInfos.get(table))
                addRow(sheet, table, fieldInfo.name, fieldInfo.getTypeDescription(),
                        Long.valueOf(fieldInfo.rowCount));
            addRow(sheet, "");
        }
    } else {
        addRow(sheet, "Table", "Field", "Type", "Max length", "N rows", "N rows checked", "Fraction empty");
        for (String table : tables) {
            for (FieldInfo fieldInfo : tableToFieldInfos.get(table))
                addRow(sheet, table, fieldInfo.name, fieldInfo.getTypeDescription(),
                        Integer.valueOf(fieldInfo.maxLength), Long.valueOf(fieldInfo.rowCount),
                        Long.valueOf(fieldInfo.nProcessed), fieldInfo.getFractionEmpty());
            addRow(sheet, "");
        }

        // Create per table sheets
        for (String table : tables) {
            sheet = workbook.createSheet(table);
            List<FieldInfo> fieldInfos = tableToFieldInfos.get(table);
            List<List<Pair<String, Integer>>> valueCounts = new ArrayList<List<Pair<String, Integer>>>();
            Object[] header = new Object[fieldInfos.size() * 2];
            int maxCount = 0;
            for (int i = 0; i < fieldInfos.size(); i++) {
                FieldInfo fieldInfo = fieldInfos.get(i);
                header[i * 2] = fieldInfo.name;
                if (fieldInfo.isFreeText)
                    header[(i * 2) + 1] = "Word count";
                else
                    header[(i * 2) + 1] = "Frequency";
                List<Pair<String, Integer>> counts = fieldInfo.getSortedValuesWithoutSmallValues();
                valueCounts.add(counts);
                if (counts.size() > maxCount)
                    maxCount = counts.size();
            }
            addRow(sheet, header);
            for (int i = 0; i < maxCount; i++) {
                Object[] row = new Object[fieldInfos.size() * 2];
                for (int j = 0; j < fieldInfos.size(); j++) {
                    List<Pair<String, Integer>> counts = valueCounts.get(j);
                    if (counts.size() > i) {
                        row[j * 2] = counts.get(i).getItem1();
                        row[(j * 2) + 1] = counts.get(i).getItem2() == -1 ? "" : counts.get(i).getItem2();
                    } else {
                        row[j * 2] = "";
                        row[(j * 2) + 1] = "";
                    }
                }
                addRow(sheet, row);
            }
            // Save some memory by derefencing tables already included in the report:
            tableToFieldInfos.remove(table);
        }
    }

    try {
        FileOutputStream out = new FileOutputStream(new File(filename));
        workbook.write(out);
        out.close();
        StringUtilities.outputWithTime("Scan report generated: " + filename);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    }
}

From source file:org.ramadda.data.docs.TabularOutputHandler.java

License:Apache License

/**
 * _more_/*www .  j a va  2 s.  co  m*/
 *
 * @param request _more_
 * @param service _more_
 * @param input _more_
 * @param args _more_
 *
 *
 * @return _more_
 * @throws Exception _more_
 */
public boolean extractSheet(Request request, Service service, ServiceInput input, List args) throws Exception {
    Entry entry = null;
    for (Entry e : input.getEntries()) {
        if (isTabular(e)) {
            entry = e;

            break;
        }
    }
    if (entry == null) {
        throw new IllegalArgumentException("No tabular entry found");
    }

    HashSet<Integer> sheetsToShow = getSheetsToShow((String) args.get(0));

    final SXSSFWorkbook wb = new SXSSFWorkbook(100);
    //        final Workbook   wb           = new XSSFWorkbook();

    String name = getStorageManager().getFileTail(entry);
    if (!Utils.stringDefined(name)) {
        name = entry.getName();
    }
    name = IOUtil.stripExtension(name);

    File newFile = new File(IOUtil.joinDir(input.getProcessDir(), name + ".xlsx"));

    TabularVisitor visitor = new TabularVisitor() {
        public boolean visit(TextReader info, String sheetName, List<List<Object>> rows) {
            sheetName = sheetName.replaceAll("[/]+", "-");
            Sheet sheet = wb.createSheet(sheetName);
            int rowCnt = 0;
            for (List<Object> cols : rows) {
                Row row = sheet.createRow(rowCnt++);
                for (int colIdx = 0; colIdx < cols.size(); colIdx++) {
                    Object col = cols.get(colIdx);
                    Cell cell = row.createCell(colIdx);
                    if (col instanceof Double) {
                        cell.setCellValue(((Double) col).doubleValue());
                    } else if (col instanceof Date) {
                        cell.setCellValue((Date) col);
                    } else if (col instanceof Boolean) {
                        cell.setCellValue(((Boolean) col).booleanValue());
                    } else {
                        cell.setCellValue(col.toString());
                    }
                }
            }

            return true;
        }
    };

    TabularVisitInfo visitInfo = new TabularVisitInfo(request, entry, getSkipRows(request, entry),
            getRowCount(request, entry, Integer.MAX_VALUE), sheetsToShow);

    TextReader info = new TextReader();
    info.setSkip(getSkipRows(request, entry));
    info.setMaxRows(getRowCount(request, entry, MAX_ROWS));
    //        http:://localhost:8080/repository/entry/show?entryid=740ae258-805d-4a1f-935d-289d0a6e5519&output=media_tabular_extractsheet&serviceform=true&execute=Execute

    visit(request, entry, info, visitor);

    FileOutputStream fileOut = new FileOutputStream(newFile);
    wb.write(fileOut);
    fileOut.close();
    wb.dispose();

    return true;

}

From source file:org.ramadda.plugins.media.TabularOutputHandler.java

License:Open Source License

/**
 * _more_/*from w w w  .j  a v  a  2s .c o  m*/
 *
 * @param request _more_
 * @param service _more_
 * @param input _more_
 * @param args _more_
 *
 *
 * @return _more_
 * @throws Exception _more_
 */
public boolean extractSheet(Request request, Service service, ServiceInput input, List args) throws Exception {
    Entry entry = null;
    for (Entry e : input.getEntries()) {
        if (isTabular(e)) {
            entry = e;

            break;
        }
    }
    if (entry == null) {
        throw new IllegalArgumentException("No tabular entry found");
    }

    HashSet<Integer> sheetsToShow = getSheetsToShow((String) args.get(0));

    final SXSSFWorkbook wb = new SXSSFWorkbook(100);
    //        final Workbook   wb           = new XSSFWorkbook();

    String name = getStorageManager().getFileTail(entry);
    if (!Utils.stringDefined(name)) {
        name = entry.getName();
    }
    name = IOUtil.stripExtension(name);

    File newFile = new File(IOUtil.joinDir(input.getProcessDir(), name + ".xlsx"));

    TabularVisitor visitor = new TabularVisitor() {
        public boolean visit(Visitor info, String sheetName, List<List<Object>> rows) {
            sheetName = sheetName.replaceAll("[/]+", "-");
            Sheet sheet = wb.createSheet(sheetName);
            int rowCnt = 0;
            for (List<Object> cols : rows) {
                Row row = sheet.createRow(rowCnt++);
                for (int colIdx = 0; colIdx < cols.size(); colIdx++) {
                    Object col = cols.get(colIdx);
                    Cell cell = row.createCell(colIdx);
                    if (col instanceof Double) {
                        cell.setCellValue(((Double) col).doubleValue());
                    } else if (col instanceof Date) {
                        cell.setCellValue((Date) col);
                    } else if (col instanceof Boolean) {
                        cell.setCellValue(((Boolean) col).booleanValue());
                    } else {
                        cell.setCellValue(col.toString());
                    }
                }
            }

            return true;
        }
    };

    TabularVisitInfo visitInfo = new TabularVisitInfo(request, entry, getSkipRows(request, entry),
            getRowCount(request, entry, Integer.MAX_VALUE), sheetsToShow);

    Visitor info = new Visitor();
    info.setSkip(getSkipRows(request, entry));
    info.setMaxRows(getRowCount(request, entry, MAX_ROWS));
    //        http:://localhost:8080/repository/entry/show?entryid=740ae258-805d-4a1f-935d-289d0a6e5519&output=media_tabular_extractsheet&serviceform=true&execute=Execute

    visit(request, entry, info, visitor);

    FileOutputStream fileOut = new FileOutputStream(newFile);
    wb.write(fileOut);
    fileOut.close();
    wb.dispose();

    return true;

}

From source file:org.riflemansd.businessprofit.excel.ExcelExamplePOI.java

License:Open Source License

public static void main(String[] args) throws Throwable {
    SXSSFWorkbook wb = new SXSSFWorkbook(1000); // keep 100 rows in memory, exceeding rows will be flushed to disk

    if (wb.getNumberOfSheets() == 0) {
        wb.createSheet("MySheet");
    }//  w  w  w.j av a 2s.c o m
    Sheet sh = wb.getSheetAt(0);
    Row row = sh.createRow(3);

    for (int i = 0; i < 10; i++) {
        Cell cell = row.createCell(i);
        //String address = new CellReference(cell).formatAsString();
        cell.setCellValue("? " + i);
        //row.setHeightInPoints(50);
        //sh.setColumnWidth(5, 1200); //4, 33 pixels
        wb.getSheetAt(0).autoSizeColumn(i);
    }

    FileOutputStream out = new FileOutputStream("test.xlsx");
    wb.write(out);
    out.close();

    // dispose of temporary files backing this workbook on disk
    wb.dispose();

    Desktop.getDesktop().open(new File("test.xlsx"));
}

From source file:poi.xssf.streaming.examples.Outlining.java

License:Apache License

private void collapseRow() throws Exception {
    SXSSFWorkbook wb2 = new SXSSFWorkbook(100);
    SXSSFSheet sheet2 = (SXSSFSheet) wb2.createSheet("new sheet");

    int rowCount = 20;
    for (int i = 0; i < rowCount; i++) {
        sheet2.createRow(i);//from   w w w . ja va2 s  .com
    }

    sheet2.groupRow(4, 9);
    sheet2.groupRow(11, 19);

    sheet2.setRowGroupCollapsed(4, true);

    FileOutputStream fileOut = new FileOutputStream("outlining_collapsed.xlsx");
    wb2.write(fileOut);
    fileOut.close();
    wb2.dispose();
}

From source file:reports.notReached.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, SQLException, InvalidFormatException {
    session = request.getSession();/*ww w .ja  va  2s  . c  o m*/
    dbConn conn = new dbConn();

    position = 1;

    String reportHeader[] = ("COUNTY NAME ,PARTNER NAME,DISTRICT NAME, DIC NAME, GROUP NAME,CLIENT FULL NAME ,"
            + " CCC NO. , MOBILE NUMBER , GENDER , DATE OF BIRTH , MARITAL STATUS , EMPLOYMENT STATUS ,"
            + "EDUCATION LEVEL , ART STATUS , SERVICE PROVIDER NAME , HEALTH FACILITY, LESSONS ATTENDED,AGE BRACKET, Knowledge of HIV Status,"
            + "Partner HIV Testing,Child HIV Testing,Discordance,HIV Disclosure,Risk Factor/Reduction,Condom Use,"
            + "Alcohol and Substance Abuse,Adherence,STIs,Family Planning,PMTCT,TB").split(",");

    //    COPY FILE TO BE WRITTEN TO 
    Path original = Paths.get(getServletContext().getRealPath("/NOT_ACHIEVED_TEMPLATE.xlsm")); //original file
    Path destination = Paths.get(getServletContext().getRealPath("/NOT_ACHIEVED_TEMPLATE_1.xlsm")); //new file
    System.out.println("origin :  " + original + " destination    :  " + destination);
    try {
        Files.copy(original, destination, StandardCopyOption.REPLACE_EXISTING);
        System.out.println("file copied----------------");
    } catch (IOException x) {
        //catch all for IO problems
        System.out.println("fine not copied");
    }

    String allpath = getServletContext().getRealPath("/NOT_ACHIEVED_TEMPLATE_1.xlsm");

    //            ^^^^^^^^^^^^^CREATE STATIC AND WRITE STATIC DATA TO THE EXCELL^^^^^^^^^^^^
    XSSFWorkbook wb1;
    OPCPackage pkg = OPCPackage.open(allpath);

    wb1 = new XSSFWorkbook(pkg);

    SXSSFWorkbook wb = new SXSSFWorkbook(wb1, 100);

    //            ^^^^^^^^^^^^^CREATE STATIC AND WRITE STATIC DATA TO THE EXCELL^^^^^^^^^^^^
    //   HSSFWorkbook wb=new HSSFWorkbook();
    Sheet shet1 = wb.getSheet("Sheet1");
    Font font = wb.createFont();
    font.setFontHeightInPoints((short) 18);
    font.setFontName("Arial Black");
    font.setColor((short) 0000);
    CellStyle style = wb.createCellStyle();
    style.setFont(font);
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
    Font font2 = wb.createFont();
    font2.setFontName("Arial Black");
    font2.setColor((short) 0000);
    CellStyle style2 = wb.createCellStyle();
    style2.setFont(font2);

    CellStyle stborder = wb.createCellStyle();
    stborder.setBorderTop(HSSFCellStyle.BORDER_THIN);
    stborder.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    stborder.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    stborder.setBorderRight(HSSFCellStyle.BORDER_THIN);
    stborder.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    for (int i = 0; i <= reportHeader.length; i++) {
        shet1.setColumnWidth(i, 4000);
    }

    CellStyle styleBorder = wb.createCellStyle();
    styleBorder.setBorderTop(HSSFCellStyle.BORDER_THIN);
    styleBorder.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    styleBorder.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    styleBorder.setBorderRight(HSSFCellStyle.BORDER_THIN);
    styleBorder.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    CellStyle stylex = wb.createCellStyle();
    stylex.setFillForegroundColor(HSSFColor.LIME.index);
    stylex.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    stylex.setBorderTop(HSSFCellStyle.BORDER_THIN);
    stylex.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    stylex.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    stylex.setBorderRight(HSSFCellStyle.BORDER_THIN);
    stylex.setAlignment(HSSFCellStyle.ALIGN_CENTER);

    Font fontx = wb.createFont();
    fontx.setColor(HSSFColor.DARK_BLUE.index);
    stylex.setFont(fontx);
    stylex.setWrapText(true);

    Cell cell;
    Row rw0 = shet1.createRow(0);
    rw0.setHeightInPoints(30);
    rw0.setRowStyle(style2);

    for (int i = 0; i <= (reportHeader.length - 1); i++) {
        cell = rw0.createCell(i);
        cell.setCellValue(reportHeader[i]);
        cell.setCellStyle(stylex);
    }

    String getClients = "SELECT county.county_name,partner.partner_name,district.district_name,dic.dic_name,"
            + "groups.group_name,personal_information.fname,personal_information.mname,personal_information.lname,"
            + "personal_information.ccc_no,personal_information.mobile_no, personal_information.gender,"
            + "personal_information.dob,marital_status.name,employment_status.name,education_levels.name,"
            + "art_status.name,"
            + "service_provider.fname,service_provider.mname,service_provider.lname,health_facility.hf_name, "
            + "personal_information.lessons_attended," + "CASE"
            + "      WHEN (DATE_FORMAT( NOW( ) , '%Y' ) - DATE_FORMAT( personal_information.dob, '%Y' )-( DATE_FORMAT( NOW( ),'YYYY-%mm-%dd' )< DATE_FORMAT( personal_information.dob, 'YYYY-%mm-%dd' ) )) BETWEEN 0 AND 9 THEN '0-9'"
            + "      WHEN (DATE_FORMAT( NOW( ) , '%Y' ) - DATE_FORMAT( personal_information.dob, '%Y' )-( DATE_FORMAT( NOW( ),'YYYY-%mm-%dd' )< DATE_FORMAT( personal_information.dob, 'YYYY-%mm-%dd' ) )) BETWEEN 10 AND 14 THEN '10-14'"
            + "      WHEN (DATE_FORMAT( NOW( ) , '%Y' ) - DATE_FORMAT( personal_information.dob, '%Y' )-( DATE_FORMAT( NOW( ),'YYYY-%mm-%dd' )< DATE_FORMAT( personal_information.dob, 'YYYY-%mm-%dd' ) )) BETWEEN 15 AND 19 THEN '15-19'"
            + "      WHEN (DATE_FORMAT( NOW( ) , '%Y' ) - DATE_FORMAT( personal_information.dob, '%Y' )-( DATE_FORMAT( NOW( ),'YYYY-%mm-%dd' )< DATE_FORMAT( personal_information.dob, 'YYYY-%mm-%dd' ) )) BETWEEN 20 AND 24 THEN '20-24'"
            + "      WHEN (DATE_FORMAT( NOW( ) , '%Y' ) - DATE_FORMAT( personal_information.dob, '%Y' )-( DATE_FORMAT( NOW( ),'YYYY-%mm-%dd' )< DATE_FORMAT( personal_information.dob, 'YYYY-%mm-%dd' ) )) BETWEEN 25 AND 49 THEN '25-49'"
            + "      WHEN (DATE_FORMAT( NOW( ) , '%Y' ) - DATE_FORMAT( personal_information.dob, '%Y' )-( DATE_FORMAT( NOW( ),'YYYY-%mm-%dd' )< DATE_FORMAT( personal_information.dob, 'YYYY-%mm-%dd' ) )) >49 THEN '50 and above'"
            + " ELSE 'NO DATE OF BIRTH'" + "   END AS AGEBRACKET," + "CASE "
            + "when personal_information.gender LIKE 'Female' THEN 'F' "
            + "when personal_information.gender LIKE 'Male' THEN 'M' " + "ELSE 'NO SEX' "
            + "END AS SEX,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13 " + " FROM personal_information "
            + " LEFT JOIN groups ON personal_information.group_id=groups.group_id "
            + " LEFT JOIN dic ON personal_information.dic_id=dic.dic_id "
            + " LEFT JOIN service_provider ON personal_information.provider_id=service_provider.provider_id "
            + " LEFT JOIN health_facility ON personal_information.hf_id=health_facility.hf_id "
            + " LEFT JOIN district ON personal_information.district_id=district.district_id "

            + " LEFT JOIN marital_status ON personal_information.marital_status=marital_status.id "
            + " LEFT JOIN employment_status ON personal_information.employment_status=employment_status.id "
            + " LEFT JOIN education_levels ON personal_information.education_level=education_levels.id "
            + " LEFT JOIN art_status ON personal_information.art_status=art_status.id "
            + " LEFT JOIN register ON personal_information.client_id=register.client_id "

            + " LEFT JOIN partner ON personal_information.partner_id=partner.partner_id "
            + " LEFT JOIN county ON district.county_id=county.county_id "

            + " WHERE (personal_information.completionmonth=0 || personal_information.completionyear=0) "
            + " ORDER BY partner.partner_name,county.county_name,district.district_name,dic.dic_name,"
            + "groups.group_name";
    System.out.println("query is : " + getClients);
    conn.rs = conn.st.executeQuery(getClients);
    while (conn.rs.next()) {
        //     ADD THE DATA TO EXCEL HERE 
        groupName = DICName = districtName = partnerName = countyName = agebracket = lessons_attended = year = "";
        clientFname = clientMname = clientLname = ccc_no = mobile_no = gender = dob = marital_status = "";
        location = employment_status = education_level = under_18 = ovc_children = hiv_year = art_status = "";
        registration_date = approved_by = designation = approval_date = "";
        SPFname = SPMname = SPLname = SPFullName = healthFacility = "";
        s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = s10 = s11 = s12 = s13 = "";
        if (conn.rs.getString(1) != null) {
            countyName = conn.rs.getString(1);
        }
        if (conn.rs.getString(2) != null) {
            partnerName = conn.rs.getString(2);
        }
        if (conn.rs.getString(3) != null) {
            districtName = conn.rs.getString(3);
        }
        if (conn.rs.getString(4) != null) {
            DICName = conn.rs.getString(4);
        } else {
            DICName = "NO DIC";
        }

        if (conn.rs.getString(5) != null) {
            groupName = conn.rs.getString(5);
        } else {
            groupName = "Individual";
        }

        if (conn.rs.getString(6) != null) {
            clientFname = conn.rs.getString(6);
        }
        if (conn.rs.getString(7) != null) {
            clientMname = conn.rs.getString(7);
        }
        if (conn.rs.getString(8) != null) {
            clientLname = conn.rs.getString(8);
        }
        if (conn.rs.getString(9) != null) {
            ccc_no = conn.rs.getString(9);
        }
        if (conn.rs.getString(10) != null) {
            mobile_no = conn.rs.getString(10);
        }
        if (conn.rs.getString(11) != null) {
            gender = conn.rs.getString(11);
        }
        if (conn.rs.getString(12) != null) {
            dob = conn.rs.getString(12);
        }
        if (conn.rs.getString(13) != null) {
            marital_status = conn.rs.getString(13);
        }
        if (conn.rs.getString(14) != null) {
            employment_status = conn.rs.getString(14);
        }
        if (conn.rs.getString(15) != null) {
            education_level = conn.rs.getString(15);
        }
        if (conn.rs.getString(16) != null) {
            art_status = conn.rs.getString(16);
        }
        if (conn.rs.getString(17) != null) {
            SPFname = conn.rs.getString(17);
        }
        if (conn.rs.getString(18) != null) {
            SPMname = conn.rs.getString(18);
        }
        if (conn.rs.getString(19) != null) {
            SPLname = conn.rs.getString(19);
        }
        if (conn.rs.getString(20) != null) {
            healthFacility = conn.rs.getString(20);
        }
        if (conn.rs.getString(21) != null) {
            lessons_attended = conn.rs.getString(21);
        }
        if (conn.rs.getString(22) != null) {
            agebracket = conn.rs.getString(22);
        }
        if (conn.rs.getString(23) != null) {
            gender = conn.rs.getString(23);
        }

        if (conn.rs.getString(24) != null) {
            s1 = conn.rs.getString(24);
        }
        if (conn.rs.getString(25) != null) {
            s2 = conn.rs.getString(25);
        }
        if (conn.rs.getString(26) != null) {
            s3 = conn.rs.getString(26);
        }
        if (conn.rs.getString(27) != null) {
            s4 = conn.rs.getString(27);
        }
        if (conn.rs.getString(28) != null) {
            s5 = conn.rs.getString(28);
        }
        if (conn.rs.getString(29) != null) {
            s6 = conn.rs.getString(29);
        }
        if (conn.rs.getString(30) != null) {
            s7 = conn.rs.getString(30);
        }
        if (conn.rs.getString(31) != null) {
            s8 = conn.rs.getString(31);
        }
        if (conn.rs.getString(32) != null) {
            s9 = conn.rs.getString(32);
        }
        if (conn.rs.getString(33) != null) {
            s10 = conn.rs.getString(33);
        }
        if (conn.rs.getString(34) != null) {
            s11 = conn.rs.getString(34);
        }
        if (conn.rs.getString(35) != null) {
            s12 = conn.rs.getString(35);
        }
        if (conn.rs.getString(36) != null) {
            s13 = conn.rs.getString(36);
        }

        if (s1.equals("5")) {
            s1 = "";
        }
        if (s1.equals("2")) {
            s1 = "0";
        }
        if (s2.equals("5")) {
            s2 = "";
        }
        if (s2.equals("2")) {
            s2 = "0";
        }
        if (s3.equals("5")) {
            s3 = "";
        }
        if (s3.equals("2")) {
            s3 = "0";
        }
        if (s4.equals("5")) {
            s4 = "";
        }
        if (s4.equals("2")) {
            s4 = "0";
        }
        if (s5.equals("5")) {
            s5 = "";
        }
        if (s5.equals("2")) {
            s5 = "0";
        }
        if (s6.equals("5")) {
            s6 = "";
        }
        if (s6.equals("2")) {
            s6 = "0";
        }
        if (s7.equals("5")) {
            s7 = "";
        }
        if (s7.equals("2")) {
            s7 = "0";
        }
        if (s8.equals("5")) {
            s8 = "";
        }
        if (s8.equals("2")) {
            s8 = "0";
        }
        if (s9.equals("5")) {
            s9 = "";
        }
        if (s9.equals("2")) {
            s9 = "0";
        }
        if (s10.equals("5")) {
            s10 = "";
        }
        if (s10.equals("2")) {
            s10 = "0";
        }
        if (s11.equals("5")) {
            s11 = "";
        }
        if (s11.equals("2")) {
            s11 = "0";
        }
        if (s12.equals("5")) {
            s12 = "";
        }
        if (s12.equals("2")) {
            s12 = "0";
        }
        if (s13.equals("5")) {
            s13 = "";
        }
        if (s13.equals("2")) {
            s13 = "0";
        }

        if (clientMname.equals(clientLname)) {
            clientMname = "";
        }

        if (SPMname.equals(SPLname)) {
            SPMname = "";
        }

        SPFullName = SPFname + " " + SPMname + " " + SPLname;
        clientFullName = clientFname + " " + clientMname + " " + clientLname;

        String rawData[] = (countyName + "," + partnerName + "," + districtName + "," + DICName + ","
                + groupName + "," + clientFullName + "," + ccc_no + "," + mobile_no + "," + gender + "," + dob
                + "," + marital_status + "," + employment_status + "," + education_level + "," + art_status
                + "," + SPFullName + "," + healthFacility + "," + lessons_attended + "," + agebracket + "," + s1
                + "," + s2 + "," + s3 + "," + s4 + "," + s5 + "," + s6 + "," + s7 + "," + s8 + "," + s9 + ","
                + s10 + "," + s11 + "," + s12 + "," + s13).split(",");

        Row rw1 = shet1.createRow(position);
        rw1.setHeightInPoints(25);
        rw1.setRowStyle(style2);

        for (int i = 0; i <= (reportHeader.length - 1); i++) {
            cell = rw1.createCell(i);
            cell.setCellStyle(styleBorder);
        }

        for (int i = 0; i <= (rawData.length - 1); i++) {
            cell = rw1.getCell(i);
            cell.setCellValue(rawData[i]);
        }

        position++;
        System.out.println("at position : " + position);
    }

    IdGenerator CRT = new IdGenerator();
    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=PWP_CLIENTS_NOT_REACHED_REPORT_CREATED_ON_" + CRT.timestamp() + ".xlsm");
    OutputStream outStream = response.getOutputStream();
    outStream.write(outArray);
    outStream.flush();

    pkg.close();
}