From: Nick Burch Date: Sun, 27 Dec 2009 17:13:44 +0000 (+0000) Subject: Make InternalSheet capture the feature related records X-Git-Tag: REL_3_7_BETA1~175 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=302bce265a6f52a37410c96b48b6c9c78f0abdc3;p=poi.git Make InternalSheet capture the feature related records git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@894081 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index b734c60b1f..a9414f2083 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -35,6 +35,8 @@ import org.apache.poi.hssf.record.DimensionsRecord; import org.apache.poi.hssf.record.DrawingRecord; import org.apache.poi.hssf.record.EOFRecord; import org.apache.poi.hssf.record.EscherAggregate; +import org.apache.poi.hssf.record.FeatHdrRecord; +import org.apache.poi.hssf.record.FeatRecord; import org.apache.poi.hssf.record.GridsetRecord; import org.apache.poi.hssf.record.GutsRecord; import org.apache.poi.hssf.record.IndexRecord; @@ -265,6 +267,12 @@ public final class InternalSheet { continue; } + if (recSid == FeatRecord.sid || + recSid == FeatHdrRecord.sid) { + records.add(rec); + continue; + } + if (recSid == EOFRecord.sid) { records.add(rec); break; diff --git a/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java b/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java index 0ba8b77273..4840561e01 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestFeatRecord.java @@ -18,7 +18,9 @@ package org.apache.poi.hssf.record; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.model.InternalSheet; import org.apache.poi.hssf.model.InternalWorkbook; +import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFTestHelper; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -34,8 +36,12 @@ public final class TestFeatRecord extends TestCase { HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls"); InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf); + assertEquals(1, hssf.getNumberOfSheets()); + int countFR = 0; int countFRH = 0; + + // Check on the workbook, but shouldn't be there! for(Record r : wb.getRecords()) { if(r instanceof FeatRecord) { countFR++; @@ -51,19 +57,41 @@ public final class TestFeatRecord extends TestCase { assertEquals(0, countFR); assertEquals(0, countFRH); + + // Now check on the sheet + HSSFSheet s = hssf.getSheetAt(0); + InternalSheet sheet = HSSFTestHelper.getSheetForTest(s); + + for(RecordBase rb : sheet.getRecords()) { + if(rb instanceof Record) { + Record r = (Record)rb; + if(r instanceof FeatRecord) { + countFR++; + } else if (r.getSid() == FeatRecord.sid) { + countFR++; + } + if(r instanceof FeatHdrRecord) { + countFRH++; + } else if (r.getSid() == FeatHdrRecord.sid) { + countFRH++; + } + } + } + + assertEquals(0, countFR); + assertEquals(0, countFRH); } - /** - * TODO - make this work! - * (Need to have the Internal Workbook capture it or something) - */ - public void DISABLEDtestReadFeatRecord() throws Exception { + public void testReadFeatRecord() throws Exception { HSSFWorkbook hssf = HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls"); InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf); FeatRecord fr = null; + assertEquals(1, hssf.getNumberOfSheets()); + + // First check it isn't on the Workbook int countFR = 0; int countFRH = 0; for(Record r : wb.getRecords()) { @@ -80,6 +108,30 @@ public final class TestFeatRecord extends TestCase { } } + assertEquals(0, countFR); + assertEquals(0, countFRH); + + // Now find it on our sheet + HSSFSheet s = hssf.getSheetAt(0); + InternalSheet sheet = HSSFTestHelper.getSheetForTest(s); + + for(RecordBase rb : sheet.getRecords()) { + if(rb instanceof Record) { + Record r = (Record)rb; + if(r instanceof FeatRecord) { + fr = (FeatRecord)r; + countFR++; + } else if (r.getSid() == FeatRecord.sid) { + countFR++; + } + if(r instanceof FeatHdrRecord) { + countFRH++; + } else if (r.getSid() == FeatHdrRecord.sid) { + countFRH++; + } + } + } + assertEquals(1, countFR); assertEquals(1, countFRH); assertNotNull(fr); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java index 132013da08..7c5a88bd45 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/HSSFTestHelper.java @@ -16,6 +16,7 @@ ==================================================================== */ package org.apache.poi.hssf.usermodel; +import org.apache.poi.hssf.model.InternalSheet; import org.apache.poi.hssf.model.InternalWorkbook; /** @@ -30,4 +31,7 @@ public class HSSFTestHelper { public static InternalWorkbook getWorkbookForTest(HSSFWorkbook wb) { return wb.getWorkbook(); } + public static InternalSheet getSheetForTest(HSSFSheet sheet) { + return sheet.getSheet(); + } }