From: Danny Mui Date: Fri, 9 May 2003 12:39:08 +0000 (+0000) Subject: Made sure all row records for the sheet are aggregated since rows are skipped X-Git-Tag: REL_2_0_PRE1~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea3a41637dd086ad8b66cad7d6526a2b61750d2a;p=poi.git Made sure all row records for the sheet are aggregated since rows are skipped if a formula yields a String. PR: 15062 git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353095 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 3a732c4f28..9a7abadc3f 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -234,17 +234,16 @@ public class Sheet implements Model } else if ( rec.getSid() == RowRecord.sid ) { + RowRecord row = (RowRecord)rec; + if (!isfirstrow) rec = null; //only add the aggregate once + if ( isfirstrow ) { retval.rows = new RowRecordsAggregate(); - rec = retval.rows; - retval.rows.construct( k, recs ); + rec = retval.rows; isfirstrow = false; } - else - { - rec = null; - } + retval.rows.insertRow(row); } else if ( rec.getSid() == PrintGridlinesRecord.sid ) { diff --git a/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java index c6347eb0e3..2fe2ef631f 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java @@ -135,6 +135,9 @@ public class RowRecordsAggregate return lastrow; } + /* + * No need to go through all the records as we're just collecting RowRecords + public int construct(int offset, List records) { int k = 0; @@ -154,7 +157,7 @@ public class RowRecordsAggregate } return k; } - + */ /** * called by the class that is responsible for writing this sucker. * Subclasses should implement this so that their data is passed back in a diff --git a/src/testcases/org/apache/poi/hssf/model/SheetTest.java b/src/testcases/org/apache/poi/hssf/model/SheetTest.java index e10ea4109d..9a78fd63c9 100644 --- a/src/testcases/org/apache/poi/hssf/model/SheetTest.java +++ b/src/testcases/org/apache/poi/hssf/model/SheetTest.java @@ -7,6 +7,8 @@ import java.util.List; import junit.framework.TestCase; import org.apache.poi.hssf.record.ColumnInfoRecord; +import org.apache.poi.hssf.record.RowRecord; +import org.apache.poi.hssf.record.StringRecord; /** * @author Tony Poppleton @@ -119,6 +121,39 @@ public class SheetTest extends TestCase } + /** + * Makes sure all rows registered for this sheet are aggregated, they were being skipped + * + */ + public void testRowAggregation() { + List records = new ArrayList(); + RowRecord row = new RowRecord(); + row.setRowNumber(0); + records.add(row); + + row = new RowRecord(); + row.setRowNumber(1); + records.add(row); + + records.add(new StringRecord()); + + row = new RowRecord(); + row.setRowNumber(2); + records.add(row); + + + Sheet sheet = Sheet.createSheet(records, 0); + assertNotNull("Row [2] was skipped", sheet.getRow(2)); + + } + + + public static void main(String [] args) { + System.out + .println("Testing : "+SheetTest.class.getName()); + junit.textui.TestRunner.run(SheetTest.class); + } + }