List of usage examples for org.apache.poi.xssf.usermodel XSSFCellStyle getFillForegroundXSSFColor
public XSSFColor getFillForegroundXSSFColor()
From source file:cc.landking.converter.office.excel.XSSFHtmlHelper.java
License:Apache License
public void colorStyles(CellStyle style, Formatter out) { XSSFCellStyle cs = (XSSFCellStyle) style; styleColor(out, "background-color", cs.getFillForegroundXSSFColor()); styleColor(out, "text-color", cs.getFont().getXSSFColor()); }
From source file:com.tutorial.excelreadwrite.excelFunctions.java
public void convertColor(int r, int g, int b, int numColors) { //Get the userDefinedColor and set the style userDefinedColor = new XSSFColor(new java.awt.Color(r, g, b)); XSSFCellStyle userDefinedCS = workbook.createCellStyle(); userDefinedCS.setFillForegroundColor(userDefinedColor); userDefinedCS.setFillPattern(CellStyle.SOLID_FOREGROUND); //Create an arrayList and add foreground colors that will be converted and then remove them List<XSSFColor> listOfColors = new ArrayList(); for (int i = 0; i < numColors; ++i) { try { //First row of excel document will be reserved for obtaining the colors of the foreground used listOfColors.add(sheet.getRow(0).getCell(i).getCellStyle().getFillForegroundXSSFColor()); sheet.getRow(0).getCell(i).setCellStyle(null); } catch (NullPointerException ex) { throw new NullPointerException("Either incorrect # colors entered OR colors NOT SET."); }//from w ww . j a v a 2s .c o m } //Set-up rowIterator and get Row Iterator<Row> rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); //Set-up cellIterator and get Cell Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); //Null-Check for Cell if (cell != null) { //Get the Cell Style, Null-Check for Cell Style XSSFCellStyle currCellStyle = (XSSFCellStyle) cell.getCellStyle(); if (currCellStyle != null) { //Get the fillForeground color XSSFColor fgColor = currCellStyle.getFillForegroundXSSFColor(); //cycle through ArrayList and compare if any of the colors listed matches for (XSSFColor col : listOfColors) { if (col.equals(fgColor)) { cell.setCellStyle(userDefinedCS); } } } } } } }
From source file:com.tutorial.excelreadwrite.excelFunctions.java
public void markHorizontal(int spacesApart){ //Set-up rowIterator and get Row Iterator<Row> rowIterator = sheet.iterator(); while(rowIterator.hasNext()){ Row row = rowIterator.next(); //w w w.j a v a 2s. c om //Set-up cellIterator and get Cell Iterator<Cell> cellIterator = row.cellIterator(); while(cellIterator.hasNext()){ Cell cell = cellIterator.next(); //Obtains the Cell Style XSSFCellStyle cellStyle = (XSSFCellStyle)cell.getCellStyle(); //Checks to see if the Cell Style is null; if null, go to next cell if(cellStyle != null){ //Checks to see what color is the cell's color XSSFColor cellColor = cellStyle.getFillForegroundXSSFColor(); //Checks to see if color is null; if not compare to accept only editted or userDefined cells if(cellColor != null){ //Checks if current cell is userDefined or editted //If it is not, then go to the next cell if(cellColor.equals(mark.getFillForegroundXSSFColor()) || cellColor.equals(userDefinedColor)){ //Set boolean isCellMarked to false before proceeding isCellMarked = false; //Define Cell to be (spacesApart+1) away //So if x = current cell then the cell that is 5 spacesApart = // [x][][][][][][x] Cell cellMark = sheet.getRow(cell.getRowIndex()).getCell(cell.getColumnIndex() + spacesApart + 1); //Checks to see if cell is null; if present, get its Cell Style if(cellMark != null){ XSSFCellStyle cellMarkStyle = (XSSFCellStyle)cellMark.getCellStyle(); //Checks to see if the style is null; if present, get its color if(cellMarkStyle != null){ XSSFColor cellMarkColor = cellMarkStyle.getFillForegroundXSSFColor(); //Checks to see if the color is null; if present, compare colors if(cellMarkColor != null){ if(cellMarkColor.equals(userDefinedColor)){ isCellMarked = true; } } } } /* ** CHECK#1: 'isCellMarked' ** If isCellMarked is marked true, start iterating through the ** cells in between and check if null or not userDefinedStyle */ if(isCellMarked == true){ for(int i = 1; i <= spacesApart; ++i){ Cell isNull = sheet.getRow(cell.getRowIndex()).getCell(cell.getColumnIndex()+i); //Checks to see if the cell is null; if color is present, set isCellMarked to false if(isNull != null){ XSSFCellStyle cellCheckIfNullCellStyle = (XSSFCellStyle)isNull.getCellStyle(); if(cellCheckIfNullCellStyle != null){ XSSFColor cellCheckIfNullColor = cellCheckIfNullCellStyle.getFillForegroundXSSFColor(); if(cellCheckIfNullColor != null){ if(cellCheckIfNullColor.equals(userDefinedColor)){ isCellMarked = false; break; } } } } } } /* ** CHECK#2: 'isCellMarked2' ** If isCellMarked remains as true, set the two cell's style */ if(isCellMarked == true){ cell.setCellStyle(mark); cellMark.setCellStyle(mark); } } } } } } }
From source file:com.vaadin.addon.spreadsheet.XSSFColorConverter.java
License:Open Source License
@Override public void colorStyles(CellStyle cellStyle, StringBuilder sb) { XSSFCellStyle cs = (XSSFCellStyle) cellStyle; XSSFColor fillBackgroundXSSFColor = cs.getFillBackgroundXSSFColor(); XSSFColor fillForegroundXSSFColor = cs.getFillForegroundXSSFColor(); String backgroundColor = null; if (fillForegroundXSSFColor != null && !fillForegroundXSSFColor.isAuto()) { backgroundColor = styleColor(fillForegroundXSSFColor); } else if (fillBackgroundXSSFColor != null && !fillBackgroundXSSFColor.isAuto()) { backgroundColor = styleColor(fillBackgroundXSSFColor); } else {//from ww w . ja v a2 s . c o m // bypass POI API and try to get the fill ourself, because of bug: // https://issues.apache.org/bugzilla/show_bug.cgi?id=53262 try { XSSFColor themeColor = getFillColor(cs); if (themeColor != null && !themeColor.isAuto()) { backgroundColor = styleColor(themeColor); } } catch (Exception e) { LOGGER.log(Level.FINEST, e.getMessage(), e); } } if (backgroundColor != null && !backgroundColor.equals(defaultBackgroundColor)) { sb.append("background-color:"); sb.append(backgroundColor); } XSSFColor xssfColor = cs.getFont().getXSSFColor(); if (xssfColor != null) { String color = styleColor(xssfColor); if (color != null && !color.equals(defaultColor)) { sb.append("color:"); sb.append(color); } } }
From source file:com.vaadin.addon.spreadsheet.XSSFColorConverter.java
License:Open Source License
@Override public boolean hasBackgroundColor(CellStyle cellStyle) { XSSFCellStyle cs = (XSSFCellStyle) cellStyle; XSSFColor fillBackgroundXSSFColor = cs.getFillBackgroundXSSFColor(); XSSFColor fillForegroundXSSFColor = cs.getFillForegroundXSSFColor(); if (fillForegroundXSSFColor != null && !fillForegroundXSSFColor.isAuto()) { return true; } else if (fillBackgroundXSSFColor != null && !fillBackgroundXSSFColor.isAuto()) { return true; } else {//w w w . j av a 2 s .com // bypass POI API and try to get the fill ourself, because of bug: // https://issues.apache.org/bugzilla/show_bug.cgi?id=53262 try { XSSFColor themeColor = getFillColor(cs); if (themeColor != null && !themeColor.isAuto()) { return true; } } catch (Exception e) { LOGGER.log(Level.FINEST, e.getMessage(), e); } } return false; }
From source file:de.escnet.ExcelTable.java
License:Open Source License
private void styleBackground(Map<String, String> styles, XSSFCell cell) { XSSFCellStyle cellStyle = cell.getCellStyle(); if (cellStyle != null) { XSSFColor xssf = cellStyle.getFillForegroundXSSFColor(); if (xssf != null) { String color = getHtmlColor(xssf); if (color != null && !color.equals("#ffffff")) { styles.put("background-color", color); }/* w w w . ja va2s.co m*/ } } }
From source file:org.apache.metamodel.excel.XlsxSheetToRowsHandler.java
License:Apache License
private void configureStyle(XSSFCellStyle style) { XSSFFont font = style.getFont();/*from w ww . ja v a2 s . c o m*/ if (font.getBold()) { _style.bold(); } if (font.getItalic()) { _style.italic(); } if (font.getUnderline() != FontUnderline.NONE.getByteValue()) { _style.underline(); } if (style.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) { XSSFColor fillForegroundXSSFColor = style.getFillForegroundXSSFColor(); String argb = fillForegroundXSSFColor.getARGBHex(); if (argb != null) { _style.background(argb.substring(2)); } } final XSSFFont stdFont = _stylesTable.getStyleAt(0).getFont(); final short fontHeight = style.getFont().getFontHeightInPoints(); if (stdFont.getFontHeightInPoints() != fontHeight) { _style.fontSize(fontHeight, SizeUnit.PT); } XSSFColor fontColor = style.getFont().getXSSFColor(); if (fontColor != null) { String argbHex = fontColor.getARGBHex(); if (argbHex != null) { _style.foreground(argbHex.substring(2)); } } switch (style.getAlignmentEnum()) { case LEFT: _style.leftAligned(); break; case RIGHT: _style.rightAligned(); break; case CENTER: _style.centerAligned(); break; case JUSTIFY: _style.justifyAligned(); break; default: // do nothing break; } }
From source file:org.bbreak.excella.core.test.util.TestUtil.java
License:Open Source License
private static String getCellStyleString(XSSFCellStyle cellStyle) { StringBuffer sb = new StringBuffer(); if (cellStyle != null) { XSSFFont font = cellStyle.getFont(); sb.append("Font=").append(font.getCTFont()).append(","); sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(","); sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(","); sb.append("Hidden=").append(cellStyle.getHidden()).append(","); sb.append("Locked=").append(cellStyle.getLocked()).append(","); sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(","); sb.append("WrapText=").append(cellStyle.getWrapText()).append(","); sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(","); sb.append("Rotation=").append(cellStyle.getRotation()).append(","); sb.append("Indention=").append(cellStyle.getIndention()).append(","); sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(","); sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(","); sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(","); sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(","); sb.append("LeftBorderColor=").append(getXSSFColorString(cellStyle.getLeftBorderXSSFColor())) .append(","); sb.append("RightBorderColor=").append(getXSSFColorString(cellStyle.getRightBorderXSSFColor())) .append(","); sb.append("TopBorderColor=").append(getXSSFColorString(cellStyle.getTopBorderXSSFColor())).append(","); sb.append("BottomBorderColor=").append(getXSSFColorString(cellStyle.getBottomBorderXSSFColor())) .append(","); sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(","); sb.append("FillForegroundColor=").append(getXSSFColorString(cellStyle.getFillForegroundXSSFColor())) .append(","); sb.append("FillBackgroundColor=").append(getXSSFColorString(cellStyle.getFillBackgroundXSSFColor())); }//w w w . j av a 2s.c o m return sb.toString(); }
From source file:org.bbreak.excella.reports.ReportsTestUtil.java
License:Open Source License
/** * XSSF????//from w ww . j a v a 2 s . c om * * @param cellStyle * @return ?? */ private static String getCellStyleString(XSSFCellStyle cellStyle) { StringBuffer sb = new StringBuffer(); if (cellStyle != null) { XSSFFont font = cellStyle.getFont(); sb.append("Font=").append(font.getCTFont()).append(","); sb.append("DataFormat=").append(cellStyle.getDataFormat()).append(","); sb.append("DataFormatString=").append(cellStyle.getDataFormatString()).append(","); sb.append("Hidden=").append(cellStyle.getHidden()).append(","); sb.append("Locked=").append(cellStyle.getLocked()).append(","); sb.append("Alignment=").append(cellStyle.getAlignmentEnum()).append(","); sb.append("WrapText=").append(cellStyle.getWrapText()).append(","); sb.append("VerticalAlignment=").append(cellStyle.getVerticalAlignmentEnum()).append(","); sb.append("Rotation=").append(cellStyle.getRotation()).append(","); sb.append("Indention=").append(cellStyle.getIndention()).append(","); sb.append("BorderLeft=").append(cellStyle.getBorderLeftEnum()).append(","); sb.append("BorderRight=").append(cellStyle.getBorderRightEnum()).append(","); sb.append("BorderTop=").append(cellStyle.getBorderTopEnum()).append(","); sb.append("BorderBottom=").append(cellStyle.getBorderBottomEnum()).append(","); sb.append("LeftBorderColor=").append(getXSSFColorString(cellStyle.getLeftBorderXSSFColor())) .append(","); sb.append("RightBorderColor=").append(getXSSFColorString(cellStyle.getRightBorderXSSFColor())) .append(","); sb.append("TopBorderColor=").append(getXSSFColorString(cellStyle.getTopBorderXSSFColor())).append(","); sb.append("BottomBorderColor=").append(getXSSFColorString(cellStyle.getBottomBorderXSSFColor())) .append(","); sb.append("FillPattern=").append(cellStyle.getFillPatternEnum()).append(","); try { sb.append("FillForegroundColor=").append(getXSSFColorString(cellStyle.getFillForegroundXSSFColor())) .append(","); } catch (NullPointerException e) { // POI-3.7??? sb.append("FillForegroundColor=none,"); } try { sb.append("FillBackgroundColor=") .append(getXSSFColorString(cellStyle.getFillBackgroundXSSFColor())); } catch (NullPointerException e) { // POI-3.7??? sb.append("FillBackgroundColor=none,"); } } return sb.toString(); }
From source file:org.sysmodb.xml.XSSFXMLStyleHelper.java
License:BSD License
public String getBGColour(CellStyle style) { XSSFCellStyle newStyle = (XSSFCellStyle) style; XSSFColor colour = newStyle.getFillForegroundXSSFColor(); return getRGBString(colour); }