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

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

Introduction

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

Prototype

short BOLDWEIGHT_BOLD

To view the source code for org.apache.poi.hssf.usermodel HSSFFont BOLDWEIGHT_BOLD.

Click Source Link

Document

Bold boldness (bold)

Usage

From source file:org.ivan.service.ExcelExporter.java

public <T extends Object, E extends Object> File createExcelFromMap(Map<T, List<E>> objects, String fileName) {

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFFont font = workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFont(font);/*from  w  w w.  j ava  2  s.  c o  m*/
    for (T mapKey : objects.keySet()) {

        HSSFSheet sheet = workbook.createSheet(mapKey.toString());
        int cellNum = 0;
        int rowNum = 0;
        List<String> headers = getHeadersFromGetMethods(objects.get(mapKey).get(0));

        Row row = sheet.createRow(rowNum++);
        for (int i = 0; i < headers.size(); i++) {
            String cup = headers.get(i);
            Cell cell = row.createCell(cellNum++);
            cell.setCellValue(cup);
            cell.setCellStyle(style);
        }

        for (E object : objects.get(mapKey)) {
            cellNum = 0;
            List<String> parameters = getValuesRecursive(object);
            row = sheet.createRow(rowNum++);
            for (String parameter : parameters) {

                Cell cell = row.createCell(cellNum++);
                cell.setCellValue(parameter);
                sheet.autoSizeColumn(cellNum);
            }
        }
    }

    File file = new File(fileName + ".xls");
    try {
        FileOutputStream out = new FileOutputStream(file);
        workbook.write(out);
        out.close();

    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }

    return null;
}

From source file:org.jcvi.ometa.utils.JsonProducer.java

License:Open Source License

public void jsonHelper(String projectNames, String attributes, String screenAttributes, String sorting,
        String fileName, String filePath, String domain) {
    String PROJECT_STATUS = "Project Status";
    try {/*  w w  w .  j a  va 2 s  .c  o  m*/
        JSONObject json = new JSONObject();

        File directory = new File(filePath);
        if (!directory.exists() || !directory.isDirectory()) {
            if ((new File(directory.getParent())).canWrite())
                directory.mkdir();
            else
                throw new Exception();
        }
        //Json file Creation
        File tempFile = new File(filePath + File.separator + fileName + "_temp.json");
        FileWriter fileWriter = new FileWriter(tempFile);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

        //Normal status data retrieval
        LookupValue tempLookupValue;

        List<String> projectNameList = new ArrayList<String>();
        if (projectNames.contains(","))
            projectNameList.addAll(Arrays.asList(projectNames.split(",")));
        else
            projectNameList.add(projectNames);

        List<String> availableAttributes = new ArrayList<String>();
        availableAttributes.add("Sample Name");

        List<Project> projects = pseEjb.getProjects(projectNameList);
        List<Long> projectIds = new ArrayList<Long>();
        Map<String, Long> projectNameVsId = new HashMap<String, Long>();
        for (Project project : projects) {
            projectIds.add(project.getProjectId());
            projectNameVsId.put(project.getProjectName(), project.getProjectId());
        }

        List<ProjectMetaAttribute> allProjectMetaAttributes = pseEjb.getProjectMetaAttributes(projectIds);
        for (ProjectMetaAttribute pma : allProjectMetaAttributes) {
            if (!availableAttributes.contains(pma.getLookupValue().getName()))
                availableAttributes.add(pma.getLookupValue().getName());
        }
        List<SampleMetaAttribute> allSampleMetaAttributes = pseEjb.getSampleMetaAttributes(projectIds);
        for (SampleMetaAttribute sma : allSampleMetaAttributes) {
            if (!availableAttributes.contains(sma.getLookupValue().getName()))
                availableAttributes.add(sma.getLookupValue().getName());
        }
        List<EventMetaAttribute> allEventMetaAttributes = pseEjb.getEventMetaAttributes(projectIds);
        for (EventMetaAttribute ema : allEventMetaAttributes) {
            if (!availableAttributes.contains(ema.getLookupValue().getName()))
                availableAttributes.add(ema.getLookupValue().getName());
        }

        List<String> parameterizedAttributes = null;
        if (attributes == null || attributes.equals("") || "ALL".equals(attributes)) {
            parameterizedAttributes = availableAttributes;
        } else {
            parameterizedAttributes = new ArrayList<String>();

            ArrayList<String> tokenizedAttribute = new ArrayList<String>(Arrays.asList(attributes.split(",")));

            for (String tempAttribute : tokenizedAttribute) {
                if (availableAttributes.contains(tempAttribute))
                    parameterizedAttributes.add(tempAttribute);
            }
        }
        parameterizedAttributes.removeAll(Arrays.asList(forbiddenAttributes));

        /*------------ XLS Part ------------*/
        //Excel file Creation
        Workbook workBook = new HSSFWorkbook();
        Sheet workSheet = workBook.createSheet();
        int cellIndex = 0, rowIndex = 0;
        Row singleRow = workSheet.createRow(rowIndex++);
        Cell headerCell = null;

        //Header row cell style
        CellStyle style = workBook.createCellStyle();
        style.setFillBackgroundColor(IndexedColors.CORNFLOWER_BLUE.getIndex());
        style.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        Font font = workBook.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        font.setColor(IndexedColors.WHITE.getIndex());
        style.setFont(font);
        /*------------ XLS Part END ------------*/

        List<String> attributeList = new ArrayList<String>();

        for (String tempAttribute : parameterizedAttributes) {
            attributeList.add(tempAttribute);
            headerCell = singleRow.createCell(cellIndex++);
            headerCell.setCellValue(tempAttribute);
            headerCell.setCellStyle(style);
        }

        if (screenAttributes == null || screenAttributes.equals("") || screenAttributes.equals("ALL")) {
            json.put("attributes", attributeList);
        } else {
            json.put("attributes", Arrays.asList(screenAttributes.split(",")));
        }

        json.put("sorting", (sorting == null || sorting.isEmpty() || sorting.equals("-") ? null : sorting));
        json.put("projectNames", projectNames);

        List<ProjectAttribute> allProjectAttributes = pseEjb.getProjectAttributes(projectIds);
        Map<Long, List<ProjectAttribute>> projIdVsAttributes = new HashMap<Long, List<ProjectAttribute>>();
        for (ProjectAttribute pa : allProjectAttributes) {
            List<ProjectAttribute> paList = projIdVsAttributes.get(pa.getProjectId());
            if (paList == null) {
                paList = new ArrayList<ProjectAttribute>();
                projIdVsAttributes.put(pa.getProjectId(), paList);
            }
            paList.add(pa);
        }

        List<Sample> allSamplesAllProjects = pseEjb.getSamplesForProjects(projectIds);
        Map<Long, List<Sample>> projectIdVsSampleList = new HashMap<Long, List<Sample>>();
        for (Sample sample : allSamplesAllProjects) {
            List<Sample> thisProjectsSamples = projectIdVsSampleList.get(sample.getProjectId());
            if (thisProjectsSamples == null) {
                thisProjectsSamples = new ArrayList<Sample>();
                projectIdVsSampleList.put(sample.getProjectId(), thisProjectsSamples);
            }
            thisProjectsSamples.add(sample);
        }

        /************* Main LOOP starts *****************/
        List<JSONObject> sampleList = new ArrayList<JSONObject>();
        List<String> statusList = new ArrayList<String>();
        List<JSONObject> sumList = new ArrayList<JSONObject>();

        for (Project project : projects) {
            JSONObject currSum = new JSONObject();

            if (project.getIsPublic() == 0)
                continue;

            Long tempProjectId = project.getProjectId();
            List<ProjectAttribute> paList = projIdVsAttributes.get(tempProjectId);
            Map<String, Object> projectAttrMap = new HashMap<String, Object>();
            if (paList != null) {
                for (ProjectAttribute pa : paList) {
                    ProjectMetaAttribute projectMeta = pa.getMetaAttribute();
                    tempLookupValue = projectMeta.getLookupValue();
                    projectAttrMap.put(tempLookupValue.getName(),
                            ModelValidator.getModelValue(tempLookupValue, pa));

                    if (projectMeta.getLabel() != null) { //add another key-value pair for a labeled attribute
                        projectAttrMap.put(projectMeta.getLabel(),
                                ModelValidator.getModelValue(tempLookupValue, pa));
                    }
                }
            }

            if (!projectAttrMap.containsKey(Constants.ATTR_PROJECT_NAME))
                projectAttrMap.put(Constants.ATTR_PROJECT_NAME, project.getProjectName());

            currSum.put("p_n", project.getProjectName());
            currSum.put("p_s", projectAttrMap.get(PROJECT_STATUS));
            currSum.put("p_g", projectAttrMap.get("Project Group"));

            List<Long> sampleIdList = getSampleIdList(getSamplesFromList(projectIdVsSampleList, tempProjectId));
            Map<Long, List<SampleAttribute>> sampleIdVsAttributeList = getSampleVsAttributeList(sampleIdList);
            Map<Long, List<Event>> sampleIdVsEventList = getSampleIdVsEventList(sampleIdList);

            List<Sample> samplesForProject = getSamplesFromList(projectIdVsSampleList, tempProjectId);
            currSum.put("tot", samplesForProject.size());

            for (Sample sample : samplesForProject) {
                Map<String, Object> sampleAttrMap = new HashMap<String, Object>();
                sampleAttrMap.putAll(projectAttrMap);
                sampleAttrMap.put(Constants.ATTR_SAMPLE_NAME, sample.getSampleName());
                sampleAttrMap.put("sampleId", sample.getSampleId());

                List<SampleAttribute> sampleAttributes = sampleIdVsAttributeList.get(sample.getSampleId());
                if (sampleAttributes != null && sampleAttributes.size() > 0) {
                    for (SampleAttribute sa : sampleAttributes) {
                        if (sa.getMetaAttribute() == null)
                            continue;
                        SampleMetaAttribute sampleMeta = sa.getMetaAttribute();
                        tempLookupValue = sampleMeta.getLookupValue();
                        Object sav = ModelValidator.getModelValue(tempLookupValue, sa);
                        sampleAttrMap.put(tempLookupValue.getName(), sav);

                        if (sampleMeta.getLabel() != null) { //add another key-value pair for a labeled attribute
                            sampleAttrMap.put(sampleMeta.getLabel(), sav);
                        }

                        if (SAMPLE_STATUS.equals(tempLookupValue.getName())) {
                            String currStatus = (String) sav;
                            if (!statusList.contains(currStatus)) //add new status value
                                statusList.add(currStatus);
                            currSum.put(currStatus,
                                    currSum.has(currStatus) ? currSum.getInt(currStatus) + 1 : 1); //count
                        }

                    }
                }

                List<Event> sampleEvents = sampleIdVsEventList.get(sample.getSampleId());
                if (sampleEvents != null && sampleEvents.size() > 0) {
                    Map<Long, List<EventAttribute>> eventIdVsAttributes = getEventIdVsAttributeList(
                            sampleEvents, tempProjectId);
                    //skip sample status value in event attributes
                    String[] skipArrForEventAttribute = { "Sample Status" };

                    for (Event evt : sampleEvents) {
                        List<EventAttribute> eventAttributes = eventIdVsAttributes.get(evt.getEventId());
                        if (eventAttributes == null)
                            continue;

                        sampleAttrMap.putAll(CommonTool.getAttributeValueMap(eventAttributes, false,
                                skipArrForEventAttribute));
                    }
                }

                if (!sampleAttrMap.containsKey("Organism")) { //manually add Organism attribute if not exist for GCID projects
                    sampleAttrMap.put("Organism", "");
                }

                JSONObject sampleJsonObj = new JSONObject();
                for (String key : sampleAttrMap.keySet()) {
                    //this is custom decorating process for json data file only
                    //in status.shtml page, link on an organism should land to the project page rather than sample detail page
                    if (key.equals("Organism")) {
                        String organismVal = (String) sampleAttrMap.get(key);
                        if (organismVal == null) { //get different attribute value for GCID projects
                            organismVal = (String) sampleAttrMap.get("Species Source Common Name(CS4)");
                        }

                        sampleJsonObj.put("OrganismUrl", (PROD_SERVER_ADDRESS + Constants.SAMPLE_DETAIL_URL
                                + "iss=true" + "&projectName=" + project.getProjectName() + "&projectId="
                                + project.getProjectId() + "&sampleName=" + sampleAttrMap.get("Sample Name")
                                + "&sampleId=" + sampleAttrMap.get("sampleId")).replaceAll("\\\"", "\\\\\""));
                        if (domain != null && !"none".equals(domain)) {
                            String projectGroup = (String) sampleAttrMap.get("Project Group");
                            organismVal = convertIntoATag(String.format(Constants.PROJECT_SPECIFIC_PAGE, domain, //hostName != null && hostName.contains("spike") ? fileName + "-dev" : fileName,
                                    (projectGroup == null ? "" : projectGroup.toLowerCase()),
                                    project.getProjectName().replaceAll(" ", "_")), organismVal);
                        }
                        sampleJsonObj.put(key, organismVal);
                    } else {
                        sampleJsonObj.put(key, CommonTool.decorateAttribute(sampleAttrMap, key, project));
                    }
                }
                sampleList.add(sampleJsonObj);

                cellIndex = 0;
                singleRow = workSheet.createRow(rowIndex++);
                for (String tempAttribute : parameterizedAttributes) {
                    singleRow.createCell(cellIndex++)
                            .setCellValue(sampleAttrMap.get(tempAttribute) != null
                                    ? "" + sampleAttrMap.get(tempAttribute)
                                    : "");
                }
            }
            sumList.add(currSum);
        }

        JSONObject sumMap = new JSONObject();
        sumMap.put("s_l", statusList);
        sumMap.put("data", sumList);
        json.put("sums", sumMap);

        json.put("samples", sampleList);
        //bufferedWriter.write("]");
        bufferedWriter.write(json.toString());
        bufferedWriter.close();

        if (tempFile.exists() && tempFile.length() > 0) {
            File dataFile = new File(filePath + File.separator + fileName + ".json");
            tempFile.renameTo(dataFile);

            FileOutputStream fileOut = new FileOutputStream(filePath + File.separator + fileName + ".xls");
            workBook.write(fileOut);
            fileOut.close();
        } else
            throw new Exception("Failure in retrieving data for " + fileName
                    + ". File does not exist or file size is zero.");

        logger.info("[JsonProducer-MBean] JsonProducer process succeeded for " + projectNames);
    } catch (Exception ex) {
        logger.info("[JsonProducer-MBean] JsonProducer failed for " + projectNames);
        ex.printStackTrace();

        /*if( hostName.contains( "dmzweb" ) ) { //Send error notification for DMZs only
        new EmailSender().send(
                "json",
                "[PST]Failure in generating Json Data file on : " + hostName,
                ex.toString()
        );
        }*/
    }
}

From source file:org.jxstar.report.studio.ExportXlsBO.java

/**
 * ?//  w ww  . j  av a  2 s  .  c  o  m
 * @param wb -- ?
 * @return
 */
public HSSFCellStyle createTitleStyle(HSSFWorkbook wb) {
    //
    HSSFFont cellFont = wb.createFont();
    cellFont.setFontName("");
    cellFont.setFontHeightInPoints((short) 16);
    cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    //?
    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);
    cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    cellStyle.setFont(cellFont);

    return cellStyle;
}

From source file:org.jxstar.report.studio.ExportXlsBO.java

/**
 * ?//w w  w . j  a  v  a2s.  co m
 * @param wb -- ?
 * @return
 */
public HSSFCellStyle createHeadStyle(HSSFWorkbook wb) {
    //
    HSSFFont cellFont = wb.createFont();
    cellFont.setFontName("");
    cellFont.setFontHeightInPoints((short) 9);
    cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

    //?
    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER_SELECTION);
    cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
    cellStyle.setFont(cellFont);

    //
    cellStyle.setBorderBottom((short) 1);
    cellStyle.setBorderLeft((short) 1);
    cellStyle.setBorderRight((short) 1);
    cellStyle.setBorderTop((short) 1);

    return cellStyle;
}

From source file:org.mili.core.text.transformation.ExcelTransformator.java

License:Apache License

/**
 * Transforms.//from w ww . ja v a2 s .  co m
 *
 * @param from from table
 * @param params the params
 * @return the HSSF workbook
 */
public HSSFWorkbook transform(Table from, Object... params) {
    if (from.getRowSize() == 0) {
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFDataFormat format = wb.createDataFormat();
        HSSFSheet sheet = wb.createSheet(getSheetName(null));
        HSSFRow r = sheet.createRow(0);
        HSSFCell c = r.createCell((short) (0));
        c.setCellValue("Keine Daten vorhanden !");
        return wb;
    }
    String fsInt = "#,###,##0";
    String fsFloat = "#,###,##0.000";
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFDataFormat format = wb.createDataFormat();
    HSSFSheet sheet = wb.createSheet(getSheetName(null));
    HSSFFont headFont = wb.createFont();
    headFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle headStyle = wb.createCellStyle();
    headStyle.setFont(headFont);
    HSSFCellStyle numberStyle = wb.createCellStyle();
    HSSFRow headerRow = sheet.createRow(0);
    short z = 0;
    for (int i = 0, n = from.getColSize(); i < n; i++) {
        Col col = from.getCol(i);
        HSSFCell headerCell = headerRow.createCell((short) (z));
        headerCell.setCellStyle(headStyle);
        headerCell.setCellValue(col.getName());
        z++;
    }
    for (int i = 0, n = from.getRowSize(); i < n; i++) {
        Row row = from.getRow(i);
        HSSFRow contentRow = sheet.createRow(i + 1);
        short j = 0;
        for (int ii = 0, nn = from.getColSize(); ii < nn; ii++) {
            Col col = from.getCol(ii);
            Object o = row.getValue(ii);
            HSSFCell contentCell = contentRow.createCell((short) (j));
            String value = o == null ? "" : String.valueOf(o);
            if (o instanceof Number) {
                if (o instanceof Integer) {
                    numberStyle.setDataFormat(format.getFormat(fsInt));
                    contentCell.setCellValue(Integer.parseInt(value));
                    contentCell.setCellStyle(numberStyle);
                } else if (o instanceof Float) {
                    numberStyle.setDataFormat(format.getFormat(fsFloat));
                    contentCell.setCellValue(Float.parseFloat(value));
                    contentCell.setCellStyle(numberStyle);
                }
            } else {
                contentCell.setCellValue(value);
            }
            j++;
        }
    }
    return wb;
}

From source file:org.ofbiz.webtools.ExcelConversionFilter.java

License:Open Source License

void applyStylesToSheet(Map<String, ? extends Object> context, HSSFWorkbook workBook, HSSFSheet sheet,
        ServletRequest request) {//from w w w .  j a  va  2  s  .  c  o m
    List headerKeys = new ArrayList();
    int noOfheads = 0;
    headerKeys = UtilMisc.toList("mainHeader1", "mainHeader2", "mainHeader3", "mainHeader4", "mainHeader5");
    Map<String, Object> stylesMap = FastMap.newInstance();
    stylesMap = (Map) context.get("stylesMap");
    ArrayList allRowAndColData = (ArrayList) context.get("allRowAndColData");
    Integer mainHeadingCell = 5;
    Integer mainHeadercellHeight = null;
    String mainHeaderFontName = null;
    Integer mainHeaderFontSize = null;
    Boolean mainHeaderBold = true;
    Integer columnHeaderCellHeight = null;
    Boolean columnHeaderBold = true;
    Boolean columnHeaderBgColor = null;
    String columnHeaderFontName = null;
    Boolean autoSizeCell = true;
    Integer columnHeaderFontSize = null;
    mainHeadercellHeight = (Integer) stylesMap.get("mainHeadercellHeight");
    mainHeaderFontName = (String) stylesMap.get("mainHeaderFontName");
    mainHeaderFontSize = (Integer) stylesMap.get("mainHeaderFontSize");
    if (stylesMap.get("mainHeaderBold") != null) {
        mainHeaderBold = (Boolean) stylesMap.get("mainHeaderBold");
    }
    if (stylesMap.get("columnHeaderBold") != null) {
        columnHeaderBold = (Boolean) stylesMap.get("columnHeaderBold");
    }
    if (stylesMap.get("autoSizeCell") != null) {
        autoSizeCell = (Boolean) stylesMap.get("autoSizeCell");
    }
    if (stylesMap.get("mainHeadingCell") != null) {
        mainHeadingCell = (Integer) stylesMap.get("mainHeadingCell");
    }
    columnHeaderCellHeight = (Integer) stylesMap.get("columnHeaderCellHeight");
    columnHeaderBgColor = (Boolean) stylesMap.get("columnHeaderBgColor");
    columnHeaderFontName = (String) stylesMap.get("columnHeaderFontName");
    columnHeaderFontSize = (Integer) stylesMap.get("columnHeaderFontSize");
    ArrayList styles = new ArrayList(stylesMap.keySet());
    for (int i = 0; i < styles.size(); i++) {
        ArrayList tempArrayList = new ArrayList<String>();
        if (headerKeys.contains(styles.get(i))) {
            ArrayList<?> innerData = (ArrayList<?>) allRowAndColData.get(i);
            tempArrayList.add(stylesMap.get(styles.get(i)));
            for (int j = 0; j < innerData.size() - 1; j++) {
                tempArrayList.add("");
            }
            allRowAndColData.add(i, tempArrayList);
            ++noOfheads;
        }
    }
    try {
        for (int i = 0; i < allRowAndColData.size(); i++) {
            HSSFCellStyle style = workBook.createCellStyle();
            HSSFFont font = workBook.createFont();
            ArrayList<?> ardata = (ArrayList<?>) allRowAndColData.get(i);
            HSSFRow row = sheet.createRow(i);
            for (int k = 0; k < ardata.size(); k++) {
                HSSFCell cell = row.createCell(k);
                if (k == mainHeadingCell && i <= noOfheads) {
                    if (UtilValidate.isNotEmpty(mainHeadercellHeight)) {
                        row.setHeight((short) mainHeadercellHeight.shortValue());
                    } else {
                        row.setHeight((short) 400);
                    }
                    if (UtilValidate.isNotEmpty(mainHeaderFontName)) {
                        font.setFontName(mainHeaderFontName);
                    }
                    if (UtilValidate.isNotEmpty(mainHeaderBold) && mainHeaderBold) {
                        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                    }
                    if (UtilValidate.isNotEmpty(mainHeaderFontSize)) {
                        font.setFontHeightInPoints((short) mainHeaderFontSize.shortValue());
                    } else {
                        font.setFontHeightInPoints((short) 12); //default value 
                    }
                    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    style.setFont(font);
                    cell.setCellValue((ardata.get(0).toString()).replaceAll("\"", ""));
                    cell.setCellStyle(style);
                } else if (i == noOfheads + 1) {
                    if (UtilValidate.isNotEmpty(columnHeaderCellHeight)) {
                        row.setHeight((short) columnHeaderCellHeight.shortValue());
                    } else {
                        row.setHeight((short) 300);
                    }
                    if (UtilValidate.isNotEmpty(columnHeaderBold) && columnHeaderBold) {
                        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                    }
                    if (UtilValidate.isNotEmpty(columnHeaderFontSize)) {
                        font.setFontHeightInPoints((short) columnHeaderFontSize.shortValue());
                    } else {
                        font.setFontHeightInPoints((short) 9);
                    }
                    if (UtilValidate.isNotEmpty(columnHeaderFontName)) {
                        font.setFontName(columnHeaderFontName);
                    }
                    if (UtilValidate.isNotEmpty(columnHeaderBgColor) && columnHeaderBgColor) {
                        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
                    }
                    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    style.setFont(font);
                    cell.setCellValue((ardata.get(k).toString()).replaceAll("\"", ""));
                    cell.setCellStyle(style);
                } else if (i > noOfheads) {
                    cell.setCellValue((ardata.get(k).toString()).replaceAll("\"", ""));
                }
                if (UtilValidate.isNotEmpty(autoSizeCell) && autoSizeCell) {
                    sheet.autoSizeColumn(k);
                }
            }
        }
    } catch (Exception e) {
        Debug.logInfo(e.getMessage(), module);
        request.setAttribute("_ERROR_MESSAGE_", e.getMessage());

    }
}

From source file:org.openmicroscopy.shoola.util.file.ExcelWriter.java

License:Open Source License

/** Creates the fonts that are going to be used in the styles. */
private void createFonts() {
    HSSFFont font;/*from ww w .j  a  va 2s. c  o m*/
    /* Hyperlink font. */
    font = workbook.createFont();
    font.setUnderline(HSSFFont.U_SINGLE);
    font.setColor(HSSFColor.BLUE.index);
    fontMap.put(HYPERLINK, font);

    /* Default Font. */
    font = workbook.createFont();
    fontMap.put(DEFAULT, font);

    /* Bold Font. */
    font = workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontMap.put(BOLD_DEFAULT, font);

    /* Underline Font. */
    font = workbook.createFont();
    font.setUnderline(HSSFFont.U_SINGLE);
    fontMap.put(UNDERLINE_DEFAULT, font);

    /* Italic Font. */
    font = workbook.createFont();
    font.setItalic(true);
    fontMap.put(ITALIC_DEFAULT, font);

    /* Italic, underline Font. */
    font = workbook.createFont();
    font.setItalic(true);
    font.setUnderline(HSSFFont.U_SINGLE);
    fontMap.put(ITALIC_UNDERLINE_DEFAULT, font);

    /* Italic, bold Font. */
    font = workbook.createFont();
    font.setItalic(true);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontMap.put(BOLD_ITALIC_DEFAULT, font);

    /* Italic, bold, underline Font. */
    font = workbook.createFont();
    font.setItalic(true);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setUnderline(HSSFFont.U_SINGLE);
    fontMap.put(BOLD_ITALIC_UNDERLINE_DEFAULT, font);

    /* Italic, bold, underline Font. */
    font = workbook.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setUnderline(HSSFFont.U_SINGLE);
    fontMap.put(BOLD_UNDERLINE_DEFAULT, font);

    /* 12 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 12);
    fontMap.put(PLAIN_12, font);

    /* 14 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 14);
    fontMap.put(PLAIN_14, font);

    /* 14 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 14);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontMap.put(BOLD_14, font);

    /* 18 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 18);
    fontMap.put(PLAIN_18, font);

    /* 18 point font. */
    font = workbook.createFont();
    font.setFontHeightInPoints((short) 18);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    fontMap.put(BOLD_18, font);
}

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

License:Open Source License

/**
 * Exports data to the Excel File/*ww  w .j a va  2s. c o  m*/
 * 
 * @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  ww  w. j  a v a 2s.  c om*/
 * 
 * @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  v a  2 s . co  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();
}