List of usage examples for org.apache.poi.xssf.usermodel XSSFFont setStrikeout
public void setStrikeout(boolean strikeout)
From source file:com.hauldata.dbpa.file.book.XlsxTargetSheet.java
License:Apache License
private static Font getFont(FontStyles fontStyles, SXSSFWorkbook book, Map<FontStyles, XSSFFont> fontsUsed, Map<Integer, XSSFColor> colorsUsed) { XSSFFont font = fontsUsed.get(fontStyles); if (font != null) { return font; }//w w w.j av a2 s .c om font = (XSSFFont) book.createFont(); if (fontStyles.color != null) { font.setColor(getColor(fontStyles.color, book, colorsUsed)); } if (fontStyles.fontStyle != null) { switch (fontStyles.fontStyle) { case NORMAL: break; case ITALIC: font.setItalic(true); break; } } if (fontStyles.fontWeight != null) { switch (fontStyles.fontWeight) { case NORMAL: break; case BOLD: font.setBold(true); break; } } if (fontStyles.textDecorationLine != null) { switch (fontStyles.textDecorationLine) { case NONE: break; case LINE_THROUGH: font.setStrikeout(true); break; case UNDERLINE: font.setUnderline((fontStyles.textDecorationStyle == FontStyles.TextDecorationStyle.DOUBLE) ? FontUnderline.DOUBLE : FontUnderline.SINGLE); break; } } fontsUsed.put(fontStyles, font); return font; }
From source file:net.mcnewfamily.rmcnew.model.excel.FontEssence.java
License:Open Source License
public XSSFFont toXSSFFont(XSSFWorkbook workbook) { XSSFFont xssfFont = null; if (workbook != null) { xssfFont = workbook.createFont(); xssfFont.setCharSet(FontCharset.DEFAULT); xssfFont.setFamily(this.fontFamily); xssfFont.setBold(this.bold); if (this.bold) { xssfFont.setBoldweight(Font.BOLDWEIGHT_BOLD); } else {//from www. ja v a 2 s . c o m xssfFont.setBoldweight(Font.BOLDWEIGHT_NORMAL); } xssfFont.setItalic(this.italic); if (this.underline) { xssfFont.setUnderline(FontUnderline.SINGLE); } xssfFont.setStrikeout(this.strikeout); xssfFont.setColor(this.color); xssfFont.setFontHeightInPoints(this.fontHeightInPoints); } else { throw new IllegalArgumentException("Cannot create XSSFFont in a null XSSFWorkbook!"); } return xssfFont; }
From source file:org.jkiss.dbeaver.data.office.export.DataExporterXLSX.java
License:Apache License
@Override public void init(IStreamDataExporterSite site) throws DBException { Object nullStringProp = site.getProperties().get(PROP_NULL_STRING); nullString = nullStringProp == null ? null : nullStringProp.toString(); try {// w w w . j a va 2 s . co m printHeader = (Boolean) site.getProperties().get(PROP_HEADER); } catch (Exception e) { printHeader = false; } try { rowNumber = (Boolean) site.getProperties().get(PROP_ROWNUMBER); } catch (Exception e) { rowNumber = false; } try { boolTrue = (String) site.getProperties().get(PROP_TRUESTRING); } catch (Exception e) { boolTrue = "true"; } try { boolFalse = (String) site.getProperties().get(PROP_FALSESTRING); } catch (Exception e) { boolFalse = "false"; } if (!"true".equals(boolTrue) || !"false".equals(boolFalse)) { booleRedefined = true; } try { exportSql = (Boolean) site.getProperties().get(PROP_EXPORT_SQL); } catch (Exception e) { exportSql = false; } try { splitSqlText = (Boolean) site.getProperties().get(PROP_SPLIT_SQLTEXT); } catch (Exception e) { splitSqlText = false; } try { splitByRowCount = (Integer) site.getProperties().get(PROP_SPLIT_BYROWCOUNT); } catch (Exception e) { splitByRowCount = EXCEL2007MAXROWS; } try { splitByCol = (Integer) site.getProperties().get(PROP_SPLIT_BYCOL); } catch (Exception e) { splitByCol = -1; } wb = new SXSSFWorkbook(ROW_WINDOW); worksheets = new HashMap<>(1); styleHeader = (XSSFCellStyle) wb.createCellStyle(); BorderStyle border; try { border = BorderStyle.valueOf((String) site.getProperties().get(PROP_BORDER)); } catch (Exception e) { border = BorderStyle.NONE; } FontStyleProp fontStyle; try { fontStyle = FontStyleProp.valueOf((String) site.getProperties().get(PROP_HEADER_FONT)); } catch (Exception e) { fontStyle = FontStyleProp.NONE; } styleHeader.setBorderTop(border); styleHeader.setBorderBottom(border); styleHeader.setBorderLeft(border); styleHeader.setBorderRight(border); XSSFFont fontBold = (XSSFFont) wb.createFont(); switch (fontStyle) { case BOLD: fontBold.setBold(true); break; case ITALIC: fontBold.setItalic(true); break; case STRIKEOUT: fontBold.setStrikeout(true); break; case UNDERLINE: fontBold.setUnderline((byte) 3); break; default: break; } styleHeader.setFont(fontBold); style = (XSSFCellStyle) wb.createCellStyle(); style.setBorderTop(border); style.setBorderBottom(border); style.setBorderLeft(border); style.setBorderRight(border); this.rowCount = 0; super.init(site); }
From source file:step.datapool.excel.StyleSyntax.java
License:Open Source License
/** * Analysiert den angegebenen Stil und setzt diesen excel-konform. * /*w w w .j a v a2s.c o 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; } }