aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java16
-rw-r--r--src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java11
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java13
-rw-r--r--test-data/spreadsheet/48180.xlsbin0 -> 20992 bytes
5 files changed, 33 insertions, 8 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 10e006b4e3..5369cda040 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<changes>
<release version="3.6-beta1" date="2009-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">48180 - be more forgiving of short chart records, which skip some unused fields</action>
<action dev="POI-DEVELOPERS" type="fix">48274 - fix erronious wrapping of byte colours in HSSFPalette.findSimilarColor</action>
<action dev="POI-DEVELOPERS" type="fix">48269 - fix fetching of error codes from XSSF formula cells</action>
<action dev="POI-DEVELOPERS" type="fix">48229 - fixed javadoc for HSSFSheet.setColumnWidth and XSSFSheet setColumnWidth </action>
diff --git a/src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java b/src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java
index 84eb4b063f..058f13cd66 100644
--- a/src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java
+++ b/src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java
@@ -35,7 +35,7 @@ public final class CatLabRecord extends StandardRecord {
private short wOffset;
private short at;
private short grbit;
- private short unused;
+ private Short unused;
public CatLabRecord(RecordInputStream in) {
rt = in.readShort();
@@ -43,12 +43,18 @@ public final class CatLabRecord extends StandardRecord {
wOffset = in.readShort();
at = in.readShort();
grbit = in.readShort();
- unused = in.readShort();
+
+ // Often, but not always has an unused short at the end
+ if(in.available() == 0) {
+ unused = null;
+ } else {
+ unused = in.readShort();
+ }
}
@Override
protected int getDataSize() {
- return 2 + 2 + 2 + 2 + 2 + 2;
+ return 2 + 2 + 2 + 2 + 2 + (unused==null? 0:2);
}
@Override
@@ -58,13 +64,13 @@ public final class CatLabRecord extends StandardRecord {
@Override
public void serialize(LittleEndianOutput out) {
-
out.writeShort(rt);
out.writeShort(grbitFrt);
out.writeShort(wOffset);
out.writeShort(at);
out.writeShort(grbit);
- out.writeShort(unused);
+ if(unused != null)
+ out.writeShort(unused);
}
@Override
diff --git a/src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java b/src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java
index f69a020c72..ac823b2b12 100644
--- a/src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java
+++ b/src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java
@@ -40,13 +40,18 @@ public final class ChartEndBlockRecord extends StandardRecord {
grbitFrt = in.readShort();
iObjectKind = in.readShort();
- unused = new byte[6];
- in.readFully(unused);
+ // Often, but not always has 6 unused bytes at the end
+ if(in.available() == 0) {
+ unused = new byte[0];
+ } else {
+ unused = new byte[6];
+ in.readFully(unused);
+ }
}
@Override
protected int getDataSize() {
- return 2 + 2 + 2 + 6;
+ return 2 + 2 + 2 + unused.length;
}
@Override
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index e55dd2d05d..5e15be8405 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -1509,4 +1509,17 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertEquals(32766, cell2.getStringCellValue().length());
}
+ /**
+ * Short records on certain sheets with charts in them
+ */
+ public void test48180() {
+ HSSFWorkbook wb = openSample("48180.xls");
+
+ HSSFSheet s = wb.getSheetAt(0);
+ HSSFCell cell1 = s.getRow(0).getCell(0);
+ assertEquals("test ", cell1.getStringCellValue().toString());
+
+ HSSFCell cell2 = s.getRow(0).getCell(1);
+ assertEquals(1.0, cell2.getNumericCellValue());
+ }
}
diff --git a/test-data/spreadsheet/48180.xls b/test-data/spreadsheet/48180.xls
new file mode 100644
index 0000000000..be72749be3
--- /dev/null
+++ b/test-data/spreadsheet/48180.xls
Binary files differ