mirror of https://github.com/apache/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
This commit is contained in:
parent
bc6f208d79
commit
302bce265a
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue