aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2011-03-18 15:18:45 +0000
committerNick Burch <nick@apache.org>2011-03-18 15:18:45 +0000
commitdd1af3acd92465e78451e0c3183dc8061338ae36 (patch)
tree1d98e52ae5d2cda2ed2b1a3082b19ba0b4311287
parent70f869b1054d91d725925487ae7c336bfde5cd19 (diff)
downloadpoi-dd1af3acd92465e78451e0c3183dc8061338ae36.tar.gz
poi-dd1af3acd92465e78451e0c3183dc8061338ae36.zip
Fix bug #50846 - XSSFCellBorder needs a theme table too, but as it gets created early switch it to the same model as XSSFFont for getting it later
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1082946 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java11
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java21
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java22
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java4
-rw-r--r--src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java2
-rw-r--r--test-data/spreadsheet/50846-border_colours.xlsxbin0 -> 12381 bytes
7 files changed, 49 insertions, 12 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 5410a7fab4..e2e772a3c2 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<changes>
<release version="3.8-beta2" date="2011-??-??">
+ <action dev="poi-developers" type="fix">50846 - More XSSFColor theme improvements, this time for Cell Borders</action>
<action dev="poi-developers" type="fix">50939 - ChartEndObjectRecord is supposed to have 6 bytes at the end, but handle it not</action>
<action dev="poi-developers" type="add">HMEF - New component which supports TNEF (Transport Neutral Encoding Format), aka winmail.dat</action>
<action dev="poi-developers" type="fix">50313 - support for getting HWPFDocument fields</action>
diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
index 60dad91b0b..e643f9fa1f 100644
--- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
+++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
@@ -98,9 +98,15 @@ public class StylesTable extends POIXMLDocumentPart {
public void setTheme(ThemesTable theme) {
this.theme = theme;
+
+ // Pass the themes table along to things which need to
+ // know about it, but have already been created by now
for(XSSFFont font : fonts) {
font.setThemesTable(theme);
}
+ for(XSSFCellBorder border : borders) {
+ border.setThemesTable(theme);
+ }
}
/**
@@ -144,7 +150,7 @@ public class StylesTable extends POIXMLDocumentPart {
CTBorders ctborders = styleSheet.getBorders();
if(ctborders != null) {
for (CTBorder border : ctborders.getBorderArray()) {
- borders.add(new XSSFCellBorder(border, theme));
+ borders.add(new XSSFCellBorder(border));
}
}
@@ -251,6 +257,7 @@ public class StylesTable extends POIXMLDocumentPart {
return idx;
}
borders.add(border);
+ border.setThemesTable(theme);
return borders.size() - 1;
}
@@ -437,7 +444,7 @@ public class StylesTable extends POIXMLDocumentPart {
fills.add(new XSSFCellFill(ctFill[1]));
CTBorder ctBorder = createDefaultBorder();
- borders.add(new XSSFCellBorder(ctBorder, theme));
+ borders.add(new XSSFCellBorder(ctBorder));
CTXf styleXf = createDefaultXf();
styleXfs.add(styleXf);
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
index adc695b095..b100bc2101 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/extensions/XSSFCellBorder.java
@@ -38,20 +38,35 @@ public class XSSFCellBorder {
* Creates a Cell Border from the supplied XML definition
*/
public XSSFCellBorder(CTBorder border, ThemesTable theme) {
- this.border = border;
+ this(border);
this._theme = theme;
}
/**
+ * Creates a Cell Border from the supplied XML definition
+ */
+ public XSSFCellBorder(CTBorder border) {
+ this.border = border;
+ }
+
+ /**
* Creates a new, empty Cell Border.
* You need to attach this to the Styles Table
*/
- public XSSFCellBorder(ThemesTable theme) {
+ public XSSFCellBorder() {
border = CTBorder.Factory.newInstance();
- this._theme = theme;
}
/**
+ * Records the Themes Table that is associated with
+ * the current font, used when looking up theme
+ * based colours and properties.
+ */
+ public void setThemesTable(ThemesTable themes) {
+ this._theme = themes;
+ }
+
+ /**
* The enumeration value indicating the side being used for a cell border.
*/
public static enum BorderSide {
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
index eaeb01faab..710ba2c01f 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
@@ -742,12 +742,26 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* should still be able to get colours
*/
public void test50846() throws Exception {
- // TODO Get file and test
- //Workbook wb = XSSFTestDataSamples.openSampleWorkbook("50846.xlsx");
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50846-border_colours.xlsx");
- // Check the style that is theme based
+ XSSFSheet sheet = wb.getSheetAt(0);
+ XSSFRow row = sheet.getRow(0);
+
+ // Border from a theme, brown
+ XSSFCell cellT = row.getCell(0);
+ XSSFCellStyle styleT = cellT.getCellStyle();
+ XSSFColor colorT = styleT.getBottomBorderXSSFColor();
+
+ assertEquals(5, colorT.getTheme());
+ assertEquals("FFC0504D", colorT.getARGBHex());
+
+ // Border from a style direct, red
+ XSSFCell cellS = row.getCell(1);
+ XSSFCellStyle styleS = cellS.getCellStyle();
+ XSSFColor colorS = styleS.getBottomBorderXSSFColor();
- // Check the one that isn't
+ assertEquals(0, colorS.getTheme());
+ assertEquals("FFFF0000", colorS.getARGBHex());
}
/**
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
index 83edc8f2f4..02b34ae85e 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
@@ -59,11 +59,11 @@ public class TestXSSFCellStyle extends TestCase {
ctStylesheet = stylesTable.getCTStylesheet();
ctBorderA = CTBorder.Factory.newInstance();
- XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA, null);
+ XSSFCellBorder borderA = new XSSFCellBorder(ctBorderA);
long borderId = stylesTable.putBorder(borderA);
assertEquals(1, borderId);
- XSSFCellBorder borderB = new XSSFCellBorder(null);
+ XSSFCellBorder borderB = new XSSFCellBorder();
assertEquals(1, stylesTable.putBorder(borderB));
ctFill = CTFill.Factory.newInstance();
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java
index 46af27d59d..e7233c227e 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/extensions/TestXSSFBorder.java
@@ -40,7 +40,7 @@ public class TestXSSFBorder extends TestCase {
right.setStyle(STBorderStyle.NONE);
bottom.setStyle(STBorderStyle.THIN);
- XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border, null);
+ XSSFCellBorder cellBorderStyle = new XSSFCellBorder(border);
assertEquals("DASH_DOT", cellBorderStyle.getBorderStyle(BorderSide.TOP).toString());
assertEquals("NONE", cellBorderStyle.getBorderStyle(BorderSide.RIGHT).toString());
diff --git a/test-data/spreadsheet/50846-border_colours.xlsx b/test-data/spreadsheet/50846-border_colours.xlsx
new file mode 100644
index 0000000000..49ec5320fd
--- /dev/null
+++ b/test-data/spreadsheet/50846-border_colours.xlsx
Binary files differ