Return-Path: X-Original-To: apmail-poi-user-archive@www.apache.org Delivered-To: apmail-poi-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6100BD383 for ; Thu, 12 Jul 2012 13:07:15 +0000 (UTC) Received: (qmail 69901 invoked by uid 500); 12 Jul 2012 13:07:15 -0000 Delivered-To: apmail-poi-user-archive@poi.apache.org Received: (qmail 69249 invoked by uid 500); 12 Jul 2012 13:07:13 -0000 Mailing-List: contact user-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "POI Users List" Delivered-To: mailing list user@poi.apache.org Received: (qmail 69203 invoked by uid 99); 12 Jul 2012 13:07:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2012 13:07:12 +0000 X-ASF-Spam-Status: No, hits=2.0 required=5.0 tests=FSL_RCVD_USER,SPF_NEUTRAL,URI_HEX X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [216.139.236.26] (HELO sam.nabble.com) (216.139.236.26) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Jul 2012 13:07:06 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1SpJ6T-0005zm-DZ for user@poi.apache.org; Thu, 12 Jul 2012 06:06:45 -0700 Date: Thu, 12 Jul 2012 06:06:45 -0700 (PDT) From: nb To: user@poi.apache.org Message-ID: <1342098405409-5710445.post@n5.nabble.com> Subject: Problems on getting rgb of an indexed XSSFColor MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hi! I have problems on getting the rgb-values of an XSSFColor in order to convert it to an awt-Color. I use this code: public static Color getAwtColor(XSSFColor color, XSSFWorkbook wb) { if(color==null) return null; if(color.getCTColor().isSetIndexed()) { short ix=color.getIndexed(); if(ix==IndexedColors.AUTOMATIC.index) return null; if(ix==IndexedColors.BLACK.index) return BLACK; //check first indexes manually because of a bug in poi3.8 if(ix==IndexedColors.WHITE.index) return WHITE; if(ix==IndexedColors.RED.index) return RED; if(ix==IndexedColors.BRIGHT_GREEN.index) return GREEN; if(ix==IndexedColors.BLUE.index) return BLUE; if(defaultPaletteRecord==null) defaultPaletteRecord=new PaletteRecord(); byte[] b=defaultPaletteRecord.getColor(ix); return b!=null ? new Color(Util.unsignedInt(b[0]), Util.unsignedInt(b[1]), Util.unsignedInt(b[2])) : null; } if(color.getCTColor().isSetTheme()) { int theme=color.getTheme(); switch(theme) { case 0: case 1: case 2: case 3: //handle bug: MSExcel does not follow own definitions double tint=color.getTint(); try { color=wb.getTheme().getThemeColor(theme^1); color.setTint(tint); } catch(NullPointerException ex){ } } } if(color.getCTColor().getRgb()==null) return null; byte[] rgb=color.getRgbWithTint(); return rgb!=null ? rgb.length==3 ? new Color(unsignedInt(rgb[0]), unsignedInt(rgb[1]), unsignedInt(rgb[2])) : new Color(unsignedInt(rgb[1]), unsignedInt(rgb[2]), unsignedInt(rgb[3]), unsignedInt(rgb[0])) : null; } Normally this works fine, but the background color of the orange cell in this xlsx-file: http://apache-poi.1045710.n5.nabble.com/file/n5710445/Color_Test.xlsx Color_Test.xlsx is converted to a bright green since the index of its XSSFColor is ==IndexedColors.BRIGHT_GREEN.index . There seems to be a custom-palette that is used instead of the default indexed colors; in HSSF I use HSSFWorkbook.getCustomPalette() but in XSSF the is not such a method. Am I doing something wrong? Is there a simpler way or a utility-method that I didn't find? Regards, Nils -- View this message in context: http://apache-poi.1045710.n5.nabble.com/Problems-on-getting-rgb-of-an-indexed-XSSFColor-tp5710445.html Sent from the POI - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional commands, e-mail: user-help@poi.apache.org