<changes>
<release version="3.7-SNAPSHOT" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="add">48779 - Allow you to get straight from a CellStyle to a Color, irrespective of if the Color is indexed or inline-defined</action>
<action dev="POI-DEVELOPERS" type="add">48924 - Allow access of the HWPF DateAndTime underlying date values</action>
<action dev="POI-DEVELOPERS" type="add">48926 - Initial support for the HWPF revision marks authors list</action>
<action dev="POI-DEVELOPERS" type="fix">49160 - Ensure that CTDigSigBlob is included in poi-ooxml jar</action>
}
return result;
}
+
+ public HSSFColor getFillBackgroundColorColor() {
+ HSSFPalette pallette = new HSSFPalette(
+ _workbook.getCustomPalette()
+ );
+ return pallette.getColor(
+ getFillBackgroundColor()
+ );
+ }
/**
* set the foreground fill color
return _format.getFillForeground();
}
+ public HSSFColor getFillForegroundColorColor() {
+ HSSFPalette pallette = new HSSFPalette(
+ _workbook.getCustomPalette()
+ );
+ return pallette.getColor(
+ getFillForegroundColor()
+ );
+ }
+
/**
* Gets the name of the user defined style.
* Returns null for built in styles, and
import java.lang.reflect.Field;
import java.util.Hashtable;
+import org.apache.poi.ss.usermodel.Color;
+
/**
* Intends to provide support for the very evil index to triplet issue and
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Brian Sanders (bsanders at risklabs dot com) - full default color palette
*/
-public class HSSFColor {
+public class HSSFColor implements Color {
// TODO make subclass instances immutable
/** Creates a new instance of HSSFColor */
void setFillBackgroundColor(short bg);
/**
- * get the background fill color
- * @return fill color
+ * get the background fill color, if the fill
+ * is defined with an indexed color.
+ * @return fill color index, or 0 if not indexed (XSSF only)
*/
short getFillBackgroundColor();
+
+ /**
+ * Gets the color object representing the current
+ * background fill, resolving indexes using
+ * the supplied workbook.
+ * This will work for both indexed and rgb
+ * defined colors.
+ */
+ Color getFillBackgroundColorColor();
/**
* set the foreground fill color
void setFillForegroundColor(short bg);
/**
- * get the foreground fill color
- * @return fill color
+ * get the foreground fill color, if the fill
+ * is defined with an indexed color.
+ * @return fill color, or 0 if not indexed (XSSF only)
*/
short getFillForegroundColor();
+
+ /**
+ * Gets the color object representing the current
+ * foreground fill, resolving indexes using
+ * the supplied workbook.
+ * This will work for both indexed and rgb
+ * defined colors.
+ */
+ Color getFillForegroundColorColor();
/**
* Clones all the style information from another
--- /dev/null
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
+package org.apache.poi.ss.usermodel;
+
+public interface Color {
+}
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.apache.poi.util.Internal;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
-import org.apache.poi.util.Internal;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorderPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellAlignment;
XSSFColor clr = getFillBackgroundXSSFColor();
return clr == null ? IndexedColors.AUTOMATIC.getIndex() : clr.getIndexed();
}
+
+ public XSSFColor getFillBackgroundColorColor() {
+ return getFillBackgroundXSSFColor();
+ }
/**
* Get the background fill color.
return clr == null ? IndexedColors.AUTOMATIC.getIndex() : clr.getIndexed();
}
+ public XSSFColor getFillForegroundColorColor() {
+ return getFillForegroundXSSFColor();
+ }
+
/**
* Get the foreground fill color.
*
package org.apache.poi.xssf.usermodel;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
+import org.apache.poi.ss.usermodel.Color;
import org.apache.poi.util.Internal;
/**
* Represents a color in SpreadsheetML
*/
-public class XSSFColor {
+public class XSSFColor implements Color {
private CTColor ctColor;
}
return rgb;
}
+
+ /**
+ * Return the ARGB value in hex format, eg FF00FF00.
+ * For indexed colours, returns null.
+ */
+ public String getARGBHex() {
+ StringBuffer sb = new StringBuffer();
+ byte[] rgb = getRgb();
+ if(rgb == null) {
+ return null;
+ }
+ for(byte c : rgb) {
+ int i = (int)c;
+ if(i < 0) {
+ i += 256;
+ }
+ String cs = Integer.toHexString(i);
+ if(cs.length() == 1) {
+ sb.append('0');
+ }
+ sb.append(cs);
+ }
+ return sb.toString().toUpperCase();
+ }
private static byte applyTint(int lum, double tint){
if(tint > 0){
XSSFColor cf = (XSSFColor)o;
return ctColor.toString().equals(cf.getCTColor().toString());
}
-
}
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.XSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
+import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
public final class TestXSSFBugs extends BaseTestBugzillaIssues {
// Now all of them
XSSFFormulaEvaluator.evaluateAllFormulaCells(wb);
}
+
+ /**
+ * Foreground colours should be found even if
+ * a theme is used
+ */
+ public void test48779() throws Exception {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("48779.xlsx");
+ XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
+ XSSFCellStyle cs = cell.getCellStyle();
+
+ assertNotNull(cs);
+ assertEquals(1, cs.getIndex());
+
+ // Look at the low level xml elements
+ assertEquals(2, cs.getCoreXf().getFillId());
+ assertEquals(0, cs.getCoreXf().getXfId());
+ assertEquals(true, cs.getCoreXf().getApplyFill());
+
+ XSSFCellFill fg = wb.getStylesSource().getFillAt(2);
+ assertEquals(0, fg.getFillForegroundColor().getIndexed());
+ assertEquals(0.0, fg.getFillForegroundColor().getTint());
+ assertEquals("FFFF0000", fg.getFillForegroundColor().getARGBHex());
+ assertEquals(64, fg.getFillBackgroundColor().getIndexed());
+
+ // Now look higher up
+ assertNotNull(cs.getFillForegroundXSSFColor());
+ assertEquals(0, cs.getFillForegroundColor());
+ assertEquals("FFFF0000", cs.getFillForegroundXSSFColor().getARGBHex());
+ assertEquals("FFFF0000", cs.getFillForegroundColorColor().getARGBHex());
+
+ assertNotNull(cs.getFillBackgroundColor());
+ assertEquals(64, cs.getFillBackgroundColor());
+ assertEquals(null, cs.getFillBackgroundXSSFColor().getARGBHex());
+ assertEquals(null, cs.getFillBackgroundColorColor().getARGBHex());
+ }
}
==================================================================== */
package org.apache.poi.ss.format;
-import junit.framework.TestCase;
-import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.ss.ITestDataProvider;
+import static java.awt.Color.BLACK;
+import static java.awt.Color.BLUE;
+import static java.awt.Color.CYAN;
+import static java.awt.Color.GREEN;
+import static java.awt.Color.MAGENTA;
+import static java.awt.Color.ORANGE;
+import static java.awt.Color.RED;
+import static java.awt.Color.WHITE;
+import static java.awt.Color.YELLOW;
+
+import java.awt.Color;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
-import javax.swing.*;
-import java.awt.*;
-import java.util.*;
+import javax.swing.JLabel;
-import static java.awt.Color.*;
-import java.io.IOException;
+import junit.framework.TestCase;
+
+import org.apache.poi.ss.ITestDataProvider;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
/**
* This class is a base class for spreadsheet-based tests, such as are used for