From 9f0f36395355f2f03028dbee206843282f4f60bd Mon Sep 17 00:00:00 2001 From: Glen Stampoultzis Date: Fri, 12 Apr 2002 08:26:29 +0000 Subject: [PATCH] Fixed a bug I introduced a couple of days ago git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352395 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/model/Sheet.java | 22 ++++++++++++------- .../poi/hssf/usermodel/HSSFWorkbook.java | 3 ++- .../poi/hssf/usermodel/TestHSSFSheet.java | 2 ++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index a247e4745..59498b969 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -55,17 +55,21 @@ package org.apache.poi.hssf.model; +import java.io.OutputStream; + import java.util.List; import java.util.ArrayList; import java.util.Iterator; import org.apache.poi.util.POILogFactory; -import org.apache.poi.hssf.record.*; // normally I don't do this, buy we literally mean ALL +import org.apache.poi.hssf + .record.*; // normally I don't do this, buy we literally mean ALL import org.apache.poi.hssf.record.formula.FormulaUtil; import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.util.IntList; import org.apache.poi.util.POILogger; -import org.apache.poi.hssf.record.aggregates.*; // normally I don't do this, buy we literally mean ALL +import org.apache.poi.hssf.record + .aggregates.*; // normally I don't do this, buy we literally mean ALL /** * Low level model implementation of a Sheet (one workbook contains many sheets) @@ -112,7 +116,7 @@ public class Sheet /** * Creates new Sheet with no intialization --useless at this point - * @see #createSheet(List,int) + * @see #createSheet(List,int,int) */ public Sheet() @@ -128,6 +132,7 @@ public class Sheet * is normally called via Workbook. * * @param recs array containing those records in the sheet in sequence (normally obtained from RecordFactory) + * @param sheetnum integer specifying the sheet's number (0,1 or 2 in this release) * @param offset of the sheet's BOF record * * @return Sheet object with all values set to those read from the file @@ -135,7 +140,7 @@ public class Sheet * @see org.apache.poi.hssf.model.Workbook * @see org.apache.poi.hssf.record.Record */ - public static Sheet createSheet(List recs, int offset) + public static Sheet createSheet(List recs, int sheetnum, int offset) { log.logFormatted(log.DEBUG, "Sheet createSheet (existing file) with %", @@ -235,14 +240,15 @@ public class Sheet * only the record offset is assumed to be 0. * * @param records array containing those records in the sheet in sequence (normally obtained from RecordFactory) + * @param sheetnum integer specifying the sheet's number (0,1 or 2 in this release) * @return Sheet object */ - public static Sheet createSheet(List records) + public static Sheet createSheet(List records, int sheetnum) { log.log(log.DEBUG, "Sheet createSheet (exisiting file) assumed offset 0"); - return createSheet(records); + return createSheet(records, sheetnum, 0); } /** @@ -520,7 +526,7 @@ public class Sheet // for (int k = 0; k < records.size(); k++) // { // bytes.add((( Record ) records.get(k)).serialize()); - // + // // } // for (int k = 0; k < bytes.size(); k++) // { @@ -562,7 +568,7 @@ public class Sheet // for (int k = 0; k < records.size(); k++) // { // bytes.add((( Record ) records.get(k)).serialize()); - // + // // } // for (int k = 0; k < bytes.size(); k++) // { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index a851a1c42..e2daea9eb 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -142,10 +142,11 @@ public class HSSFWorkbook workbook = Workbook.createWorkbook(records); setPropertiesFromWorkbook(workbook); int numRecords = workbook.getNumRecords(); + int sheetNum = 0; while (numRecords < records.size()) { - Sheet sheet = Sheet.createSheet(records); + Sheet sheet = Sheet.createSheet(records, sheetNum++, numRecords); numRecords += sheet.getNumRecords(); sheet.convertLabelRecords( diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 51901a10b..4868aee04 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -58,6 +58,7 @@ import junit.framework.TestCase; import org.apache.poi.hssf.model.Sheet; import org.apache.poi.hssf.record.VCenterRecord; import org.apache.poi.hssf.record.WSBoolRecord; +import org.apache.poi.hssf.dev.BiffViewer; import java.io.File; import java.io.FileInputStream; @@ -187,6 +188,7 @@ public class TestHSSFSheet row = sheet.getRow(2); stream.close(); tempFile.delete(); + assertNotNull(row); assertEquals(2, row.getPhysicalNumberOfCells());