Example usage for org.apache.poi.xssf.usermodel XSSFFont setUnderline

List of usage examples for org.apache.poi.xssf.usermodel XSSFFont setUnderline

Introduction

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

Prototype

public void setUnderline(FontUnderline underline) 

Source Link

Document

set an enumeration representing the style of underlining that is used.

Usage

From source file:poi.xssf.usermodel.examples.WorkingWithRichText.java

License:Apache License

public static void main(String[] args) throws Exception {

    XSSFWorkbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();

    XSSFSheet sheet = wb.createSheet();//from ww  w.ja  v  a  2  s .  c  om
    XSSFRow row = sheet.createRow((short) 2);

    XSSFCell cell = row.createCell(1);
    XSSFRichTextString rt = new XSSFRichTextString("The quick brown fox");

    XSSFFont font1 = wb.createFont();
    font1.setBold(true);
    font1.setColor(new XSSFColor(new java.awt.Color(255, 0, 0)));
    rt.applyFont(0, 10, font1);

    XSSFFont font2 = wb.createFont();
    font2.setItalic(true);
    font2.setUnderline(XSSFFont.U_DOUBLE);
    font2.setColor(new XSSFColor(new java.awt.Color(0, 255, 0)));
    rt.applyFont(10, 19, font2);

    XSSFFont font3 = wb.createFont();
    font3.setColor(new XSSFColor(new java.awt.Color(0, 0, 255)));
    rt.append(" Jumped over the lazy dog", font3);

    cell.setCellValue(rt);

    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("xssf-richtext.xlsx");
    wb.write(fileOut);
    fileOut.close();
}

From source file:se.inera.intyg.rehabstod.service.export.xlsx.XlsxExportServiceImpl.java

License:Open Source License

private XSSFFont buildFont(XSSFWorkbook wb, int heightInPoints, String fontName, boolean bold,
        boolean underline) {
    XSSFFont font = wb.createFont();
    font.setFontHeightInPoints((short) heightInPoints);
    font.setFontName(fontName);//from   ww w.  j a  va2  s.  c  o  m
    font.setColor(IndexedColors.BLACK.getIndex());
    font.setBold(bold);
    font.setBoldweight(bold ? Font.BOLDWEIGHT_BOLD : Font.BOLDWEIGHT_NORMAL);
    font.setUnderline(underline ? XSSFFont.U_SINGLE : XSSFFont.U_NONE);
    return font;
}

From source file:step.datapool.excel.StyleSyntax.java

License:Open Source License

/**
 * Analysiert den angegebenen Stil und setzt diesen excel-konform.
 * // w  w  w  .  ja  va2 s.  co m
 * @param strStyle strStyle
 * @param _wb _wb
 * @return XSSFCellStyle
 */
public static XSSFCellStyle composeStyle(String strStyle, Workbook _wb) {
    if (_wb instanceof XSSFWorkbook) {
        XSSFWorkbook wb = (XSSFWorkbook) _wb;
        if (strStyle == null || strStyle.isEmpty())
            return null;
        XSSFCellStyle style = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        strStyle = replaceColors(strStyle);

        /* Unterteilung der verschiedenen Stilangaben: Schriftschnitt, Vordergrund/Hintergrundfarbe, Schriftgroesse, Schriftsatz */
        String[] arr = strStyle.split(",");
        for (String str : arr) {
            /* Abhandlung des Schriftschnitts. Diese koennen alle zusammen auftreten und schliessen sich nicht aus */
            if (str.matches("( *bold *| *italic *| *underline *| *strikeout *)*")) {
                if (str.contains("bold")) {
                    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
                }
                if (str.contains("italic")) {
                    font.setItalic(true);
                }
                if (str.contains("underline")) {
                    font.setUnderline(Font.U_SINGLE);
                }
                if (str.contains("strikeout")) {
                    font.setStrikeout(true);
                }
                continue;
            }
            /* Abhandlung der Farben */
            if (str.contains("/") && !str.contains(":")) {
                continue;
            }
            if (str.contains(":")) {
                String[] fgBg;
                /* Vordergrund / Hintergrund */
                if (str.contains("/")) {
                    fgBg = str.split("/");
                } else {
                    /* Verkuerzte Angabe ohne / (nur Vordergrund) */
                    fgBg = new String[1];
                    fgBg[0] = str;
                }

                for (int i = 0; i < fgBg.length; i++) {
                    fgBg[i] = fgBg[i].trim();
                    if (!fgBg[i].isEmpty()) {
                        String[] clr = fgBg[i].split(":");
                        if (clr.length != 3) {
                            return null;
                        }
                        int red = Integer.parseInt(clr[0].trim());
                        int green = Integer.parseInt(clr[1].trim());
                        int blue = Integer.parseInt(clr[2].trim());

                        if (i == 0) {
                            /* Schriftfarbe
                             *  -------------------------------------------------------------
                             * | ACHTUNG: poi hat einen Fehler beim Setzen der Schriftfarbe! |
                             *  -------------------------------------------------------------
                             *  Weiss und Schwarz sind verwechselt worden! Gilt NUR fuer
                             *  font.setColor!
                             *  Deshalb wird hier einfach Weiss auf Schwarz korrigiert und
                             *  umgekehrt.
                             */
                            if (red == 0 && green == 0 && blue == 0) {
                                red = 255;
                                green = 255;
                                blue = 255;
                            } else if (red == 255 && green == 255 && blue == 255) {
                                red = 0;
                                green = 0;
                                blue = 0;
                            }
                            XSSFColor xssfColor = new XSSFColor(new Color(red, green, blue));
                            font.setColor(xssfColor);
                        } else {
                            // Vordergrund/Hintergrundfarbe der Zelle
                            XSSFColor xssfColor = new XSSFColor(new Color(red, green, blue));
                            style.setFillForegroundColor(xssfColor);
                            style.setFillBackgroundColor(xssfColor);
                            style.setFillPattern(CellStyle.SOLID_FOREGROUND);
                        }

                    }
                }
                continue;
            }
            /* Abhandlung der Schriftgroesse */
            if (str.matches(" *[1-9][0-9]* *")) {
                short fontHeightInPoints = Short.parseShort(str.trim());
                font.setFontHeightInPoints(fontHeightInPoints);
                continue;
            }
            /* Abhandlung der Schriftart */
            if (!str.isEmpty()) {
                font.setFontName(str);
                continue;
            }
        }
        style.setFont(font);
        return style;
    } else {
        return null;
    }
}