diff options
author | Dominik Stadler <centic@apache.org> | 2014-12-22 14:16:23 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2014-12-22 14:16:23 +0000 |
commit | e224d82fe5927d95e96b30544f271d3e2b5a9871 (patch) | |
tree | 9d56f740d2f11ae103b8c8f62d172ae423faa6ba | |
parent | c116c2b2e7301d7ea07a72f9f97331e2c812b69a (diff) | |
download | poi-e224d82fe5927d95e96b30544f271d3e2b5a9871.tar.gz poi-e224d82fe5927d95e96b30544f271d3e2b5a9871.zip |
Bug 57362: Properly initialize chart axis when loading a workbook which already contains a chart.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1647317 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java | 17 | ||||
-rw-r--r-- | src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java | 22 | ||||
-rw-r--r-- | test-data/spreadsheet/57362.xlsx | bin | 0 -> 13283 bytes |
3 files changed, 30 insertions, 9 deletions
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java index 41038114f6..0f2179a9dc 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java @@ -79,14 +79,13 @@ public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartA */ private CTChart chart; - List<XSSFChartAxis> axis; + List<XSSFChartAxis> axis = new ArrayList<XSSFChartAxis>(); /** * Create a new SpreadsheetML chart */ protected XSSFChart() { super(); - axis = new ArrayList<XSSFChartAxis>(); createChart(); } @@ -227,13 +226,13 @@ public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartA return categoryAxis; } - public List<? extends XSSFChartAxis> getAxis() { - if (axis.isEmpty() && hasAxis()) { - parseAxis(); - } - return axis; - } - + public List<? extends XSSFChartAxis> getAxis() { + if (axis.isEmpty() && hasAxis()) { + parseAxis(); + } + return axis; + } + public XSSFManualLayout getManualLayout() { return new XSSFManualLayout(this); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java index 0188c71555..f1351f1862 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/charts/TestXSSFChartAxis.java @@ -17,9 +17,14 @@ package org.apache.poi.xssf.usermodel.charts; +import java.util.List; + import junit.framework.TestCase; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.charts.*; +import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.usermodel.*; public final class TestXSSFChartAxis extends TestCase { @@ -111,4 +116,21 @@ public final class TestXSSFChartAxis extends TestCase { axis.setMinorTickMark(AxisTickMark.CROSS); assertEquals(AxisTickMark.CROSS, axis.getMinorTickMark()); } + + public void testGetChartAxisBug57362() { + //Load existing excel with some chart on it having primary and secondary axis. + final Workbook workbook = XSSFTestDataSamples.openSampleWorkbook("57362.xlsx"); + final Sheet sh = workbook.getSheetAt(0); + final XSSFSheet xsh = (XSSFSheet) sh; + final XSSFDrawing drawing = xsh.createDrawingPatriarch(); + final XSSFChart chart = drawing.getCharts().get(0); + + final List<? extends XSSFChartAxis> axisList = chart.getAxis(); + + assertEquals(4, axisList.size()); + assertNotNull(axisList.get(0)); + assertNotNull(axisList.get(1)); + assertNotNull(axisList.get(2)); + assertNotNull(axisList.get(3)); + } } diff --git a/test-data/spreadsheet/57362.xlsx b/test-data/spreadsheet/57362.xlsx Binary files differnew file mode 100644 index 0000000000..ec2be38234 --- /dev/null +++ b/test-data/spreadsheet/57362.xlsx |