Bug fix & cleanup

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352389 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Glen Stampoultzis 2002-04-10 12:48:00 +00:00
parent 65805d686e
commit 8291c9dc85
5 changed files with 98 additions and 81 deletions

View File

@ -55,21 +55,17 @@
package org.apache.poi.hssf.model; package org.apache.poi.hssf.model;
import java.io.OutputStream;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.hssf import org.apache.poi.hssf.record.*; // normally I don't do this, buy we literally mean ALL
.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.FormulaUtil;
import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.util.IntList; import org.apache.poi.util.IntList;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.hssf.record import org.apache.poi.hssf.record.aggregates.*; // normally I don't do this, buy we literally mean ALL
.aggregates.*; // normally I don't do this, buy we literally mean ALL
/** /**
* Low level model implementation of a Sheet (one workbook contains many sheets) * Low level model implementation of a Sheet (one workbook contains many sheets)
@ -116,7 +112,7 @@ public class Sheet
/** /**
* Creates new Sheet with no intialization --useless at this point * Creates new Sheet with no intialization --useless at this point
* @see #createSheet(List,int,int) * @see #createSheet(List,int)
*/ */
public Sheet() public Sheet()
@ -132,7 +128,6 @@ public class Sheet
* is normally called via Workbook. * is normally called via Workbook.
* *
* @param recs array containing those records in the sheet in sequence (normally obtained from RecordFactory) * @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 * @param offset of the sheet's BOF record
* *
* @return Sheet object with all values set to those read from the file * @return Sheet object with all values set to those read from the file
@ -140,7 +135,7 @@ public class Sheet
* @see org.apache.poi.hssf.model.Workbook * @see org.apache.poi.hssf.model.Workbook
* @see org.apache.poi.hssf.record.Record * @see org.apache.poi.hssf.record.Record
*/ */
public static Sheet createSheet(List recs, int sheetnum, int offset) public static Sheet createSheet(List recs, int offset)
{ {
log.logFormatted(log.DEBUG, log.logFormatted(log.DEBUG,
"Sheet createSheet (existing file) with %", "Sheet createSheet (existing file) with %",
@ -240,15 +235,14 @@ public class Sheet
* only the record offset is assumed to be 0. * 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 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 * @return Sheet object
*/ */
public static Sheet createSheet(List records, int sheetnum) public static Sheet createSheet(List records)
{ {
log.log(log.DEBUG, log.log(log.DEBUG,
"Sheet createSheet (exisiting file) assumed offset 0"); "Sheet createSheet (exisiting file) assumed offset 0");
return createSheet(records, sheetnum, 0); return createSheet(records);
} }
/** /**

View File

@ -63,7 +63,6 @@ import java.util.*;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.HexDump;
/** /**
* Title: Record Factory<P> * Title: Record Factory<P>
@ -103,7 +102,7 @@ public class RecordFactory
WindowTwoRecord.class, SelectionRecord.class, ContinueRecord.class, WindowTwoRecord.class, SelectionRecord.class, ContinueRecord.class,
LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class, LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class,
MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class, MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class,
FormulaRecord.class FormulaRecord.class, BoolErrRecord.class
}; };
private static Map recordsMap = recordsToMap(records); private static Map recordsMap = recordsToMap(records);
@ -221,8 +220,9 @@ public class RecordFactory
} }
catch (Exception introspectionException) catch (Exception introspectionException)
{ {
introspectionException.printStackTrace();
throw new RecordFormatException( throw new RecordFormatException(
"Unable to construct record instance"); "Unable to construct record instance, the following exception occured: " + introspectionException.getMessage());
} }
if (retval instanceof RKRecord) if (retval instanceof RKRecord)
{ {

View File

@ -142,11 +142,10 @@ public class HSSFWorkbook
workbook = Workbook.createWorkbook(records); workbook = Workbook.createWorkbook(records);
setPropertiesFromWorkbook(workbook); setPropertiesFromWorkbook(workbook);
int numRecords = workbook.getNumRecords(); int numRecords = workbook.getNumRecords();
int sheetnum = 0;
while (numRecords < records.size()) while (numRecords < records.size())
{ {
Sheet sheet = Sheet.createSheet(records, sheetnum, numRecords); Sheet sheet = Sheet.createSheet(records);
numRecords += sheet.getNumRecords(); numRecords += sheet.getNumRecords();
sheet.convertLabelRecords( sheet.convertLabelRecords(

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
@ -56,14 +55,13 @@
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.Sheet; import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.record.VCenterRecord; import org.apache.poi.hssf.record.VCenterRecord;
import org.apache.poi.hssf.record.WSBoolRecord; import org.apache.poi.hssf.record.WSBoolRecord;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter;
/** /**
* Tests HSSFSheet. This test case is very incomplete at the moment. * Tests HSSFSheet. This test case is very incomplete at the moment.
@ -167,4 +165,30 @@ public class TestHSSFSheet
assertEquals(true, s.getRowSumsBelow()); assertEquals(true, s.getRowSumsBelow());
assertEquals(true, s.getRowSumsRight()); assertEquals(true, s.getRowSumsRight());
} }
public void testReadBooleans()
throws Exception
{
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Test boolean");
HSSFRow row = sheet.createRow((short) 2);
HSSFCell cell = row.createCell((short) 9);
cell.setCellValue(true);
cell = row.createCell((short) 11);
cell.setCellValue(true);
File tempFile = File.createTempFile("bool", "test.xls");
FileOutputStream stream = new FileOutputStream(tempFile);
workbook.write(stream);
stream.close();
FileInputStream readStream = new FileInputStream(tempFile);
workbook = new HSSFWorkbook(readStream);
sheet = workbook.getSheetAt(0);
row = sheet.getRow(2);
stream.close();
tempFile.delete();
assertEquals(2, row.getPhysicalNumberOfCells());
}
} }