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

@ -4,54 +4,54 @@
<todo title="Things To Do for Poi">
<devs>
<!-- in strict alphabetical order -->
<person id="AO" name="Andrew C. Oliver" email="acoliver2@users.sourceforge.net"/>
<person id="GS" name="Glen Stampoultzis" email="gstamp@iprimus.com.au"/>
<person id="MJ" name="Marc Johnson" email="mjohnson at apache dot org"/>
<person id="NKB" name="Nicola Ken Barozzi" email="barozzi@nicolaken.com"/>
<person id="open" name="Poi Developers" email="poi-dev@jakarta.apache.org"/>
</devs>
<devs>
<!-- in strict alphabetical order -->
<person id="AO" name="Andrew C. Oliver" email="acoliver2@users.sourceforge.net"/>
<person id="GS" name="Glen Stampoultzis" email="gstamp@iprimus.com.au"/>
<person id="MJ" name="Marc Johnson" email="mjohnson at apache dot org"/>
<person id="NKB" name="Nicola Ken Barozzi" email="barozzi@nicolaken.com"/>
<person id="open" name="Poi Developers" email="poi-dev@jakarta.apache.org"/>
</devs>
<actions priority="high">
<action context="code" assigned-to="NKB">
Finish HDF
</action>
<action context="code" assigned-to="NKB">
Finish Charts
</action>
<action context="code">
Add Formulas.
</action>
<actions priority="high">
<action context="code" assigned-to="NKB">
Finish HDF
</action>
<action context="code" assigned-to="NKB">
Finish Charts
</action>
<action context="code">
Add Formulas.
</action>
</actions>
</actions>
<actions priority="medium">
<action context="code">
Expose functionality in low level records in higher level API
</action>
<action context="code">
Implement more record types (for other things ... not sure
what this will mean yet).
</action>
<action context="code">
Implement more record types (for other things ... not sure
what this will mean yet).
</action>
<action context="code">
Add more dummy checks (for when API user's do things they
&quot;can't&quot; do)
</action>
<action context="code">
Add support for embedded graphics and stuff like that.
</action>
<action context="code">
Create new adapter object for handling MulBlank, MulRk, Rk
records.
</action>
<action context="code">
Add a way to copy sheets.
</action>
</actions>
<actions priority="medium">
<action context="code">
Expose functionality in low level records in higher level API
</action>
<action context="code">
Implement more record types (for other things ... not sure
what this will mean yet).
</action>
<action context="code">
Implement more record types (for other things ... not sure
what this will mean yet).
</action>
<action context="code">
Add more dummy checks (for when API user's do things they
&quot;can't&quot; do)
</action>
<action context="code">
Add support for embedded graphics and stuff like that.
</action>
<action context="code">
Create new adapter object for handling MulBlank, MulRk, Rk
records.
</action>
<action context="code">
Add a way to copy sheets.
</action>
</actions>
</todo>

View File

@ -55,21 +55,17 @@
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)
@ -116,7 +112,7 @@ public class Sheet
/**
* Creates new Sheet with no intialization --useless at this point
* @see #createSheet(List,int,int)
* @see #createSheet(List,int)
*/
public Sheet()
@ -132,7 +128,6 @@ 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
@ -140,7 +135,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 sheetnum, int offset)
public static Sheet createSheet(List recs, int offset)
{
log.logFormatted(log.DEBUG,
"Sheet createSheet (existing file) with %",
@ -240,15 +235,14 @@ 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, int sheetnum)
public static Sheet createSheet(List records)
{
log.log(log.DEBUG,
"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 org.apache.poi.util.LittleEndian;
import org.apache.poi.util.HexDump;
/**
* Title: Record Factory<P>
@ -103,7 +102,7 @@ public class RecordFactory
WindowTwoRecord.class, SelectionRecord.class, ContinueRecord.class,
LabelRecord.class, BlankRecord.class, ColumnInfoRecord.class,
MulRKRecord.class, MulBlankRecord.class, MergeCellsRecord.class,
FormulaRecord.class
FormulaRecord.class, BoolErrRecord.class
};
private static Map recordsMap = recordsToMap(records);
@ -221,8 +220,9 @@ public class RecordFactory
}
catch (Exception introspectionException)
{
introspectionException.printStackTrace();
throw new RecordFormatException(
"Unable to construct record instance");
"Unable to construct record instance, the following exception occured: " + introspectionException.getMessage());
}
if (retval instanceof RKRecord)
{

View File

@ -142,11 +142,10 @@ 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, sheetnum, numRecords);
Sheet sheet = Sheet.createSheet(records);
numRecords += sheet.getNumRecords();
sheet.convertLabelRecords(

View File

@ -1,4 +1,3 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
@ -56,14 +55,13 @@
package org.apache.poi.hssf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.record.VCenterRecord;
import org.apache.poi.hssf.record.WSBoolRecord;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
/**
* Tests HSSFSheet. This test case is very incomplete at the moment.
@ -74,7 +72,7 @@ import java.io.FileWriter;
*/
public class TestHSSFSheet
extends TestCase
extends TestCase
{
public TestHSSFSheet(String s)
{
@ -86,11 +84,11 @@ public class TestHSSFSheet
*/
public void testBackupRecord()
throws Exception
throws Exception
{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
Sheet sheet = s.getSheet();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
Sheet sheet = s.getSheet();
assertEquals(true, sheet.getGridsetRecord().getGridset());
s.setGridsPrinted(true);
@ -102,13 +100,13 @@ public class TestHSSFSheet
*/
public void testVerticallyCenter()
throws Exception
throws Exception
{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
Sheet sheet = s.getSheet();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
Sheet sheet = s.getSheet();
VCenterRecord record =
( VCenterRecord ) sheet.findFirstRecordBySid(VCenterRecord.sid);
(VCenterRecord) sheet.findFirstRecordBySid(VCenterRecord.sid);
assertEquals(false, record.getVCenter());
s.setVerticallyCenter(true);
@ -123,11 +121,11 @@ public class TestHSSFSheet
public void testWSBool()
{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
Sheet sheet = s.getSheet();
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
Sheet sheet = s.getSheet();
WSBoolRecord record =
( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid);
(WSBoolRecord) sheet.findFirstRecordBySid(WSBoolRecord.sid);
// Check defaults
assertEquals(true, record.getAlternateExpression());
@ -167,4 +165,30 @@ public class TestHSSFSheet
assertEquals(true, s.getRowSumsBelow());
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());
}
}