Renamed model.Workbook to InternalWorkbook to alleviate name clash.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@893050 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-12-22 00:51:29 +00:00
parent 66d86cb8da
commit 1fd52310cd
22 changed files with 267 additions and 299 deletions

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.BoundSheetRecord;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.ExternSheetRecord;
@ -30,39 +30,31 @@ import org.apache.poi.hssf.record.SupBookRecord;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* When working with the EventUserModel, if you want to
* When working with the EventUserModel, if you want to
* process formulas, you need an instance of
* {@link Workbook} to pass to a {@link HSSFWorkbook},
* to finally give to {@link HSSFFormulaParser},
* {@link InternalWorkbook} to pass to a {@link HSSFWorkbook},
* to finally give to {@link HSSFFormulaParser},
* and this will build you stub ones.
* Since you're working with the EventUserModel, you
* wouldn't want to get a full {@link Workbook} and
* wouldn't want to get a full {@link InternalWorkbook} and
* {@link HSSFWorkbook}, as they would eat too much memory.
* Instead, you should collect a few key records as they
* go past, then call this once you have them to build a
* stub {@link Workbook}, and from that a stub
* stub {@link InternalWorkbook}, and from that a stub
* {@link HSSFWorkbook}, to use with the {@link HSSFFormulaParser}.
*
*
* The records you should collect are:
* * {@link ExternSheetRecord}
* * {@link BoundSheetRecord}
* You should probably also collect {@link SSTRecord},
* You should probably also collect {@link SSTRecord},
* but it's not required to pass this in.
*
*
* To help, this class includes a HSSFListener wrapper
* that will do the collecting for you.
*/
public class EventWorkbookBuilder {
/**
* Wraps up your stub {@link Workbook} as a stub
* {@link HSSFWorkbook}, ready for passing to
* {@link HSSFFormulaParser}
* @param workbook A stub {@link Workbook}
*/
public static HSSFWorkbook createStubHSSFWorkbook(Workbook workbook) {
return new StubHSSFWorkbook(workbook);
}
/**
* Creates a stub Workbook from the supplied records,
* suitable for use with the {@link HSSFFormulaParser}
@ -71,10 +63,10 @@ public class EventWorkbookBuilder {
* @param sst The SSTRecord in your file.
* @return A stub Workbook suitable for use with {@link HSSFFormulaParser}
*/
public static Workbook createStubWorkbook(ExternSheetRecord[] externs,
public static InternalWorkbook createStubWorkbook(ExternSheetRecord[] externs,
BoundSheetRecord[] bounds, SSTRecord sst) {
List wbRecords = new ArrayList();
// Core Workbook records go first
if(bounds != null) {
for(int i=0; i<bounds.length; i++) {
@ -84,7 +76,7 @@ public class EventWorkbookBuilder {
if(sst != null) {
wbRecords.add(sst);
}
// Now we can have the ExternSheetRecords,
// preceded by a SupBookRecord
if(externs != null) {
@ -94,13 +86,13 @@ public class EventWorkbookBuilder {
wbRecords.add(externs[i]);
}
}
// Finally we need an EoF record
wbRecords.add(EOFRecord.instance);
return Workbook.createWorkbook(wbRecords);
return InternalWorkbook.createWorkbook(wbRecords);
}
/**
* Creates a stub workbook from the supplied records,
* suitable for use with the {@link HSSFFormulaParser}
@ -108,16 +100,16 @@ public class EventWorkbookBuilder {
* @param bounds The BoundSheetRecords in your file
* @return A stub Workbook suitable for use with {@link HSSFFormulaParser}
*/
public static Workbook createStubWorkbook(ExternSheetRecord[] externs,
public static InternalWorkbook createStubWorkbook(ExternSheetRecord[] externs,
BoundSheetRecord[] bounds) {
return createStubWorkbook(externs, bounds, null);
}
/**
* A wrapping HSSFListener which will collect
* A wrapping HSSFListener which will collect
* {@link BoundSheetRecord}s and {@link ExternSheetRecord}s as
* they go past, so you can create a Stub {@link Workbook} from
* they go past, so you can create a Stub {@link InternalWorkbook} from
* them once required.
*/
public static class SheetRecordCollectingListener implements HSSFListener {
@ -125,12 +117,12 @@ public class EventWorkbookBuilder {
private List boundSheetRecords = new ArrayList();
private List externSheetRecords = new ArrayList();
private SSTRecord sstRecord = null;
public SheetRecordCollectingListener(HSSFListener childListener) {
this.childListener = childListener;
}
public BoundSheetRecord[] getBoundSheetRecords() {
return (BoundSheetRecord[])boundSheetRecords.toArray(
new BoundSheetRecord[boundSheetRecords.size()]
@ -144,20 +136,18 @@ public class EventWorkbookBuilder {
public SSTRecord getSSTRecord() {
return sstRecord;
}
public HSSFWorkbook getStubHSSFWorkbook() {
return createStubHSSFWorkbook(
getStubWorkbook()
);
return HSSFWorkbook.create(getStubWorkbook());
}
public Workbook getStubWorkbook() {
public InternalWorkbook getStubWorkbook() {
return createStubWorkbook(
getExternSheetRecords(), getBoundSheetRecords(),
getExternSheetRecords(), getBoundSheetRecords(),
getSSTRecord()
);
}
/**
* Process this record ourselves, and then
* pass it on to our child listener
@ -165,11 +155,11 @@ public class EventWorkbookBuilder {
public void processRecord(Record record) {
// Handle it ourselves
processRecordInternally(record);
// Now pass on to our child
childListener.processRecord(record);
}
/**
* Process the record ourselves, but do not
* pass it on to the child Listener.
@ -186,14 +176,4 @@ public class EventWorkbookBuilder {
}
}
}
/**
* Let us at the {@link Workbook} constructor on
* {@link HSSFWorkbook}
*/
private static class StubHSSFWorkbook extends HSSFWorkbook {
private StubHSSFWorkbook(Workbook wb) {
super(wb);
}
}
}
}

View File

@ -82,6 +82,7 @@ import org.apache.poi.hssf.record.formula.FormulaShifter;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.formula.EvaluationWorkbook.ExternalSheet;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
@ -108,7 +109,8 @@ import org.apache.poi.util.POILogger;
* @author Glen Stampoultzis (glens at apache.org)
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook
*/
public final class Workbook {
@Internal
public final class InternalWorkbook {
/**
* Excel silently truncates long sheet names to 31 chars.
* This constant is used to ensure uniqueness in the first 31 chars
@ -116,7 +118,7 @@ public final class Workbook {
private static final int MAX_SENSITIVE_SHEET_NAME_LEN = 31;
private static final POILogger log = POILogFactory.getLogger(Workbook.class);
private static final POILogger log = POILogFactory.getLogger(InternalWorkbook.class);
private static final int DEBUG = POILogger.DEBUG;
/**
@ -162,7 +164,7 @@ public final class Workbook {
private WriteAccessRecord writeAccess;
private WriteProtectRecord writeProtect;
private Workbook() {
private InternalWorkbook() {
records = new WorkbookRecordList();
boundsheets = new ArrayList<BoundSheetRecord>();
@ -187,11 +189,11 @@ public final class Workbook {
* @param recs an array of Record objects
* @return Workbook object
*/
public static Workbook createWorkbook(List<Record> recs) {
public static InternalWorkbook createWorkbook(List<Record> recs) {
if (log.check( POILogger.DEBUG ))
log.log(DEBUG, "Workbook (readfile) created with reclen=",
Integer.valueOf(recs.size()));
Workbook retval = new Workbook();
InternalWorkbook retval = new InternalWorkbook();
List<Record> records = new ArrayList<Record>(recs.size() / 3);
retval.records.setRecords(records);
@ -329,11 +331,11 @@ public final class Workbook {
* Creates an empty workbook object with three blank sheets and all the empty
* fields. Use this to create a workbook from scratch.
*/
public static Workbook createWorkbook()
public static InternalWorkbook createWorkbook()
{
if (log.check( POILogger.DEBUG ))
log.log( DEBUG, "creating new workbook from scratch" );
Workbook retval = new Workbook();
InternalWorkbook retval = new InternalWorkbook();
List<Record> records = new ArrayList<Record>( 30 );
retval.records.setRecords(records);
List<FormatRecord> formats = retval.formats;

View File

@ -91,7 +91,7 @@ import org.apache.poi.util.POILogger;
* @author Brian Sanders (kestrel at burdell dot org) Active Cell support
* @author Jean-Pierre Paris (jean-pierre.paris at m4x dot org) (Just a little)
*
* @see org.apache.poi.hssf.model.Workbook
* @see org.apache.poi.hssf.model.InternalWorkbook
* @see org.apache.poi.hssf.usermodel.HSSFSheet
*/
public final class Sheet {
@ -151,7 +151,7 @@ public final class Sheet {
*
* @return Sheet object with all values set to those read from the file
*
* @see org.apache.poi.hssf.model.Workbook
* @see org.apache.poi.hssf.model.InternalWorkbook
* @see org.apache.poi.hssf.record.Record
*/
public static Sheet createSheet(RecordStream rs) {

View File

@ -58,7 +58,7 @@ public final class FormatRecord extends StandardRecord {
* get the format index code (for built in formats)
*
* @return the format index code
* @see org.apache.poi.hssf.model.Workbook
* @see org.apache.poi.hssf.model.InternalWorkbook
*/
public int getIndexCode() {
return field_1_index_code;

View File

@ -34,35 +34,32 @@ public final class PaletteRecord extends StandardRecord {
public final static byte STANDARD_PALETTE_SIZE = (byte) 56;
/** The byte index of the first color */
public final static short FIRST_COLOR_INDEX = (short) 0x8;
private List<PColor> field_2_colors;
public PaletteRecord()
{
private final List<PColor> _colors;
public PaletteRecord() {
PColor[] defaultPalette = createDefaultPalette();
field_2_colors = new ArrayList<PColor>(defaultPalette.length);
_colors = new ArrayList<PColor>(defaultPalette.length);
for (int i = 0; i < defaultPalette.length; i++) {
field_2_colors.add(defaultPalette[i]);
_colors.add(defaultPalette[i]);
}
}
public PaletteRecord(RecordInputStream in)
{
public PaletteRecord(RecordInputStream in) {
int field_1_numcolors = in.readShort();
field_2_colors = new ArrayList<PColor>(field_1_numcolors);
_colors = new ArrayList<PColor>(field_1_numcolors);
for (int k = 0; k < field_1_numcolors; k++) {
field_2_colors.add(new PColor(in));
}
_colors.add(new PColor(in));
}
}
public String toString()
{
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("[PALETTE]\n");
buffer.append(" numcolors = ").append(field_2_colors.size()).append('\n');
for (int i = 0; i < field_2_colors.size(); i++) {
PColor c = field_2_colors.get(i);
buffer.append(" numcolors = ").append(_colors.size()).append('\n');
for (int i = 0; i < _colors.size(); i++) {
PColor c = _colors.get(i);
buffer.append("* colornum = ").append(i).append('\n');
buffer.append(c.toString());
buffer.append("/*colornum = ").append(i).append('\n');
@ -71,20 +68,18 @@ public final class PaletteRecord extends StandardRecord {
return buffer.toString();
}
public void serialize(LittleEndianOutput out)
{
out.writeShort(field_2_colors.size());
for (int i = 0; i < field_2_colors.size(); i++) {
field_2_colors.get(i).serialize(out);
public void serialize(LittleEndianOutput out) {
out.writeShort(_colors.size());
for (int i = 0; i < _colors.size(); i++) {
_colors.get(i).serialize(out);
}
}
protected int getDataSize() {
return 2 + field_2_colors.size() * PColor.ENCODED_SIZE;
return 2 + _colors.size() * PColor.ENCODED_SIZE;
}
public short getSid()
{
public short getSid() {
return sid;
}
@ -94,16 +89,14 @@ public final class PaletteRecord extends StandardRecord {
* @return the RGB triplet for the color, or <code>null</code> if the specified index
* does not exist
*/
public byte[] getColor(short byteIndex) {
public byte[] getColor(int byteIndex) {
int i = byteIndex - FIRST_COLOR_INDEX;
if (i < 0 || i >= field_2_colors.size())
{
if (i < 0 || i >= _colors.size()) {
return null;
}
PColor color = field_2_colors.get(i);
return new byte[] { color.red, color.green, color.blue };
return _colors.get(i).getTriplet();
}
/**
* Sets the color value at a given index
*
@ -120,18 +113,16 @@ public final class PaletteRecord extends StandardRecord {
{
return;
}
// may need to grow - fill intervening pallette entries with black
while (field_2_colors.size() <= i) {
field_2_colors.add(new PColor(0, 0, 0));
// may need to grow - fill intervening palette entries with black
while (_colors.size() <= i) {
_colors.add(new PColor(0, 0, 0));
}
PColor custColor = new PColor(red, green, blue);
field_2_colors.set(i, custColor);
_colors.set(i, custColor);
}
/**
* Creates the default palette as PaletteRecord binary data
*
* @see org.apache.poi.hssf.model.Workbook#createPalette
*/
private static PColor[] createDefaultPalette()
{
@ -199,41 +190,45 @@ public final class PaletteRecord extends StandardRecord {
return new PColor(r, g, b);
}
/**
* PColor - element in the list of colors - consider it a "struct"
*/
private static final class PColor {
public static final short ENCODED_SIZE = 4;
public byte red;
public byte green;
public byte blue;
/**
* PColor - element in the list of colors
*/
private static final class PColor {
public static final short ENCODED_SIZE = 4;
private int _red;
private int _green;
private int _blue;
public PColor(int red, int green, int blue) {
this.red=(byte) red;
this.green=(byte) green;
this.blue=(byte) blue;
}
public PColor(int red, int green, int blue) {
_red = red;
_green = green;
_blue = blue;
}
public PColor(RecordInputStream in) {
red=in.readByte();
green=in.readByte();
blue=in.readByte();
in.readByte(); // unused
}
public byte[] getTriplet() {
return new byte[] { (byte) _red, (byte) _green, (byte) _blue };
}
public void serialize(LittleEndianOutput out) {
out.writeByte(red);
out.writeByte(green);
out.writeByte(blue);
out.writeByte(0);
}
public PColor(RecordInputStream in) {
_red = in.readByte();
_green = in.readByte();
_blue = in.readByte();
in.readByte(); // unused
}
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(" red = ").append(red & 0xff).append('\n');
buffer.append(" green = ").append(green & 0xff).append('\n');
buffer.append(" blue = ").append(blue & 0xff).append('\n');
return buffer.toString();
}
public void serialize(LittleEndianOutput out) {
out.writeByte(_red);
out.writeByte(_green);
out.writeByte(_blue);
out.writeByte(0);
}
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append(" red = ").append(_red & 0xff).append('\n');
buffer.append(" green = ").append(_green & 0xff).append('\n');
buffer.append(" blue = ").append(_blue & 0xff).append('\n');
return buffer.toString();
}
}
}
}

View File

@ -25,12 +25,10 @@ import org.apache.poi.util.LittleEndianOutput;
* Description: This record contains an ID that marks when a worksheet was last
* recalculated. It's an optimization Excel uses to determine if it
* needs to recalculate the spreadsheet when it's opened. So far, only
* the two engine ids <code>0x80 0x38 0x01 0x00</code>
* the two engine ids <code>0x80 0x38 0x01 0x00</code>
* and <code>0x60 0x69 0x01 0x00</code> have been seen.<p/>
* REFERENCE: http://chicago.sourceforge.net/devel/docs/excel/biff8.html<p/>
* @author Luc Girardin (luc dot girardin at macrofocus dot com)
*
* @see org.apache.poi.hssf.model.Workbook
*/
public final class RecalcIdRecord extends StandardRecord {
public final static short sid = 0x01C1;

View File

@ -23,7 +23,7 @@ import java.util.*;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.BoolErrRecord;
import org.apache.poi.hssf.record.CellValueRecordInterface;
@ -229,7 +229,7 @@ public class HSSFCell implements Cell {
/**
* Returns the Workbook that this Cell is bound to
*/
protected Workbook getBoundWorkbook() {
protected InternalWorkbook getBoundWorkbook() {
return _book.getWorkbook();
}

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.FontRecord;
import org.apache.poi.hssf.record.StyleRecord;
@ -38,7 +38,7 @@ import org.apache.poi.ss.usermodel.Font;
public final class HSSFCellStyle implements CellStyle {
private ExtendedFormatRecord _format = null;
private short _index = 0;
private Workbook _workbook = null;
private InternalWorkbook _workbook = null;
/** Creates new HSSFCellStyle why would you want to do this?? */
@ -46,7 +46,7 @@ public final class HSSFCellStyle implements CellStyle {
{
this(index, rec, workbook.getWorkbook());
}
protected HSSFCellStyle(short index, ExtendedFormatRecord rec, Workbook workbook)
protected HSSFCellStyle(short index, ExtendedFormatRecord rec, InternalWorkbook workbook)
{
_workbook = workbook;
_index = index;
@ -125,7 +125,7 @@ public final class HSSFCellStyle implements CellStyle {
* the DataFormat against the supplied low level workbook
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
*/
public String getDataFormatString(org.apache.poi.hssf.model.Workbook workbook) {
public String getDataFormatString(org.apache.poi.hssf.model.InternalWorkbook workbook) {
HSSFDataFormat format = new HSSFDataFormat( workbook );
return format.getFormat(getDataFormat());

View File

@ -29,7 +29,7 @@ import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.FormatRecord;
import org.apache.poi.ss.usermodel.BuiltinFormats;
import org.apache.poi.ss.usermodel.DataFormat;
@ -37,15 +37,15 @@ import org.apache.poi.ss.usermodel.DataFormat;
/**
* Identifies both built-in and user defined formats within a workbook.<p/>
* See {@link BuiltinFormats} for a list of supported built-in formats.<p/>
*
*
* <b>International Formats</b><br/>
* Since version 2003 Excel has supported international formats. These are denoted
* Since version 2003 Excel has supported international formats. These are denoted
* with a prefix "[$-xxx]" (where xxx is a 1-7 digit hexadecimal number).
* See the Microsoft article
* See the Microsoft article
* <a href="http://office.microsoft.com/assistance/hfws.aspx?AssetID=HA010346351033&CTT=6&Origin=EC010272491033">
* Creating international number formats
* </a> for more details on these codes.
*
*
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Shawn M. Laubach (slaubach at apache dot org)
*/
@ -53,7 +53,7 @@ public final class HSSFDataFormat implements DataFormat {
private static final String[] _builtinFormats = BuiltinFormats.getAll();
private final Vector<String> _formats = new Vector<String>();
private final Workbook _workbook;
private final InternalWorkbook _workbook;
private boolean _movedBuiltins = false; // Flag to see if need to
// check the built in list
// or if the regular list
@ -64,7 +64,7 @@ public final class HSSFDataFormat implements DataFormat {
* access to the workbooks format records.
* @param workbook the workbook the formats are tied to.
*/
public HSSFDataFormat(Workbook workbook) {
HSSFDataFormat(InternalWorkbook workbook) {
_workbook = workbook;
@SuppressWarnings("unchecked")

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.formula.NamePtg;
@ -42,7 +42,7 @@ import org.apache.poi.ss.formula.FormulaType;
public final class HSSFEvaluationWorkbook implements FormulaRenderingWorkbook, EvaluationWorkbook, FormulaParsingWorkbook {
private final HSSFWorkbook _uBook;
private final Workbook _iBook;
private final InternalWorkbook _iBook;
public static HSSFEvaluationWorkbook create(HSSFWorkbook book) {
if (book == null) {

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.ss.formula.FormulaType;
@ -114,7 +114,7 @@ public final class HSSFName implements Name {
public void setNameName(String nameName){
validateName(nameName);
Workbook wb = _book.getWorkbook();
InternalWorkbook wb = _book.getWorkbook();
_definedNameRec.setNameText(nameName);
int sheetNumber = _definedNameRec.getSheetNumber();
@ -135,7 +135,7 @@ public final class HSSFName implements Name {
private static void validateName(String name){
if(name.length() == 0) throw new IllegalArgumentException("Name cannot be blank");
char c = name.charAt(0);
if(!(c == '_' || Character.isLetter(c)) || name.indexOf(' ') != -1) {
throw new IllegalArgumentException("Invalid name: '"+name+"'; Names must begin with a letter or underscore and not contain spaces");
@ -249,9 +249,7 @@ public final class HSSFName implements Name {
*
* @param value <code>true</code> indicates the name refers to a function.
*/
public void setFunction(boolean value) {
_definedNameRec.setFunction(value);
}
public void setFunction(boolean value) {
_definedNameRec.setFunction(value);
}
}

View File

@ -19,7 +19,7 @@ package org.apache.poi.hssf.usermodel;
import java.util.Iterator;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.ss.usermodel.Font;
@ -74,7 +74,7 @@ public final class HSSFRichTextString implements Comparable<HSSFRichTextString>,
public static final short NO_FONT = 0;
private UnicodeString _string;
private Workbook _book;
private InternalWorkbook _book;
private LabelSSTRecord _record;
public HSSFRichTextString()
@ -90,7 +90,7 @@ public final class HSSFRichTextString implements Comparable<HSSFRichTextString>,
}
}
HSSFRichTextString(Workbook book, LabelSSTRecord record) {
HSSFRichTextString(InternalWorkbook book, LabelSSTRecord record) {
setWorkbookReferences(book, record);
_string = book.getSSTString(record.getSSTIndex());
@ -99,7 +99,7 @@ public final class HSSFRichTextString implements Comparable<HSSFRichTextString>,
/** This must be called to setup the internal work book references whenever
* a RichTextString is added to a cell
*/
void setWorkbookReferences(Workbook book, LabelSSTRecord record) {
void setWorkbookReferences(InternalWorkbook book, LabelSSTRecord record) {
_book = book;
_record = record;
}

View File

@ -32,7 +32,7 @@ import java.util.TreeMap;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.DVRecord;
import org.apache.poi.hssf.record.EscherAggregate;
@ -82,7 +82,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
private final Sheet _sheet;
/** stores rows by zero-based row number */
private final TreeMap<Integer, HSSFRow> _rows;
protected final Workbook _book;
protected final InternalWorkbook _book;
protected final HSSFWorkbook _workbook;
private int _firstrow;
private int _lastrow;
@ -636,7 +636,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
/**
* Sets whether the worksheet is displayed from right to left instead of from left to right.
*
*
* @param value true for right to left, false otherwise.
*/
public void setRightToLeft(boolean value)
@ -1693,7 +1693,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
FontRenderContext frc = new FontRenderContext(null, true, true);
HSSFWorkbook wb = new HSSFWorkbook(_book);
HSSFWorkbook wb = HSSFWorkbook.create(_book); // TODO - is it important to not use _workbook?
HSSFFont defaultFont = wb.getFontAt((short) 0);
str = new AttributedString("" + defaultChar);

View File

@ -38,7 +38,7 @@ import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.AbstractEscherHolderRecord;
import org.apache.poi.hssf.record.BackupRecord;
import org.apache.poi.hssf.record.DrawingGroupRecord;
@ -78,13 +78,13 @@ import org.apache.poi.util.POILogger;
* will construct whether they are reading or writing a workbook. It is also the
* top level object for creating new sheets/etc.
*
* @see org.apache.poi.hssf.model.Workbook
* @see org.apache.poi.hssf.model.InternalWorkbook
* @see org.apache.poi.hssf.usermodel.HSSFSheet
* @author Andrew C. Oliver (acoliver at apache dot org)
* @author Glen Stampoultzis (glens at apache.org)
* @author Shawn Laubach (slaubach at apache dot org)
*/
public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.usermodel.Workbook {
public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.usermodel.Workbook {
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
private static final int MAX_ROW = 0xFFFF;
private static final short MAX_COLUMN = (short)0x00FF;
@ -104,7 +104,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
* this is the reference to the low level Workbook object
*/
private Workbook workbook;
private InternalWorkbook workbook;
/**
* this holds the HSSFSheet objects attached to this workbook
@ -162,25 +162,26 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
private static POILogger log = POILogFactory.getLogger(HSSFWorkbook.class);
public static HSSFWorkbook create(InternalWorkbook book) {
return new HSSFWorkbook(book);
}
/**
* Creates new HSSFWorkbook from scratch (start here!)
*
*/
public HSSFWorkbook()
{
this(Workbook.createWorkbook());
public HSSFWorkbook() {
this(InternalWorkbook.createWorkbook());
}
protected HSSFWorkbook( Workbook book )
{
super(null, null);
workbook = book;
_sheets = new ArrayList( INITIAL_CAPACITY );
names = new ArrayList( INITIAL_CAPACITY );
}
private HSSFWorkbook(InternalWorkbook book) {
super(null, null);
workbook = book;
_sheets = new ArrayList(INITIAL_CAPACITY);
names = new ArrayList(INITIAL_CAPACITY);
}
public HSSFWorkbook(POIFSFileSystem fs) throws IOException {
this(fs,true);
this(fs,true);
}
/**
@ -275,7 +276,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
List records = RecordFactory.createRecords(stream);
workbook = Workbook.createWorkbook(records);
workbook = InternalWorkbook.createWorkbook(records);
setPropertiesFromWorkbook(workbook);
int recOffset = workbook.getNumRecords();
int sheetNum = 0;
@ -321,7 +322,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
* used internally to set the workbook properties.
*/
private void setPropertiesFromWorkbook(Workbook book)
private void setPropertiesFromWorkbook(InternalWorkbook book)
{
this.workbook = book;
@ -1225,7 +1226,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
* @return byte[] array containing the binary representation of this workbook and all contained
* sheets, rows, cells, etc.
*
* @see org.apache.poi.hssf.model.Workbook
* @see org.apache.poi.hssf.model.InternalWorkbook
* @see org.apache.poi.hssf.model.Sheet
*/
public byte[] getBytes() {
@ -1290,8 +1291,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
return workbook.getSSTString(index).getString();
}
protected Workbook getWorkbook()
{
InternalWorkbook getWorkbook() {
return workbook;
}

View File

@ -27,7 +27,7 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.eventusermodel.EventWorkbookBuilder.SheetRecordCollectingListener;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.formula.Ptg;
@ -41,13 +41,13 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public final class TestEventWorkbookBuilder extends TestCase {
private MockHSSFListener mockListen;
private SheetRecordCollectingListener listener;
public void setUp() {
HSSFRequest req = new HSSFRequest();
mockListen = new MockHSSFListener();
listener = new SheetRecordCollectingListener(mockListen);
req.addListenerForAllRecords(listener);
HSSFEventFactory factory = new HSSFEventFactory();
try {
InputStream is = HSSFTestDataSamples.openSampleFileStream("3dFormulas.xls");
@ -56,94 +56,94 @@ public final class TestEventWorkbookBuilder extends TestCase {
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public void testBasics() {
assertNotNull(listener.getSSTRecord());
assertNotNull(listener.getBoundSheetRecords());
assertNotNull(listener.getExternSheetRecords());
}
public void testGetStubWorkbooks() {
assertNotNull(listener.getStubWorkbook());
assertNotNull(listener.getStubHSSFWorkbook());
}
public void testContents() {
assertEquals(2, listener.getSSTRecord().getNumStrings());
assertEquals(3, listener.getBoundSheetRecords().length);
assertEquals(1, listener.getExternSheetRecords().length);
assertEquals(3, listener.getStubWorkbook().getNumSheets());
Workbook ref = listener.getStubWorkbook();
InternalWorkbook ref = listener.getStubWorkbook();
assertEquals("Sh3", ref.findSheetNameFromExternSheet(0));
assertEquals("Sheet1", ref.findSheetNameFromExternSheet(1));
assertEquals("S2", ref.findSheetNameFromExternSheet(2));
}
public void testFormulas() {
FormulaRecord[] fRecs = mockListen.getFormulaRecords();
// Check our formula records
assertEquals(6, fRecs.length);
Workbook stubWB = listener.getStubWorkbook();
InternalWorkbook stubWB = listener.getStubWorkbook();
assertNotNull(stubWB);
HSSFWorkbook stubHSSF = listener.getStubHSSFWorkbook();
assertNotNull(stubHSSF);
// Check these stubs have the right stuff on them
assertEquals("Sheet1", stubWB.getSheetName(0));
assertEquals("S2", stubWB.getSheetName(1));
assertEquals("Sh3", stubWB.getSheetName(2));
// Check we can get the formula without breaking
for(int i=0; i<fRecs.length; i++) {
HSSFFormulaParser.toFormulaString(stubHSSF, fRecs[i].getParsedExpression());
}
// Peer into just one formula, and check that
// all the ptgs give back the right things
Ptg[] ptgs = fRecs[0].getParsedExpression();
assertEquals(1, ptgs.length);
assertTrue(ptgs[0] instanceof Ref3DPtg);
Ref3DPtg ptg = (Ref3DPtg)ptgs[0];
HSSFEvaluationWorkbook book = HSSFEvaluationWorkbook.create(stubHSSF);
assertEquals("Sheet1!A1", ptg.toFormulaString(book));
// Now check we get the right formula back for
// a few sample ones
FormulaRecord fr;
// Sheet 1 A2 is on same sheet
fr = fRecs[0];
assertEquals(1, fr.getRow());
assertEquals(0, fr.getColumn());
assertEquals("Sheet1!A1", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
// Sheet 1 A5 is to another sheet
fr = fRecs[3];
assertEquals(4, fr.getRow());
assertEquals(0, fr.getColumn());
assertEquals("'S2'!A1", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
// Sheet 1 A7 is to another sheet, range
fr = fRecs[5];
assertEquals(6, fr.getRow());
assertEquals(0, fr.getColumn());
assertEquals("SUM(Sh3!A1:A4)", HSSFFormulaParser.toFormulaString(stubHSSF, fr.getParsedExpression()));
// Now, load via Usermodel and re-check
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("3dFormulas.xls");
assertEquals("Sheet1!A1", wb.getSheetAt(0).getRow(1).getCell(0).getCellFormula());
assertEquals("SUM(Sh3!A1:A4)", wb.getSheetAt(0).getRow(6).getCell(0).getCellFormula());
}
private static final class MockHSSFListener implements HSSFListener {
public MockHSSFListener() {}
private final List _records = new ArrayList();
@ -161,4 +161,4 @@ public final class TestEventWorkbookBuilder extends TestCase {
return result;
}
}
}
}

View File

@ -17,10 +17,11 @@
package org.apache.poi.hssf.model;
import junit.framework.TestCase;
import org.apache.poi.hssf.record.FontRecord;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import junit.framework.TestCase;
import org.apache.poi.hssf.usermodel.TestHSSFWorkbook;
/**
* Unit test for the Workbook class.
@ -29,7 +30,7 @@ import junit.framework.TestCase;
*/
public final class TestWorkbook extends TestCase {
public void testFontStuff() {
Workbook wb = (new HW()).getWorkbook();
InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(new HSSFWorkbook());
assertEquals(4, wb.getNumberOfFontRecords());
assertEquals(68, wb.getRecords().size());
@ -82,13 +83,4 @@ public final class TestWorkbook extends TestCase {
assertEquals(6, wb.getFontIndex(n7));
assertEquals(n7, wb.getFontRecordAt(6));
}
private static final class HW extends HSSFWorkbook {
public HW() {
super();
}
protected Workbook getWorkbook() {
return super.getWorkbook();
}
}
}

View File

@ -21,7 +21,7 @@ package org.apache.poi.hssf.usermodel;
import junit.framework.Assert;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
@ -208,7 +208,7 @@ public class SanityChecker
new CheckRecord(EOFRecord.class, '1')
};
private void checkWorkbookRecords(Workbook workbook)
private void checkWorkbookRecords(InternalWorkbook workbook)
{
List records = workbook.getRecords();
assertTrue(records.get(0) instanceof BOFRecord);

View File

@ -31,7 +31,7 @@ import junit.framework.AssertionFailedError;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.OldExcelFormatException;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;
import org.apache.poi.hssf.record.NameRecord;
@ -171,7 +171,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
public void test15375_2() {
baseTest15375(6000);
}
/**Double byte strings*/
public void test15556() {
@ -844,7 +844,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
// Check all names fit within range, and use
// DeletedArea3DPtg
Workbook w = wb.getWorkbook();
InternalWorkbook w = wb.getWorkbook();
for(int i=0; i<w.getNumNames(); i++) {
NameRecord r = w.getNameRecord(i);
assertTrue(r.getSheetNumber() <= wb.getNumberOfSheets());
@ -1249,7 +1249,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
/**
* The resolution for bug 45777 assumed that the maximum text length in a header / footer
* record was 256 bytes. This assumption appears to be wrong. Since the fix for bug 47244,
* POI now supports header / footer text lengths beyond 256 bytes.
* POI now supports header / footer text lengths beyond 256 bytes.
*/
public void test45777() {
HSSFWorkbook wb = new HSSFWorkbook();
@ -1375,7 +1375,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
HSSFWorkbook wb = openSample("45290.xls");
assertEquals(1, wb.getNumberOfSheets());
}
/**
* In POI-2.5 user reported exception when parsing a name with a custom VBA function:
* =MY_VBA_FUNCTION("lskdjflsk")
@ -1455,7 +1455,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
wb.write(out);
out.close();
int size1 = out.size();
out = new ByteArrayOutputStream();
wb.write(out);
out.close();
@ -1469,7 +1469,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
assertEquals(size2, size3);
}
/**
* java.io.IOException: block[ 0 ] already removed
* (is an excel 95 file though)
@ -1484,7 +1484,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
));
}
}
/**
* java.lang.NegativeArraySizeException reading long
* non-unicode data for a name record
@ -1514,7 +1514,7 @@ public final class TestBugs extends BaseTestBugzillaIssues {
*/
public void test48180() {
HSSFWorkbook wb = openSample("48180.xls");
HSSFSheet s = wb.getSheetAt(0);
HSSFCell cell1 = s.getRow(0).getCell(0);
assertEquals("test ", cell1.getStringCellValue().toString());
@ -1524,12 +1524,12 @@ public final class TestBugs extends BaseTestBugzillaIssues {
}
/**
* POI 3.5 beta 7 can not read excel file contain list box (Form Control)
* POI 3.5 beta 7 can not read excel file contain list box (Form Control)
*/
public void test47701() {
openSample("47701.xls");
}
public void test48026() {
openSample("48026.xls");
}

View File

@ -25,7 +25,7 @@ import java.util.TimeZone;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
/**
* Class TestHSSFDateUtil
@ -306,7 +306,7 @@ public final class TestHSSFDateUtil extends TestCase {
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls");
HSSFSheet sheet = workbook.getSheetAt(0);
Workbook wb = workbook.getWorkbook();
InternalWorkbook wb = workbook.getWorkbook();
HSSFRow row;
HSSFCell cell;

View File

@ -25,6 +25,7 @@ import junit.framework.AssertionFailedError;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.Record;
@ -48,6 +49,13 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook {
return HSSFITestDataProvider.getInstance();
}
/**
* gives test code access to the {@link InternalWorkbook} within {@link HSSFWorkbook}
*/
public static InternalWorkbook getInternalWorkbook(HSSFWorkbook wb) {
return wb.getWorkbook();
}
public void testSetRepeatingRowsAndColumns() {
// Test bug 29747
HSSFWorkbook b = new HSSFWorkbook( );

View File

@ -25,7 +25,7 @@ import java.io.IOException;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.BackupRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.Record;
@ -449,7 +449,7 @@ public final class TestWorkbook extends TestCase {
public void testBackupRecord() {
HSSFWorkbook wb = new HSSFWorkbook();
wb.createSheet();
Workbook workbook = wb.getWorkbook();
InternalWorkbook workbook = wb.getWorkbook();
BackupRecord record = workbook.getBackupRecord();
assertEquals(0, record.getBackup());

View File

@ -17,14 +17,13 @@
package org.apache.poi.hssf.util;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.formula.Area3DPtg;
import org.apache.poi.hssf.record.formula.MemFuncPtg;
@ -36,10 +35,11 @@ import org.apache.poi.hssf.usermodel.HSSFName;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.TestHSSFWorkbook;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
/**
*
*
*/
public final class TestAreaReference extends TestCase {
@ -52,54 +52,54 @@ public final class TestAreaReference extends TestCase {
assertTrue("row is abs",cf.isRowAbsolute());
assertTrue("col is abs",cf.isColAbsolute());
assertTrue("string is $A$1",cf.formatAsString().equals("$A$1"));
cf = ar.getLastCell();
assertTrue("row is 4",cf.getRow()==1);
assertTrue("col is 1",cf.getCol()==1);
assertTrue("row is abs",cf.isRowAbsolute());
assertTrue("col is abs",cf.isColAbsolute());
assertTrue("string is $B$2",cf.formatAsString().equals("$B$2"));
CellReference[] refs = ar.getAllReferencedCells();
assertEquals(4, refs.length);
assertEquals(0, refs[0].getRow());
assertEquals(0, refs[0].getCol());
assertNull(refs[0].getSheetName());
assertEquals(0, refs[1].getRow());
assertEquals(1, refs[1].getCol());
assertNull(refs[1].getSheetName());
assertEquals(1, refs[2].getRow());
assertEquals(0, refs[2].getCol());
assertNull(refs[2].getSheetName());
assertEquals(1, refs[3].getRow());
assertEquals(1, refs[3].getCol());
assertNull(refs[3].getSheetName());
}
/**
* References failed when sheet names were being used
* Reported by Arne.Clauss@gedas.de
*/
public void testReferenceWithSheet() {
AreaReference ar;
ar = new AreaReference("Tabelle1!B5:B5");
assertTrue(ar.isSingleCell());
TestCellReference.confirmCell(ar.getFirstCell(), "Tabelle1", 4, 1, false, false, "Tabelle1!B5");
assertEquals(1, ar.getAllReferencedCells().length);
ar = new AreaReference("Tabelle1!$B$5:$B$7");
assertFalse(ar.isSingleCell());
TestCellReference.confirmCell(ar.getFirstCell(), "Tabelle1", 4, 1, true, true, "Tabelle1!$B$5");
TestCellReference.confirmCell(ar.getLastCell(), "Tabelle1", 6, 1, true, true, "Tabelle1!$B$7");
// And all that make it up
CellReference[] allCells = ar.getAllReferencedCells();
assertEquals(3, allCells.length);
@ -108,16 +108,6 @@ public final class TestAreaReference extends TestCase {
TestCellReference.confirmCell(allCells[2], "Tabelle1", 6, 1, true, true, "Tabelle1!$B$7");
}
// TODO - remove this sub-class
private static final class HSSFWB extends HSSFWorkbook {
public HSSFWB(InputStream in) throws IOException {
super(in);
}
public Workbook getWorkbook() {
return super.getWorkbook();
}
}
public void testContiguousReferences() {
String refSimple = "$C$10:$C$10";
String ref2D = "$C$10:$D$11";
@ -138,15 +128,21 @@ public final class TestAreaReference extends TestCase {
try {
new AreaReference(refDCSimple);
fail();
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException e) {
// expected during successful test
}
try {
new AreaReference(refDC2D);
fail();
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException e) {
// expected during successful test
}
try {
new AreaReference(refDC3D);
fail();
} catch(IllegalArgumentException e) {}
} catch(IllegalArgumentException e) {
// expected during successful test
}
// Test that we split as expected
AreaReference[] refs;
@ -193,8 +189,8 @@ public final class TestAreaReference extends TestCase {
public void testDiscontinousReference() throws Exception {
InputStream is = HSSFTestDataSamples.openSampleFileStream("44167.xls");
HSSFWB wb = new HSSFWB(is);
Workbook workbook = wb.getWorkbook();
HSSFWorkbook wb = new HSSFWorkbook(is);
InternalWorkbook workbook = TestHSSFWorkbook.getInternalWorkbook(wb);
HSSFEvaluationWorkbook eb = HSSFEvaluationWorkbook.create(wb);
assertEquals(1, wb.getNumberOfNames());
@ -252,18 +248,18 @@ public final class TestAreaReference extends TestCase {
HSSFCell c = r.getCell((int)cref.getCol());
assertNotNull(c);
}
public void testSpecialSheetNames() {
AreaReference ar;
ar = new AreaReference("'Sheet A'!A1:A1");
confirmAreaSheetName(ar, "Sheet A", "'Sheet A'!A1");
ar = new AreaReference("'Hey! Look Here!'!A1:A1");
confirmAreaSheetName(ar, "Hey! Look Here!", "'Hey! Look Here!'!A1");
ar = new AreaReference("'O''Toole'!A1:B2");
confirmAreaSheetName(ar, "O'Toole", "'O''Toole'!A1:B2");
ar = new AreaReference("'one:many'!A1:B2");
confirmAreaSheetName(ar, "one:many", "'one:many'!A1:B2");
}
@ -273,25 +269,24 @@ public final class TestAreaReference extends TestCase {
assertEquals(sheetName, cells[0].getSheetName());
assertEquals(expectedFullText, ar.formatAsString());
}
public void testWholeColumnRefs() {
confirmWholeColumnRef("A:A", 0, 0, false, false);
confirmWholeColumnRef("$C:D", 2, 3, true, false);
confirmWholeColumnRef("AD:$AE", 29, 30, false, true);
}
confirmWholeColumnRef("A:A", 0, 0, false, false);
confirmWholeColumnRef("$C:D", 2, 3, true, false);
confirmWholeColumnRef("AD:$AE", 29, 30, false, true);
}
private static void confirmWholeColumnRef(String ref, int firstCol, int lastCol, boolean firstIsAbs, boolean lastIsAbs) {
AreaReference ar = new AreaReference(ref);
confirmCell(ar.getFirstCell(), 0, firstCol, true, firstIsAbs);
confirmCell(ar.getLastCell(), 0xFFFF, lastCol, true, lastIsAbs);
}
private static void confirmWholeColumnRef(String ref, int firstCol, int lastCol, boolean firstIsAbs, boolean lastIsAbs) {
AreaReference ar = new AreaReference(ref);
confirmCell(ar.getFirstCell(), 0, firstCol, true, firstIsAbs);
confirmCell(ar.getLastCell(), 0xFFFF, lastCol, true, lastIsAbs);
}
private static void confirmCell(CellReference cell, int row, int col, boolean isRowAbs,
boolean isColAbs) {
assertEquals(row, cell.getRow());
assertEquals(col, cell.getCol());
assertEquals(isRowAbs, cell.isRowAbsolute());
assertEquals(isColAbs, cell.isColAbsolute());
}
private static void confirmCell(CellReference cell, int row, int col, boolean isRowAbs,
boolean isColAbs) {
assertEquals(row, cell.getRow());
assertEquals(col, cell.getCol());
assertEquals(isRowAbs, cell.isRowAbsolute());
assertEquals(isColAbs, cell.isColAbsolute());
}
}