Example usage for org.apache.poi.ss.usermodel Font setUnderline

List of usage examples for org.apache.poi.ss.usermodel Font setUnderline

Introduction

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

Prototype


void setUnderline(byte underline);

Source Link

Document

set type of text underlining to use

Usage

From source file:uk.co.certait.htmlexporter.writer.excel.ExcelStyleGenerator.java

License:Apache License

public Font createFont(Workbook workbook, Style style) {
    Font font = workbook.createFont();

    if (style.isFontNameSet()) {
        font.setFontName(style.getProperty(CssStringProperty.FONT_FAMILY));
    }/*from  w w  w . ja  v  a2 s .c o  m*/

    if (style.isFontSizeSet()) {
        font.setFontHeightInPoints((short) style.getProperty(CssIntegerProperty.FONT_SIZE));
    }

    if (style.isColorSet()) {
        Color color = style.getProperty(CssColorProperty.COLOR);

        // if(! color.equals(Color.WHITE)) // POI Bug
        // {
        ((XSSFFont) font).setColor(new XSSFColor(color));
        // }
    }

    if (style.isFontBold()) {
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    }

    font.setItalic(style.isFontItalic());

    if (style.isTextUnderlined()) {
        font.setUnderline(Font.U_SINGLE);
    }

    return font;
}

From source file:uk.co.spudsoft.birt.emitters.excel.FontManager.java

License:Open Source License

/**
 * Create a new POI Font based upon a BIRT style.
 * @param birtStyle/*from   w ww  . j a  v a 2  s.co  m*/
 * The BIRT style to base the Font upon.
 * @return
 * The Font whose attributes are described by the BIRT style. 
 */
private Font createFont(BirtStyle birtStyle) {
    Font font = workbook.createFont();

    // Family
    String fontName = smu
            .poiFontNameFromBirt(cleanupQuotes(birtStyle.getProperty(StyleConstants.STYLE_FONT_FAMILY)));
    if (fontName == null) {
        fontName = "Calibri";
    }
    font.setFontName(fontName);
    // Size
    short fontSize = smu.fontSizeInPoints(cleanupQuotes(birtStyle.getProperty(StyleConstants.STYLE_FONT_SIZE)));
    if (fontSize > 0) {
        font.setFontHeightInPoints(fontSize);
    }
    // Weight
    short fontWeight = smu
            .poiFontWeightFromBirt(cleanupQuotes(birtStyle.getProperty(StyleConstants.STYLE_FONT_WEIGHT)));
    if (fontWeight > 0) {
        font.setBoldweight(fontWeight);
    }
    // Style
    String fontStyle = cleanupQuotes(birtStyle.getProperty(StyleConstants.STYLE_FONT_STYLE));
    if (CSSConstants.CSS_ITALIC_VALUE.equals(fontStyle) || CSSConstants.CSS_OBLIQUE_VALUE.equals(fontStyle)) {
        font.setItalic(true);
    }
    // Underline
    String fontUnderline = cleanupQuotes(birtStyle.getProperty(StyleConstants.STYLE_TEXT_UNDERLINE));
    if (CSSConstants.CSS_UNDERLINE_VALUE.equals(fontUnderline)) {
        font.setUnderline(FontUnderline.SINGLE.getByteValue());
    }
    // Colour
    smu.addColourToFont(workbook, font, cleanupQuotes(birtStyle.getProperty(StyleConstants.STYLE_COLOR)));

    fonts.add(new FontPair(birtStyle, font));
    return font;
}

From source file:uk.gov.ofwat.fountain.api.report.POIReportWriter.java

License:Open Source License

private void renderReport(ReportStructure reportStructure, ReportDto report) {

    Sheet sheet = workBook.createSheet();
    Map<Integer, Set<GroupEntry>> groupEntries = report.getGroupEntriesByCompany();
    inputDataNumericStyleMap = new HashMap<Short, XSSFCellStyle>();
    calcDataNumericStyleMap = new HashMap<Short, XSSFCellStyle>();

    yellow = new XSSFColor(new java.awt.Color(255, 255, 0));
    lightYellow = new XSSFColor(new java.awt.Color(255, 255, 224));
    lightBlue = new XSSFColor(new java.awt.Color(224, 255, 255));

    // Styles//ww  w  .ja v a 2  s.c o m
    // Row header style
    rowHeaderStyle = workBook.createCellStyle();
    // Col header style
    colHeaderStyle = workBook.createCellStyle();
    colHeaderStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    colHeaderStyle.setFillForegroundColor(yellow);
    Font colHeaderFont = workBook.createFont();
    colHeaderFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    colHeaderStyle.setFont(colHeaderFont);
    // Input numeric Data cell style
    inputDataNumericStyle = workBook.createCellStyle();
    inputDataNumericStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    inputDataNumericStyle.setFillForegroundColor(lightYellow);
    // Calc numeric Data cell style
    calcDataNumericStyle = workBook.createCellStyle();
    calcDataNumericStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    calcDataNumericStyle.setFillForegroundColor(lightBlue);
    // Input text data cell style
    inputDataTextStyle = workBook.createCellStyle();
    inputDataTextStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    inputDataTextStyle.setFillForegroundColor(lightYellow);
    // Calc text data cell style
    calcDataTextStyle = workBook.createCellStyle();
    calcDataTextStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    calcDataTextStyle.setFillForegroundColor(lightBlue);
    // Input CG style
    inputCGStyle = workBook.createCellStyle();
    inputCGStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    inputCGStyle.setFillForegroundColor(lightYellow);
    // Calc CG style
    calcCGStyle = workBook.createCellStyle();
    calcCGStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
    calcCGStyle.setFillForegroundColor(lightBlue);

    // data format
    DataFormat format = workBook.createDataFormat();

    int rownum = 1; // starting point
    Row infoRow = sheet.createRow(rownum);
    Cell titleCell = infoRow.createCell(2);
    titleCell.setCellType(Cell.CELL_TYPE_STRING);
    String title = reportStructure.getReportName();
    RichTextString rts = creationHelper.createRichTextString(title);
    titleCell.setCellValue(rts);
    XSSFCellStyle style = workBook.createCellStyle();
    Font font = workBook.createFont();
    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
    font.setUnderline(Font.U_SINGLE);
    style.setFont(font);
    titleCell.setCellStyle(style);

    Cell dateCell = infoRow.createCell(4);
    dateCell.setCellType(Cell.CELL_TYPE_STRING);
    String DATE_FORMAT = "dd MMM yyyy H:mm";
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    Calendar c1 = Calendar.getInstance(); // today
    String today = sdf.format(c1.getTime());
    RichTextString dateRts = creationHelper.createRichTextString("Run on " + today);
    dateCell.setCellValue(dateRts);
    dateCell.setCellStyle(style);

    rownum++;
    rownum++;

    ReportDefinition reportDefinition = reportService.getReportDefinition(report.getId());

    if (reportStructure.isCompanyAcrossTop()) {
        for (ReportLine line : reportStructure.getLines()) {
            // get the group entries for this line
            // ungrouped line
            Row row = sheet.createRow(rownum);
            rownum++;
            List<ReportCell> nonRepeatHeaderCells = new ArrayList<ReportCell>();
            writeLine(line, report, workBook, row, format, null, nonRepeatHeaderCells, groupEntries,
                    reportDefinition);
        }
    } else {
        for (ReportLine line : reportStructure.getLines()) {
            // get the group entries for this line
            Set<GroupEntry> groupEntrySet = null;
            for (ReportCell cell : line.getCells()) {
                if (cell.getCellType() == CellType.CALC || cell.getCellType() == CellType.INPUT) {
                    String id = cell.getCellContents();
                    DataKey key = new DataKey(id);
                    // get the company
                    if (report.getCompany() != null) {
                        // interchangable company. A single company supplied with data rather than with the report template.
                        groupEntrySet = groupEntries.get(report.getCompany().getId());
                    } else {
                        // get the company for this line
                        groupEntrySet = groupEntries.get(key.getCompanyIdInteger());
                    }
                    break;
                }
            }
            if (null != groupEntrySet) {
                // group line
                List<ReportCell> nonRepeatHeaderCells = new ArrayList<ReportCell>();
                for (GroupEntry ge : groupEntrySet) {
                    Row row = sheet.createRow(rownum);
                    rownum++;
                    writeLine(line, report, workBook, row, format, ge, nonRepeatHeaderCells, null,
                            reportDefinition);
                }
            } else {
                // ungrouped line
                Row row = sheet.createRow(rownum);
                rownum++;
                writeLine(line, report, workBook, row, format, null, null, null, reportDefinition);
            }
        }
    }

}