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

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

Introduction

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

Prototype

@Override
public void setDisplayRowColHeadings(boolean show) 

Source Link

Document

Sets whether the RowColHeadings are shown in a viewer.

Usage

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

License:Apache License

public static void copySheetStyle(HSSFWorkbook destwb, HSSFSheet dest, HSSFWorkbook srcwb, HSSFSheet src) {
    if (src == null || dest == null)
        return;//  ww w  .j av  a2  s  .c om

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

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

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

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

From source file:org.openmrs.module.tracnetreporting.impl.TracNetIndicatorServiceImpl.java

License:Open Source License

/**
 * Exports data to the Excel File//from   w  w w.j  a  v a 2 s.  c  om
 * 
 * @throws IOException
 * @see org.openmrs.module.tracnetreporting.service.TracNetIndicatorService#exportDataToExcelFile(java.util.Map)
 */
@SuppressWarnings({ "deprecation", "unchecked" })
public void exportDataToExcelFile(HttpServletRequest request, HttpServletResponse response,
        Map<String, Integer> indicatorsList, String filename, String title, String startDate, String endDate)
        throws IOException {

    HSSFWorkbook workbook = new HSSFWorkbook();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
    HSSFSheet sheet = workbook.createSheet(title);
    int count = 0;
    sheet.setDisplayRowColHeadings(true);

    // Setting Style
    HSSFFont font = workbook.createFont();
    HSSFCellStyle cellStyle = workbook.createCellStyle();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFFont.COLOR_RED);
    cellStyle.setFillForegroundColor((short) 0xA);

    // Title
    HSSFRow row = sheet.createRow((short) 0);
    HSSFCell cell = row.createCell((short) 0);
    cell.setCellValue("");
    row.setRowStyle(cellStyle);
    row.createCell((short) 1).setCellValue("" + title + "(Between " + startDate + " and " + endDate + ")");

    // Headers
    row = sheet.createRow((short) 2);
    row.createCell((short) 0).setCellValue("#");
    row.createCell((short) 1).setCellValue("INDICATOR NAME");
    row.createCell((short) 2).setCellValue("INDICATOR");

    Log log = LogFactory.getLog(this.getClass());
    log.info("00000000000000000000000000000000000000000000000000000000000000000");
    // log.info();

    List<String> indicator_msg = null;

    indicator_msg = (ArrayList<String>) request.getSession().getAttribute(request.getParameter("id") + "_msg");

    for (String indicator : indicatorsList.keySet()) {
        count++;
        row = sheet.createRow((short) count + 3);
        row.createCell((short) 0).setCellValue(indicator.toString().substring(4));
        row.createCell((short) 1).setCellValue(indicator_msg.get(count - 1));// .substring(3)
        row.createCell((short) 2).setCellValue(indicatorsList.get(indicator).toString());
        // log.info("========================>>> "+count);
    }
    OutputStream outputStream = response.getOutputStream();
    workbook.write(outputStream);
    outputStream.flush();
    outputStream.close();
}

From source file:org.openmrs.module.tracnetreporting.impl.TracNetIndicatorServiceImpl.java

License:Open Source License

/**
 * Exports data to the Excel File/*from  w  w w.  ja v a2  s . c  o m*/
 * 
 * @throws IOException
 * @see org.openmrs.module.tracnetreporting.service.TracNetIndicatorService#exportDataToExcelFile(java.util.Map)
 */

@SuppressWarnings("deprecation")
@Override
public void exportPatientsListToExcelFile(HttpServletRequest request, HttpServletResponse response,
        List<Person> patientsList, String filename, String title, String startDate, String endDate)
        throws IOException {

    log.info("exporttttttttttttttttttttttttttttttttttttt" + patientsList);

    Session session = getSessionFactory().getCurrentSession();
    HSSFWorkbook workbook = new HSSFWorkbook();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
    HSSFSheet sheet = workbook.createSheet(title);
    int count = 0;
    sheet.setDisplayRowColHeadings(true);

    // Setting Style
    HSSFFont font = workbook.createFont();
    HSSFCellStyle cellStyle = workbook.createCellStyle();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFFont.COLOR_RED);
    cellStyle.setFillForegroundColor((short) 0xA);

    // Title
    HSSFRow row = sheet.createRow((short) 0);
    HSSFCell cell = row.createCell((short) 0);
    cell.setCellValue("");
    row.setRowStyle(cellStyle);
    row.createCell((short) 1).setCellValue("" + title + "(Between " + startDate + " and " + endDate + ")");

    // Headers
    row = sheet.createRow((short) 2);
    row.createCell((short) 0).setCellValue("#");
    row.createCell((short) 1).setCellValue("Patient ID");
    row.createCell((short) 2).setCellValue("Patient Names");
    row.createCell((short) 3).setCellValue("Gender");
    row.createCell((short) 4).setCellValue("Last Encounter Date");
    row.createCell((short) 5).setCellValue("Last Return Visit Date");

    for (Person person : patientsList) {

        // Getting some stuff for Last Encounter Date and Last Return Visit
        // Date.
        Date maxEncounterDateTime = (Date) session
                .createSQLQuery("select cast(max(encounter_datetime)as DATE) from encounter where patient_id = "
                        + person.getPersonId())
                .uniqueResult();

        Date maxReturnVisitDay = (Date) session
                .createSQLQuery("select cast(max(value_datetime) as DATE ) " + "from obs where concept_id = "
                        + ConstantValues.NEXT_SCHEDULED_VISIT + " and person_id = " + person.getPersonId())
                .uniqueResult();

        count++;
        row = sheet.createRow((short) count + 3);
        row.createCell((short) 0).setCellValue(count);
        row.createCell((short) 1).setCellValue(person.getPersonId());
        row.createCell((short) 2).setCellValue(person.getFamilyName() + " " + person.getGivenName());
        row.createCell((short) 3).setCellValue(person.getGender());
        row.createCell((short) 4).setCellValue(maxEncounterDateTime.toString());
        row.createCell((short) 5).setCellValue(maxReturnVisitDay.toString());
    }
    OutputStream outputStream = response.getOutputStream();
    workbook.write(outputStream);
    outputStream.flush();
    outputStream.close();
}

From source file:org.openmrs.module.tracnetreporting.impl.TracNetPatientServiceImpl.java

License:Open Source License

/**
 * Exports data to the Excel File/*from  w  w  w  . ja va 2 s.  c  o  m*/
 * 
 * @throws IOException
 * @see org.openmrs.module.tracnetreporting.service.TracNetIndicatorService#exportDataToExcelFile(java.util.Map)
 */

@SuppressWarnings("deprecation")
public void exportDataToExcelFile(HttpServletRequest request, HttpServletResponse response,
        Map<String, Integer> indicatorsList, String filename, String title, String startDate, String endDate)
        throws IOException {

    log.info("exporttttttttttttttttttttttttttttttt" + indicatorsList);

    HSSFWorkbook workbook = new HSSFWorkbook();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
    HSSFSheet sheet = workbook.createSheet(title);
    int count = 0;
    sheet.setDisplayRowColHeadings(true);

    // Setting Style
    HSSFFont font = workbook.createFont();
    HSSFCellStyle cellStyle = workbook.createCellStyle();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFFont.COLOR_RED);
    cellStyle.setFillForegroundColor((short) 0xA);

    // Title
    HSSFRow row = sheet.createRow((short) 0);
    HSSFCell cell = row.createCell((short) 0);
    cell.setCellValue("");
    row.setRowStyle(cellStyle);
    row.createCell((short) 1).setCellValue("" + title + "(Between " + startDate + " and " + endDate + ")");

    // Headers
    row = sheet.createRow((short) 2);
    row.createCell((short) 0).setCellValue("#");
    row.createCell((short) 1).setCellValue("INDICATOR NAME");
    row.createCell((short) 2).setCellValue("INDICATOR");

    // for (String indicator : indicatorsList.keySet()) {
    // count++;
    // row = sheet.createRow((short) count + 3);
    // row.createCell((short) 0).setCellValue(count);
    // row.createCell((short) 1).setCellValue(indicator.toString());
    // row.createCell((short) 2).setCellValue(
    // indicatorsList.get(indicator).toString());
    // }
    OutputStream outputStream = response.getOutputStream();
    workbook.write(outputStream);
    outputStream.flush();
    outputStream.close();
}

From source file:org.openmrs.module.tracnetreporting.utils.exports.ExportToExcelUtil.java

License:Open Source License

/**
 * Exports data to the Excel File// w  w  w  .ja  va  2 s  .c om
 * 
 * @throws IOException
 * @see org.openmrs.module.tracnetreporting.service.TracNetIndicatorService#exportDataToExcelFile(java.util.Map)
 */

@SuppressWarnings("deprecation")
public static void exportDataToExcelFile(HttpServletRequest request, HttpServletResponse response,
        Map<String, Integer> indicatorsList, String filename, String title, String startDate, String endDate)
        throws IOException {

    HSSFWorkbook workbook = new HSSFWorkbook();
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
    HSSFSheet sheet = workbook.createSheet(title);
    int count = 0;
    sheet.setDisplayRowColHeadings(true);

    //Setting Style
    HSSFFont font = workbook.createFont();
    HSSFCellStyle cellStyle = workbook.createCellStyle();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setColor(HSSFFont.COLOR_RED);
    cellStyle.setFillForegroundColor((short) 0xA);

    // Title
    HSSFRow row = sheet.createRow((short) 0);
    HSSFCell cell = row.createCell((short) 0);
    cell.setCellValue("");
    row.setRowStyle(cellStyle);
    row.createCell((short) 1).setCellValue("" + title + "(Between " + startDate + " and " + endDate + ")");

    // Headers
    row = sheet.createRow((short) 2);
    row.createCell((short) 0).setCellValue("#");
    row.createCell((short) 1).setCellValue("INDICATOR NAME");
    row.createCell((short) 2).setCellValue("INDICATOR");

    for (String indicator : indicatorsList.keySet()) {
        count++;
        row = sheet.createRow((short) count + 3);
        row.createCell((short) 0).setCellValue(count);
        row.createCell((short) 1).setCellValue(indicator.toString());
        row.createCell((short) 2).setCellValue(indicatorsList.get(indicator).toString());
    }
    OutputStream outputStream = response.getOutputStream();
    workbook.write(outputStream);
    outputStream.flush();
    outputStream.close();
}