List of usage examples for org.apache.poi.xssf.usermodel XSSFColor getARGBHex
public String getARGBHex()
From source file:com.cn.led.Grid.java
private java.awt.Color poiColor2awtColor(org.apache.poi.ss.usermodel.Color color) { java.awt.Color awtColor = null; if (color instanceof XSSFColor) { //.xlsx XSSFColor xc = (XSSFColor) color; String rgbHex = xc.getARGBHex(); if (rgbHex != null) { awtColor = new Color(Integer.parseInt(rgbHex.substring(2), 16)); }//from w ww . j a v a 2s. c om } else if (color instanceof HSSFColor) { //.xls HSSFColor hc = (HSSFColor) color; short[] s = hc.getTriplet(); if (s != null) { awtColor = new Color(s[0], s[1], s[2]); } } return awtColor; }
From source file:org.apache.metamodel.excel.XlsxSheetToRowsHandler.java
License:Apache License
private void configureStyle(XSSFCellStyle style) { XSSFFont font = style.getFont();//from w ww.j av 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.drugepi.table.ExcelUtils.java
License:Mozilla Public License
private static boolean cellIsColor(Cell cell, ColorRepresentation color) { if (cell == null) return false; CellStyle style = cell.getCellStyle(); Color bgColor = style.getFillForegroundColorColor(); if (bgColor instanceof XSSFColor) { XSSFColor xssfBgColor = (XSSFColor) bgColor; // System.out.printf("Cell color is %s index is %d %d\n", xssfBgColor.getARGBHex(), xssfBgColor.getRgb()[0], xssfBgColor.getIndexed()); return xssfBgColor.getARGBHex().equalsIgnoreCase(color.xssfArgb); } else if (bgColor instanceof HSSFColor) { HSSFColor hssfBgColor = (HSSFColor) bgColor; // System.out.printf("Cell color is %s\n", hssfBgColor.getHexString()); return hssfBgColor.getHexString().equalsIgnoreCase(color.hssfHexString); } else/*from w w w . ja v a2s.c o m*/ return false; }
From source file:org.sysmodb.xml.XSSFXMLStyleHelper.java
License:BSD License
private String getRGBString(XSSFColor colour) { String string = null;/*from w ww .j a v a2 s .co m*/ // Disregard default/automatic colours, to avoid cluttering XML if (colour == null || colour.isAuto()) { return string; } else { String rgb = colour.getARGBHex(); // XSSF has a bug where the above can sometimes return null // so we check here if (rgb != null) { if (rgb.length() > 6) rgb = rgb.substring(2, rgb.length()); string = "#" + rgb; } } return string; }
From source file:ru.icc.cells.ssdc.DataLoader.java
License:Apache License
private void fillCellStyle(CStyle cellStyle, CellStyle excelCellStyle) { Font excelFont = workbook.getFontAt(excelCellStyle.getFontIndex()); // TODO CFont newFont(excelFont) //CFont font = new CFont(); //cellStyle.setFont( font ); CFont font = cellStyle.getFont();//w w w . j ava2s .c om fillFont(font, excelFont); cellStyle.setHidden(excelCellStyle.getHidden()); cellStyle.setLocked(excelCellStyle.getLocked()); cellStyle.setWrapped(excelCellStyle.getWrapText()); cellStyle.setIndention(excelCellStyle.getIndention()); cellStyle.setRotation(excelCellStyle.getRotation()); cellStyle.setHorzAlignment(this.getHorzAlignment(excelCellStyle.getAlignment())); cellStyle.setVertAlignment(this.getVertAlignment(excelCellStyle.getVerticalAlignment())); CBorder leftBorder = cellStyle.getLeftBorder(); CBorder rightBorder = cellStyle.getRightBorder(); CBorder topBorder = cellStyle.getTopBorder(); CBorder bottomBorder = cellStyle.getBottomBorder(); BorderType lbType = this.convertBorderType(excelCellStyle.getBorderLeft()); BorderType rbType = this.convertBorderType(excelCellStyle.getBorderRight()); BorderType tbType = this.convertBorderType(excelCellStyle.getBorderTop()); BorderType bbType = this.convertBorderType(excelCellStyle.getBorderBottom()); leftBorder.setType(lbType); rightBorder.setType(rbType); topBorder.setType(tbType); bottomBorder.setType(bbType); // "Fill Background Color" ???, ??, // ? ??? . ? . // "Fill Foreground Color" XSSFColor bgColor = (XSSFColor) excelCellStyle.getFillBackgroundColorColor(); // ? Index 64, ? , , // ? ? null ? if (null != bgColor && 64 != bgColor.getIndexed()) { String bgColorHexRGB = bgColor.getARGBHex().substring(2); cellStyle.setBgColor(new CColor(bgColorHexRGB)); } // "Fill Background Color" ??, // ? ??? . XSSFColor fgColor = (XSSFColor) excelCellStyle.getFillForegroundColorColor(); if (null != fgColor && 64 != fgColor.getIndexed()) { String fgColorHexRGB = fgColor.getARGBHex().substring(2); cellStyle.setFgColor(new CColor(fgColorHexRGB)); } // TODO }
From source file:uk.co.spudsoft.birt.emitters.excel.tests.NestedTables2ReportTest.java
License:Open Source License
@Test public void testRunReport() throws BirtException, IOException { InputStream inputStream = runAndRenderReport("NestedTables2.rptdesign", "xlsx"); assertNotNull(inputStream);/*from w w w. j a va2 s . com*/ try { XSSFWorkbook workbook = new XSSFWorkbook(inputStream); assertNotNull(workbook); assertEquals(1, workbook.getNumberOfSheets()); assertEquals("Nested Tables Test Report", workbook.getSheetAt(0).getSheetName()); Sheet sheet = workbook.getSheetAt(0); assertEquals(12, firstNullRow(sheet)); assertEquals(1, sheet.getRow(0).getCell(0).getNumericCellValue(), 0.0); assertEquals(1, sheet.getRow(0).getCell(1).getNumericCellValue(), 0.0); assertEquals(2, sheet.getRow(1).getCell(0).getNumericCellValue(), 0.0); assertEquals(2, sheet.getRow(1).getCell(1).getNumericCellValue(), 0.0); assertEquals(3, sheet.getRow(2).getCell(0).getNumericCellValue(), 0.0); assertEquals(3, sheet.getRow(2).getCell(1).getNumericCellValue(), 0.0); assertEquals(1, sheet.getRow(3).getCell(0).getNumericCellValue(), 0.0); assertEquals(2, sheet.getRow(3).getCell(1).getNumericCellValue(), 0.0); assertEquals(3, sheet.getRow(3).getCell(2).getNumericCellValue(), 0.0); assertEquals(2, sheet.getRow(4).getCell(0).getNumericCellValue(), 0.0); assertEquals(2, sheet.getRow(4).getCell(1).getNumericCellValue(), 0.0); assertEquals(4, sheet.getRow(5).getCell(0).getNumericCellValue(), 0.0); assertEquals(4, sheet.getRow(5).getCell(1).getNumericCellValue(), 0.0); assertEquals(6, sheet.getRow(6).getCell(0).getNumericCellValue(), 0.0); assertEquals(6, sheet.getRow(6).getCell(1).getNumericCellValue(), 0.0); assertEquals(2, sheet.getRow(7).getCell(0).getNumericCellValue(), 0.0); assertEquals(4, sheet.getRow(7).getCell(1).getNumericCellValue(), 0.0); assertEquals(6, sheet.getRow(7).getCell(2).getNumericCellValue(), 0.0); assertEquals(3, sheet.getRow(8).getCell(0).getNumericCellValue(), 0.0); assertEquals(3, sheet.getRow(8).getCell(1).getNumericCellValue(), 0.0); assertEquals(6, sheet.getRow(9).getCell(0).getNumericCellValue(), 0.0); assertEquals(6, sheet.getRow(9).getCell(1).getNumericCellValue(), 0.0); assertEquals(9, sheet.getRow(10).getCell(0).getNumericCellValue(), 0.0); assertEquals(9, sheet.getRow(10).getCell(1).getNumericCellValue(), 0.0); assertEquals(3, sheet.getRow(11).getCell(0).getNumericCellValue(), 0.0); assertEquals(6, sheet.getRow(11).getCell(1).getNumericCellValue(), 0.0); assertEquals(9, sheet.getRow(11).getCell(2).getNumericCellValue(), 0.0); XSSFColor bgColour = ((XSSFCell) sheet.getRow(0).getCell(0)).getCellStyle() .getFillForegroundColorColor(); assertEquals("FF800000", bgColour.getARGBHex()); XSSFColor baseColour = ((XSSFCell) sheet.getRow(0).getCell(0)).getCellStyle().getFont().getXSSFColor(); assertEquals("FF000000", baseColour.getARGBHex()); } finally { inputStream.close(); } }