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

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

Introduction

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

Prototype


public void setUnderline(byte underline) 

Source Link

Document

set type of text underlining to use

Usage

From source file:com.commander4j.util.JExcel.java

License:Open Source License

public void exportToExcel(String filename, ResultSet rs) {
    try {//from www  .  j  av a 2s .c  o m

        ResultSetMetaData rsmd = rs.getMetaData();
        int numberOfColumns = rsmd.getColumnCount();
        int columnType = 0;
        String columnTypeName = "";
        int recordNumber = 0;
        int passwordCol = -1;

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();

        HSSFCellStyle cellStyle_varchar = workbook.createCellStyle();
        cellStyle_varchar.setAlignment(HorizontalAlignment.LEFT);

        HSSFCellStyle cellStyle_nvarchar = workbook.createCellStyle();
        cellStyle_nvarchar.setAlignment(HorizontalAlignment.LEFT);

        HSSFCellStyle cellStyle_varchar2 = workbook.createCellStyle();
        cellStyle_varchar2.setAlignment(HorizontalAlignment.LEFT);

        HSSFCellStyle cellStyle_title = workbook.createCellStyle();
        cellStyle_title.setAlignment(HorizontalAlignment.CENTER);

        HSSFCellStyle cellStyle_char = workbook.createCellStyle();
        cellStyle_char.setAlignment(HorizontalAlignment.LEFT);

        HSSFCellStyle cellStyle_date = workbook.createCellStyle();
        cellStyle_date.setAlignment(HorizontalAlignment.CENTER);
        cellStyle_date.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));

        HSSFCellStyle cellStyle_timestamp = workbook.createCellStyle();
        cellStyle_timestamp.setAlignment(HorizontalAlignment.CENTER);
        cellStyle_timestamp.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));

        HSSFCellStyle cellStyle_decimal = workbook.createCellStyle();
        cellStyle_decimal.setAlignment(HorizontalAlignment.RIGHT);

        HSSFFont font_title = workbook.createFont();
        font_title.setColor((short) 0xc);
        font_title.setBold(true);
        ;
        font_title.setItalic(true);
        font_title.setUnderline(HSSFFont.U_DOUBLE);
        cellStyle_title.setFont(font_title);

        HSSFCell cell;
        HSSFRow row;

        // rs.beforeFirst();

        while (rs.next()) {
            recordNumber++;

            if (recordNumber == 1) {
                row = sheet.createRow((int) 0);
                for (int column = 1; column <= numberOfColumns; column++) {
                    cell = row.createCell((int) (column - 1));
                    String columnName = rsmd.getColumnLabel(column);
                    columnName = columnName.replace("_", " ");
                    columnName = JUtility.capitalize(columnName);
                    cell.setCellStyle(cellStyle_title);
                    cell.setCellValue(columnName);
                    if (columnName.equals("Password")) {
                        passwordCol = column;
                    }
                }
            }

            row = sheet.createRow((int) recordNumber);

            for (int column = 1; column <= numberOfColumns; column++) {

                columnType = rsmd.getColumnType(column);
                columnTypeName = rsmd.getColumnTypeName(column);

                cell = row.createCell((int) (column - 1));

                try {
                    switch (columnType) {
                    case java.sql.Types.NVARCHAR:
                        HSSFRichTextString rtf_nvarchar;
                        if (column == passwordCol) {
                            rtf_nvarchar = new HSSFRichTextString("*****");
                        } else {
                            rtf_nvarchar = new HSSFRichTextString(rs.getString(column));
                        }

                        cell.setCellStyle(cellStyle_nvarchar);
                        cell.setCellValue(rtf_nvarchar);
                        break;
                    case java.sql.Types.VARCHAR:
                        HSSFRichTextString rtf_varchar;
                        if (column == passwordCol) {
                            rtf_varchar = new HSSFRichTextString("*****");
                        } else {
                            rtf_varchar = new HSSFRichTextString(rs.getString(column));
                        }

                        cell.setCellStyle(cellStyle_varchar);
                        cell.setCellValue(rtf_varchar);
                        break;
                    case java.sql.Types.CHAR:
                        HSSFRichTextString rtf_char = new HSSFRichTextString(rs.getString(column));
                        cell.setCellStyle(cellStyle_char);
                        cell.setCellValue(rtf_char);
                        break;
                    case java.sql.Types.DATE:
                        try {
                            cell.setCellValue(rs.getTimestamp(column));
                            cell.setCellStyle(cellStyle_date);
                        } catch (Exception ex) {

                        }
                        break;
                    case java.sql.Types.TIMESTAMP:
                        try {
                            cell.setCellValue(rs.getTimestamp(column));
                            cell.setCellStyle(cellStyle_timestamp);
                        } catch (Exception ex) {

                        }
                        break;
                    case java.sql.Types.DECIMAL:
                        HSSFRichTextString rtf_decimal = new HSSFRichTextString(
                                rs.getBigDecimal(column).toString());
                        cell.setCellStyle(cellStyle_decimal);
                        cell.setCellValue(rtf_decimal);
                        break;
                    case java.sql.Types.NUMERIC:
                        HSSFRichTextString rtf_decimaln = new HSSFRichTextString(
                                rs.getBigDecimal(column).toString());
                        cell.setCellStyle(cellStyle_decimal);
                        cell.setCellValue(rtf_decimaln);
                        break;
                    case java.sql.Types.BIGINT:
                        HSSFRichTextString rtf_bigint = new HSSFRichTextString(
                                rs.getBigDecimal(column).toString());
                        cell.setCellStyle(cellStyle_decimal);
                        cell.setCellValue(rtf_bigint);
                        break;
                    case java.sql.Types.INTEGER:
                        HSSFRichTextString rtf_int = new HSSFRichTextString(String.valueOf(rs.getInt(column)));
                        cell.setCellStyle(cellStyle_decimal);
                        cell.setCellValue(rtf_int);
                        break;
                    case java.sql.Types.FLOAT:
                        HSSFRichTextString rtf_float = new HSSFRichTextString(
                                String.valueOf(rs.getFloat(column)));
                        cell.setCellStyle(cellStyle_decimal);
                        cell.setCellValue(rtf_float);
                        break;
                    case java.sql.Types.DOUBLE:
                        HSSFRichTextString rtf_double = new HSSFRichTextString(
                                String.valueOf(rs.getDouble(column)));
                        cell.setCellStyle(cellStyle_decimal);
                        cell.setCellValue(rtf_double);
                        break;
                    default:
                        cell.setCellValue(new HSSFRichTextString(columnTypeName));
                        break;
                    }
                } catch (Exception ex) {
                    String errormessage = ex.getLocalizedMessage();
                    HSSFRichTextString rtf_exception = new HSSFRichTextString(errormessage);
                    cell.setCellStyle(cellStyle_varchar);
                    cell.setCellValue(rtf_exception);
                    break;
                }
            }

            if (recordNumber == 65535) {
                break;
            }
        }

        for (int column = 1; column <= numberOfColumns; column++) {
            sheet.autoSizeColumn((int) (column - 1));
        }

        if (recordNumber > 0) {
            try {
                FileOutputStream fileOut = new FileOutputStream(filename.toLowerCase());
                workbook.write(fileOut);
                fileOut.close();
            } catch (Exception ex) {
                setErrorMessage(ex.getMessage());
            }
        }

        try {
            workbook.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (SQLException e) {
        setErrorMessage(e.getMessage());
    }
}

From source file:com.develog.utils.report.engine.export.JRXlsExporter.java

License:Open Source License

/**
 *
 *//*from   ww  w  . j  a  v a 2 s .c o  m*/
protected HSSFFont getLoadedFont(JRFont font, short forecolor) {
    HSSFFont cellFont = null;

    if (loadedFonts != null && loadedFonts.size() > 0) {
        HSSFFont cf = null;
        for (int i = 0; i < loadedFonts.size(); i++) {
            cf = (HSSFFont) loadedFonts.get(i);

            if (cf.getFontName().equals(font.getFontName()) && (cf.getColor() == forecolor)
                    && (cf.getFontHeightInPoints() == (short) font.getSize())
                    && ((cf.getUnderline() == HSSFFont.U_SINGLE) ? (font.isUnderline()) : (!font.isUnderline()))
                    && (cf.getStrikeout() == font.isStrikeThrough())
                    && ((cf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) ? (font.isBold()) : (!font.isBold()))
                    && (cf.getItalic() == font.isItalic())) {
                cellFont = cf;
                break;
            }
        }
    }

    if (cellFont == null) {
        cellFont = workbook.createFont();
        cellFont.setFontName(font.getFontName());
        cellFont.setColor(forecolor);
        cellFont.setFontHeightInPoints((short) font.getSize());

        if (font.isUnderline()) {
            cellFont.setUnderline(HSSFFont.U_SINGLE);
        }
        if (font.isStrikeThrough()) {
            cellFont.setStrikeout(true);
        }
        if (font.isBold()) {
            cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        if (font.isItalic()) {
            cellFont.setItalic(true);
        }

        loadedFonts.add(cellFont);
    }

    return cellFont;
}

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

License:Apache License

public static void copyCellStyle(HSSFWorkbook destwb, HSSFCellStyle dest, HSSFWorkbook srcwb,
        HSSFCellStyle src) {/*from   www.  j a  v  a2 s.c om*/
    if (src == null || dest == null)
        return;
    dest.setAlignment(src.getAlignment());
    dest.setBorderBottom(src.getBorderBottom());
    dest.setBorderLeft(src.getBorderLeft());
    dest.setBorderRight(src.getBorderRight());
    dest.setBorderTop(src.getBorderTop());
    dest.setBottomBorderColor(findColor(src.getBottomBorderColor(), srcwb, destwb));
    dest.setDataFormat(
            destwb.createDataFormat().getFormat(srcwb.createDataFormat().getFormat(src.getDataFormat())));
    dest.setFillPattern(src.getFillPattern());
    dest.setFillForegroundColor(findColor(src.getFillForegroundColor(), srcwb, destwb));
    dest.setFillBackgroundColor(findColor(src.getFillBackgroundColor(), srcwb, destwb));
    dest.setHidden(src.getHidden());
    dest.setIndention(src.getIndention());
    dest.setLeftBorderColor(findColor(src.getLeftBorderColor(), srcwb, destwb));
    dest.setLocked(src.getLocked());
    dest.setRightBorderColor(findColor(src.getRightBorderColor(), srcwb, destwb));
    dest.setRotation(src.getRotation());
    dest.setTopBorderColor(findColor(src.getTopBorderColor(), srcwb, destwb));
    dest.setVerticalAlignment(src.getVerticalAlignment());
    dest.setWrapText(src.getWrapText());

    HSSFFont f = srcwb.getFontAt(src.getFontIndex());
    HSSFFont nf = findFont(f, srcwb, destwb);
    if (nf == null) {
        nf = destwb.createFont();
        nf.setBoldweight(f.getBoldweight());
        nf.setCharSet(f.getCharSet());
        nf.setColor(findColor(f.getColor(), srcwb, destwb));
        nf.setFontHeight(f.getFontHeight());
        nf.setFontHeightInPoints(f.getFontHeightInPoints());
        nf.setFontName(f.getFontName());
        nf.setItalic(f.getItalic());
        nf.setStrikeout(f.getStrikeout());
        nf.setTypeOffset(f.getTypeOffset());
        nf.setUnderline(f.getUnderline());
    }
    dest.setFont(nf);
}

From source file:com.haulmont.yarg.formatters.impl.xls.hints.CustomCellStyleHint.java

License:Apache License

@Override
public void apply() {
    for (DataObject dataObject : data) {
        HSSFCell templateCell = dataObject.templateCell;
        HSSFCell resultCell = dataObject.resultCell;
        BandData bandData = dataObject.bandData;

        HSSFWorkbook resultWorkbook = resultCell.getSheet().getWorkbook();
        HSSFWorkbook templateWorkbook = templateCell.getSheet().getWorkbook();

        String templateCellValue = templateCell.getStringCellValue();

        Matcher matcher = pattern.matcher(templateCellValue);
        if (matcher.find()) {
            String paramName = matcher.group(1);
            String styleName = (String) bandData.getParameterValue(paramName);
            if (styleName == null)
                continue;

            HSSFCellStyle cellStyle = styleCache.getStyleByName(styleName);
            if (cellStyle == null)
                continue;

            HSSFCellStyle resultStyle = styleCache.getNamedCachedStyle(cellStyle);

            if (resultStyle == null) {
                HSSFCellStyle newStyle = resultWorkbook.createCellStyle();
                // color
                newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor());
                newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor());
                newStyle.setFillPattern(cellStyle.getFillPattern());

                // borders
                newStyle.setBorderLeft(cellStyle.getBorderLeft());
                newStyle.setBorderRight(cellStyle.getBorderRight());
                newStyle.setBorderTop(cellStyle.getBorderTop());
                newStyle.setBorderBottom(cellStyle.getBorderBottom());

                // border colors
                newStyle.setLeftBorderColor(cellStyle.getLeftBorderColor());
                newStyle.setRightBorderColor(cellStyle.getRightBorderColor());
                newStyle.setBottomBorderColor(cellStyle.getBottomBorderColor());
                newStyle.setTopBorderColor(cellStyle.getTopBorderColor());

                // alignment
                newStyle.setAlignment(cellStyle.getAlignment());
                newStyle.setVerticalAlignment(cellStyle.getVerticalAlignment());
                // misc
                DataFormat dataFormat = resultWorkbook.getCreationHelper().createDataFormat();
                newStyle.setDataFormat(dataFormat.getFormat(cellStyle.getDataFormatString()));
                newStyle.setHidden(cellStyle.getHidden());
                newStyle.setLocked(cellStyle.getLocked());
                newStyle.setIndention(cellStyle.getIndention());
                newStyle.setRotation(cellStyle.getRotation());
                newStyle.setWrapText(cellStyle.getWrapText());
                // font
                HSSFFont cellFont = cellStyle.getFont(templateWorkbook);
                HSSFFont newFont = fontCache.getFontByTemplate(cellFont);

                if (newFont == null) {
                    newFont = resultWorkbook.createFont();

                    newFont.setFontName(cellFont.getFontName());
                    newFont.setItalic(cellFont.getItalic());
                    newFont.setStrikeout(cellFont.getStrikeout());
                    newFont.setTypeOffset(cellFont.getTypeOffset());
                    newFont.setBoldweight(cellFont.getBoldweight());
                    newFont.setCharSet(cellFont.getCharSet());
                    newFont.setColor(cellFont.getColor());
                    newFont.setUnderline(cellFont.getUnderline());
                    newFont.setFontHeight(cellFont.getFontHeight());
                    newFont.setFontHeightInPoints(cellFont.getFontHeightInPoints());
                    fontCache.addCachedFont(cellFont, newFont);
                }/*from   www.j  a  va  2s .c  om*/
                newStyle.setFont(newFont);

                resultStyle = newStyle;
                styleCache.addCachedNamedStyle(cellStyle, resultStyle);
            }

            fixNeighbourCellBorders(cellStyle, resultCell);

            resultCell.setCellStyle(resultStyle);

            Sheet sheet = resultCell.getSheet();
            for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
                CellRangeAddress mergedRegion = sheet.getMergedRegion(i);
                if (mergedRegion.isInRange(resultCell.getRowIndex(), resultCell.getColumnIndex())) {

                    int firstRow = mergedRegion.getFirstRow();
                    int lastRow = mergedRegion.getLastRow();
                    int firstCol = mergedRegion.getFirstColumn();
                    int lastCol = mergedRegion.getLastColumn();

                    for (int row = firstRow; row <= lastRow; row++)
                        for (int col = firstCol; col <= lastCol; col++)
                            sheet.getRow(row).getCell(col).setCellStyle(resultStyle);

                    // cell includes only in one merged region
                    break;
                }
            }
        }
    }
}

From source file:com.siteview.ecc.report.xls.JRXlsExporter.java

License:Open Source License

/**
 *
 *///from   w  w  w .  j  a  va 2s .com
protected HSSFFont getLoadedFont(JRFont font, short forecolor, Map attributes, Locale locale) {
    HSSFFont cellFont = null;

    String fontName = font.getFontName();
    if (fontMap != null && fontMap.containsKey(fontName)) {
        fontName = (String) fontMap.get(fontName);
    } else {
        FontInfo fontInfo = JRFontUtil.getFontInfo(fontName, locale);
        if (fontInfo != null) {
            //fontName found in font extensions
            FontFamily family = fontInfo.getFontFamily();
            String exportFont = family.getExportFont(getExporterKey());
            if (exportFont != null) {
                fontName = exportFont;
            }
        }
    }

    short superscriptType = HSSFFont.SS_NONE;

    if (attributes != null && attributes.get(TextAttribute.SUPERSCRIPT) != null) {
        Object value = attributes.get(TextAttribute.SUPERSCRIPT);
        if (TextAttribute.SUPERSCRIPT_SUPER.equals(value)) {
            superscriptType = HSSFFont.SS_SUPER;
        } else if (TextAttribute.SUPERSCRIPT_SUB.equals(value)) {
            superscriptType = HSSFFont.SS_SUB;
        }

    }
    for (int i = 0; i < loadedFonts.size(); i++) {
        HSSFFont cf = (HSSFFont) loadedFonts.get(i);

        short fontSize = (short) font.getFontSize();
        if (isFontSizeFixEnabled)
            fontSize -= 1;

        if (cf.getFontName().equals(fontName) && (cf.getColor() == forecolor)
                && (cf.getFontHeightInPoints() == fontSize)
                && ((cf.getUnderline() == HSSFFont.U_SINGLE) ? (font.isUnderline()) : (!font.isUnderline()))
                && (cf.getStrikeout() == font.isStrikeThrough())
                && ((cf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) ? (font.isBold()) : (!font.isBold()))
                && (cf.getItalic() == font.isItalic()) && (cf.getTypeOffset() == superscriptType)) {
            cellFont = cf;
            break;
        }
    }

    if (cellFont == null) {
        cellFont = workbook.createFont();

        cellFont.setFontName(fontName);
        cellFont.setColor(forecolor);

        short fontSize = (short) font.getFontSize();
        if (isFontSizeFixEnabled)
            fontSize -= 1;

        cellFont.setFontHeightInPoints(fontSize);

        if (font.isUnderline()) {
            cellFont.setUnderline(HSSFFont.U_SINGLE);
        }
        if (font.isStrikeThrough()) {
            cellFont.setStrikeout(true);
        }
        if (font.isBold()) {
            cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        if (font.isItalic()) {
            cellFont.setItalic(true);
        }

        cellFont.setTypeOffset(superscriptType);
        loadedFonts.add(cellFont);
    }

    return cellFont;
}

From source file:devcup.search4u.xlsview.ConvertResultsToXLS.java

public void createXLSTable() throws IOException {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("Result sheet");

    //create headerRow
    Row headerRow = sheet.createRow(0);/*  w w w.  j ava  2  s.  c  om*/

    HSSFCellStyle headerStyle = workbook.createCellStyle();
    HSSFCellStyle style = workbook.createCellStyle();

    HSSFFont partFont = workbook.createFont();
    //partFont.setItalic(true);
    partFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    partFont.setUnderline(HSSFFont.U_DOUBLE);

    HSSFFont defaultFont = workbook.createFont();
    defaultFont.setFontHeightInPoints((short) 10);
    defaultFont.setFontName("Arial");
    defaultFont.setColor(HSSFColor.BLACK.index);
    defaultFont.setItalic(false);

    HSSFFont font = workbook.createFont();
    font.setFontHeightInPoints((short) 11);
    font.setFontName("Arial");
    font.setColor(HSSFColor.BLUE_GREY.index);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    font.setItalic(true);

    //style=(HSSFCellStyle) headerRow.getRowStyle();       
    //style.setFillPattern(CellStyle.SOLID_FOREGROUND);       
    headerStyle.setWrapText(true);
    headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
    //style.setFillBackgroundColor(HSSFColor.ROYAL_BLUE.index);
    //style.setFillForegroundColor(HSSFColor.ROYAL_BLUE.index);
    //style.setHidden(false);
    //style.setIndention(indent);
    headerStyle.setFont(font);

    //create a new cell in headerRow
    Cell headerCell;
    headerCell = headerRow.createCell(0);
    headerCell.setCellValue("?");
    headerCell.setCellStyle(headerStyle);
    //sheet.autoSizeColumn(0);
    sheet.setColumnWidth(0, 7000);

    headerCell = headerRow.createCell(1);
    headerCell.setCellValue("  ");
    headerCell.setCellStyle(headerStyle);
    //sheet.autoSizeColumn(1);
    sheet.setColumnWidth(1, 12000);

    /*headerCell = headerRow.createCell(2);
    headerCell.setCellValue("?  ");
    headerCell.setCellStyle(style);
    sheet.autoSizeColumn(2);
    //sheet.setColumnWidth(2, 7000);
    */

    headerCell = headerRow.createCell(2);
    headerCell.setCellValue(" ?");
    headerCell.setCellStyle(headerStyle);
    //sheet.autoSizeColumn(3);
    sheet.setColumnWidth(2, 18000);

    style.setWrapText(true);
    style.setFont(defaultFont);

    //create another Rows
    int rowNum = 1;
    for (SearchResult searchResult : searchResultsList) {
        for (String key : searchResult.getRelevDocsPath()) {
            //for (String key : searchResult.getDocumentsFragments().keySet()) {
            for (ObjectPair<Integer, String> pair : searchResult.getDocumentsFragments().get(key)) {

                Row row = sheet.createRow(rowNum++);

                Cell cell;
                cell = row.createCell(0);
                cell.setCellValue(searchResult.getQuery());
                cell.setCellStyle(style);

                cell = row.createCell(1);
                cell.setCellValue(key);
                cell.setCellStyle(style);

                //cell = row.createCell(2);
                //cell.setCellValue(pair.getFirst());
                //cell.setCellStyle(style);

                cell = row.createCell(2);
                cell.setCellValue(labeledStringToRichTextString(pair.getSecond(), partFont));
                cell.setCellStyle(style);

            }
        }
    }

    try {
        FileOutputStream out = new FileOutputStream(new File(resultXMLPath));
        workbook.write(out);
        out.close();
        System.out.println("Excel written successfully..");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:gov.nih.nci.cananolab.service.sample.impl.CharacterizationExporter.java

License:BSD License

/**
 * Output Sample Characterization Summary report (==>
 * bodyCharacterizationSummaryPrintViewTable.jsp)
 *
 * @param summaryBean/*from  w w  w  .j av  a 2s. co  m*/
 * @param wb
 * @throws IOException
 */
private static void outputSummarySheet(List<String> charTypes, CharacterizationSummaryViewBean summaryBean,
        String downloadURL, HSSFWorkbook wb) throws IOException {
    HSSFFont headerFont = wb.createFont();
    headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle headerStyle = wb.createCellStyle();
    headerStyle.setFont(headerFont);

    HSSFCellStyle hlinkStyle = wb.createCellStyle();
    HSSFFont hlinkFont = wb.createFont();
    hlinkFont.setUnderline(HSSFFont.U_SINGLE);
    hlinkFont.setColor(HSSFColor.BLUE.index);
    hlinkStyle.setFont(hlinkFont);

    int charCount = 1;
    Map<String, SortedSet<CharacterizationBean>> charBeanMap = summaryBean.getType2Characterizations();
    for (String type : charTypes) {
        // Output data of report
        SortedSet<CharacterizationBean> charBeans = charBeanMap.get(type);
        if (charBeans != null && !charBeans.isEmpty()) {
            for (CharacterizationBean charBean : charBeans) {
                int rowIndex = 0;

                // Create one work sheet for each Characterization.
                HSSFSheet sheet = wb.createSheet(charCount++ + "." + charBean.getCharacterizationName());
                HSSFPatriarch patriarch = sheet.createDrawingPatriarch();

                // 1. Output Characterization type at (0, 0).
                rowIndex = outputHeader(charBean, sheet, headerStyle, rowIndex);
                // 2. Output Assay Type (2, 0).
                rowIndex = outputAssayType(charBean, sheet, headerStyle, rowIndex);
                // 3. Output POC at (3, 0).
                rowIndex = outputPOC(charBean, sheet, headerStyle, rowIndex);
                // 4. Output Characterization Date at (4, 0).
                rowIndex = outputCharDate(charBean, sheet, headerStyle, rowIndex);
                // 5. Output Protocol at (5, 0).
                rowIndex = outputProtocol(charBean, sheet, headerStyle, rowIndex);
                // 6. Output Properties at (6, 0).
                rowIndex = outputProperties(charBean, sheet, headerStyle, rowIndex);
                // 7. Output Design Description at (7, 0).
                rowIndex = outputDesignDescription(charBean, sheet, headerStyle, rowIndex);
                // 8. Output Technique and Instruments at (8, 0).
                rowIndex = outputTechInstruments(charBean, sheet, headerStyle, rowIndex);
                // 9. Output Characterization Results at (9, 0).
                rowIndex = outputCharResults(charBean, downloadURL, wb, sheet, headerStyle, hlinkStyle,
                        patriarch, rowIndex);
                // 10.Output Analysis and Conclusion at (10, 0).
                rowIndex = outputConclusion(charBean, sheet, headerStyle, rowIndex);
            }
        }
    }
}

From source file:gov.nih.nci.cananolab.service.sample.impl.CompositionExporter.java

License:BSD License

/**
 * Output sample Composition Summary report =>
 * bodyCompositionSummaryView.jsp//from w  w w  . j  a v  a  2 s .  c o m
 *
 * @param compBean
 * @param wb
 */
private static void outputSummarySheet(CompositionBean compBean, String downloadURL, HSSFWorkbook wb)
        throws IOException {
    HSSFFont headerFont = wb.createFont();
    headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle headerStyle = wb.createCellStyle();
    headerStyle.setFont(headerFont);

    HSSFCellStyle hlinkStyle = wb.createCellStyle();
    HSSFFont hlinkFont = wb.createFont();
    hlinkFont.setUnderline(HSSFFont.U_SINGLE);
    hlinkFont.setColor(HSSFColor.BLUE.index);
    hlinkStyle.setFont(hlinkFont);

    int entityCount = 1;
    entityCount = outputNanomaterialEntities(compBean, wb, headerStyle, hlinkStyle, entityCount, downloadURL);

    entityCount = outputFunctionalEntities(compBean, wb, headerStyle, hlinkStyle, entityCount, downloadURL);

    entityCount = outputChemicalEntities(compBean, wb, headerStyle, hlinkStyle, entityCount, downloadURL);

    outputFilesEntities(compBean, wb, headerStyle, hlinkStyle, entityCount, downloadURL);
}

From source file:gov.nih.nci.cananolab.service.sample.impl.SampleExporter.java

License:BSD License

/**
 * Output advance sample summary report, representing,
 * bodyAdvancedSampleSearchResult.jsp//from  w ww .j  av  a 2 s . co  m
 *
 * @param searchBean
 * @param wb
 */
private static void outputSummarySheet(AdvancedSampleSearchBean searchBean,
        List<AdvancedSampleBean> sampleBeans, String viewSampleUrl, HSSFWorkbook wb) throws IOException {
    HSSFFont headerFont = wb.createFont();
    headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle headerStyle = wb.createCellStyle();
    headerStyle.setFont(headerFont);

    HSSFCellStyle hlinkStyle = wb.createCellStyle();
    HSSFFont hlinkFont = wb.createFont();
    hlinkFont.setUnderline(HSSFFont.U_SINGLE);
    hlinkFont.setColor(HSSFColor.BLUE.index);
    hlinkStyle.setFont(hlinkFont);

    int rowIndex = 0;
    HSSFSheet sheet = wb.createSheet("Advanced Sample Search Report");

    // 1.Output Search Criteria. comment out as per Sharon.
    // rowIndex = outputCriteria(searchBean, sheet, headerStyle, rowIndex);

    // 2.Output table column headers.
    rowIndex = outputHeader(sampleBeans.get(0), sheet, headerStyle, rowIndex);

    // 3.Output each table row.
    for (AdvancedSampleBean sampleBean : sampleBeans) {
        rowIndex = outputRow(sampleBean, viewSampleUrl, sheet, hlinkStyle, rowIndex);
    }
}

From source file:net.sf.jasperreports.engine.export.JRXlsExporter.java

License:Open Source License

/**
 *
 *///ww  w  .  ja v a  2 s.  c om
protected HSSFFont getLoadedFont(JRFont font, short forecolor, Map<Attribute, Object> attributes,
        Locale locale) {
    HSSFFont cellFont = null;

    String fontName = font.getFontName();

    FontInfo fontInfo = FontUtil.getInstance(jasperReportsContext).getFontInfo(fontName, locale);
    if (fontInfo != null) {
        //fontName found in font extensions
        FontFamily family = fontInfo.getFontFamily();
        String exportFont = family.getExportFont(getExporterKey());
        if (exportFont != null) {
            fontName = exportFont;
        }
    }

    short superscriptType = HSSFFont.SS_NONE;

    if (attributes != null && attributes.get(TextAttribute.SUPERSCRIPT) != null) {
        Object value = attributes.get(TextAttribute.SUPERSCRIPT);
        if (TextAttribute.SUPERSCRIPT_SUPER.equals(value)) {
            superscriptType = HSSFFont.SS_SUPER;
        } else if (TextAttribute.SUPERSCRIPT_SUB.equals(value)) {
            superscriptType = HSSFFont.SS_SUB;
        }

    }
    boolean isFontSizeFixEnabled = getCurrentItemConfiguration().isFontSizeFixEnabled();
    for (int i = 0; i < loadedFonts.size(); i++) {
        HSSFFont cf = (HSSFFont) loadedFonts.get(i);

        short fontSize = (short) font.getFontsize();
        if (isFontSizeFixEnabled) {
            fontSize -= 1;
        }
        if (cf.getFontName().equals(fontName) && (cf.getColor() == forecolor)
                && (cf.getFontHeightInPoints() == fontSize)
                && ((cf.getUnderline() == HSSFFont.U_SINGLE) ? (font.isUnderline()) : (!font.isUnderline()))
                && (cf.getStrikeout() == font.isStrikeThrough())
                && ((cf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) ? (font.isBold()) : (!font.isBold()))
                && (cf.getItalic() == font.isItalic()) && (cf.getTypeOffset() == superscriptType)) {
            cellFont = cf;
            break;
        }
    }

    if (cellFont == null) {
        cellFont = workbook.createFont();

        cellFont.setFontName(fontName);
        cellFont.setColor(forecolor);

        short fontSize = (short) font.getFontsize();
        if (isFontSizeFixEnabled) {
            fontSize -= 1;
        }
        cellFont.setFontHeightInPoints(fontSize);

        if (font.isUnderline()) {
            cellFont.setUnderline(HSSFFont.U_SINGLE);
        }
        if (font.isStrikeThrough()) {
            cellFont.setStrikeout(true);
        }
        if (font.isBold()) {
            cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        if (font.isItalic()) {
            cellFont.setItalic(true);
        }

        cellFont.setTypeOffset(superscriptType);
        loadedFonts.add(cellFont);
    }

    return cellFont;
}