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

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

Introduction

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

Prototype

byte U_SINGLE

To view the source code for org.apache.poi.ss.usermodel Font U_SINGLE.

Click Source Link

Document

single (normal) underline

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 a 2  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.StyleManagerUtils.java

License:Open Source License

/**
 * Add font details to an AttributedString.
 * @param attrString/* w ww.  jav a2  s  . c o  m*/
 * The AttributedString to modify.
 * @param font
 * The font to take attributes from.
 * @param startIdx
 * The index of the first character to be attributed (inclusive).
 * @param endIdx
 * The index of the last character to be attributed (inclusive). 
 */
protected void addFontAttributes(AttributedString attrString, Font font, int startIdx, int endIdx) {
    attrString.addAttribute(TextAttribute.FAMILY, font.getFontName(), startIdx, endIdx);
    attrString.addAttribute(TextAttribute.SIZE, (float) font.getFontHeightInPoints(), startIdx, endIdx);
    if (font.getBoldweight() == Font.BOLDWEIGHT_BOLD)
        attrString.addAttribute(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD, startIdx, endIdx);
    if (font.getItalic())
        attrString.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, startIdx, endIdx);
    if (font.getUnderline() == Font.U_SINGLE)
        attrString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, startIdx, endIdx);
}

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/* w w  w .j av  a  2s. 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);
            }
        }
    }

}