| Method from org.apache.cocoon.poi.hssf.model.Sheet Detail: |
public void addDBCellRecords() {
int offset = 0;
int recnum = 0;
int rownum = 0;
int lastrow = 0;
long lastrowoffset = 0;
IndexRecord index = null;
// ArrayList rowOffsets = new ArrayList();
IntList rowOffsets = new IntList();
for (recnum = 0; recnum < records.size(); recnum++)
{
Record rec = ( Record ) records.get(recnum);
if (rec.getSid() == IndexRecord.sid)
{
index = ( IndexRecord ) rec;
}
if (rec.getSid() != RowRecord.sid)
{
offset += rec.serialize().length;
}
else
{
break;
}
}
// First Row Record
for (; recnum < records.size(); recnum++)
{
Record rec = ( Record ) records.get(recnum);
if (rec.getSid() == RowRecord.sid)
{
rownum++;
rowOffsets.add(offset);
if ((rownum % 32) == 0)
{
// if this is the last rec in a dbcell block
// find the next row or last value record
for (int rn = recnum; rn < records.size(); rn++)
{
rec = ( Record ) records.get(rn);
if ((!rec.isInValueSection())
|| (rec.getSid() == RowRecord.sid))
{
// here is the next row or last value record
records.add(rn,
createDBCell(offset, rowOffsets,
index));
recnum = rn;
break;
}
}
}
else
{
}
}
if (!rec.isInValueSection())
{
records.add(recnum, createDBCell(offset, rowOffsets, index));
break;
}
offset += rec.serialize().length;
}
}
Not currently used method to calculate and add dbcell records |
public void addRow(RowRecord row) {
log.debug("addRow ");
DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc());
if (row.getRowNumber() > d.getLastRow())
{
d.setLastRow(row.getRowNumber() + 1);
}
if (row.getRowNumber() < d.getFirstRow())
{
d.setFirstRow(row.getRowNumber());
}
IndexRecord index = null;
for (int k = loc; k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
if (rec.getSid() == IndexRecord.sid)
{
index = ( IndexRecord ) rec;
}
if (rec.getSid() == RowRecord.sid)
{
RowRecord rowrec = ( RowRecord ) rec;
if (rowrec.getRowNumber() > row.getRowNumber())
{
records.add(k, row);
loc = k;
break;
}
}
if (rec.getSid() == WindowTwoRecord.sid)
{
records.add(k, row);
loc = k;
break;
}
}
if (index != null)
{
if (index.getLastRowAdd1() < = row.getRowNumber())
{
index.setLastRowAdd1(row.getRowNumber() + 1);
}
}
log.debug("exit addRow");
}
Adds a row record to the sheet
This method is "loc" sensitive. Meaning you need to set LOC to where you
want it to start searching. If you don't know do this: setLoc(getDimsLoc).
When adding several rows you can just start at the last one by leaving loc
at what this sets it to. |
public void addValueRecord(short row,
CellValueRecordInterface col) {
log.debug((new StringBuffer("add value record row,loc ")).append(row)
.append(",").append(loc).toString());
DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc());
if (col.getColumn() > d.getLastCol())
{
d.setLastCol(( short ) (col.getColumn() + 1));
}
if (col.getColumn() < d.getFirstCol())
{
d.setFirstCol(col.getColumn());
}
for (int k = loc; k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
if (rec.getSid() == RowRecord.sid)
{
RowRecord rowrec = ( RowRecord ) rec;
if (rowrec.getRowNumber() == col.getRow())
{
records.add(k + 1, col);
loc = k;
if (rowrec.getLastCol() < = col.getColumn())
{
rowrec.setLastCol((( short ) (col.getColumn() + 1)));
}
break;
}
}
}
}
Adds a value record to the sheet's contained binary records
(i.e. LabelSSTRecord or NumberRecord).
This method is "loc" sensitive. Meaning you need to set LOC to where you
want it to start searching. If you don't know do this: setLoc(getDimsLoc).
When adding several rows you can just start at the last one by leaving loc
at what this sets it to. |
public void checkDimsLoc(Record rec,
int recloc) {
if (rec.getSid() == DimensionsRecord.sid)
{
loc = recloc;
dimsloc = recloc;
}
}
in the event the record is a dimensions record, resets both the loc index and dimsloc index |
public void convertLabelRecords(Workbook wb) {
log.debug("convertLabelRecords called");
if (containsLabels)
{
for (int k = 0; k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
if (rec.getSid() == LabelRecord.sid)
{
LabelRecord oldrec = ( LabelRecord ) rec;
records.remove(k);
LabelSSTRecord newrec = new LabelSSTRecord();
int stringid =
wb.addSSTString(oldrec.getValue());
newrec.setRow(oldrec.getRow());
newrec.setColumn(oldrec.getColumn());
newrec.setXFIndex(oldrec.getXFIndex());
newrec.setSSTIndex(stringid);
records.add(k, newrec);
}
}
}
log.debug("convertLabelRecords exit");
}
This is basically a kludge to deal with the now obsolete Label records. If
you have to read in a sheet that contains Label records, be aware that the rest
of the API doesn't deal with them, the low level structure only provides read-only
semi-immutable structures (the sets are there for interface conformance with NO
impelmentation). In short, you need to call this function passing it a reference
to the Workbook object. All labels will be converted to LabelSST records and their
contained strings will be written to the Shared String tabel (SSTRecord) within
the Workbook. |
protected Record createBOF() {
BOFRecord retval = new BOFRecord();
retval.setVersion(( short ) 0x600);
retval.setType(( short ) 0x010);
// retval.setBuild((short)0x10d3);
retval.setBuild(( short ) 0x0dbb);
retval.setBuildYear(( short ) 1996);
retval.setHistoryBitMask(0xc1);
retval.setRequiredVersion(0x6);
return retval;
}
|
public BlankRecord createBlank(short row,
short col) {
log.debug((new StringBuffer("create blank row,col ")).append(row)
.append(",").append(col).toString());
BlankRecord rec = new BlankRecord();
rec.setRow(( short ) row);
rec.setColumn(col);
rec.setXFIndex(( short ) 0x0f);
return rec;
}
create a BLANK record (does not add it to the records contained in this sheet) |
protected Record createCalcCount() {
CalcCountRecord retval = new CalcCountRecord();
retval.setIterations(( short ) 0x64); // default 64 iterations
return retval;
}
creates the CalcCount record and sets it to 0x64 (default number of iterations) |
protected Record createCalcMode() {
CalcModeRecord retval = new CalcModeRecord();
retval.setCalcMode(( short ) 1);
return retval;
}
creates the CalcMode record and sets it to 1 (automatic formula caculation) |
protected Record createColInfo() {
ColumnInfoRecord retval = new ColumnInfoRecord();
retval.setColumnWidth(( short ) 0x8);
retval.setOptions(( short ) 6);
retval.setXFIndex(( short ) 0x0f);
return retval;
}
creates the ColumnInfo Record and sets it to a default column/width |
protected Record createDefaultColWidth() {
DefaultColWidthRecord retval = new DefaultColWidthRecord();
retval.setColWidth(( short ) 8);
return retval;
}
creates the DefaultColWidth Record and sets it to 8 |
protected Record createDefaultRowHeight() {
DefaultRowHeightRecord retval = new DefaultRowHeightRecord();
retval.setOptionFlags(( short ) 0);
retval.setRowHeight(( short ) 0xff);
return retval;
}
creates the DefaultRowHeight Record and sets its options to 0 and rowheight to 0xff |
protected Record createDelta() {
DeltaRecord retval = new DeltaRecord();
retval.setMaxChange((( double ) 0.0010));
return retval;
}
creates the Delta record and sets it to 0.0010 (default accuracy) |
protected Record createDimensions() {
DimensionsRecord retval = new DimensionsRecord();
retval.setFirstCol(( short ) 0);
retval.setLastRow(1); // one more than it is
retval.setFirstRow(0);
retval.setLastCol(( short ) 1); // one more than it is
return retval;
}
creates the Dimensions Record and sets it to bogus values (you should set this yourself
or let the high level API do it for you) |
protected Record createEOF() {
return new EOFRecord();
}
|
protected Record createFooter() {
FooterRecord retval = new FooterRecord();
retval.setFooterLength(( byte ) 0);
retval.setFooter(null);
return retval;
}
creates the Footer Record and sets it to nothing/0 length |
public FormulaRecord createFormula(short row,
short col,
String formula) {
log.debug((new StringBuffer("create formula row,col,formula "))
.append(row).append(",").append(col).append(",").append(formula)
.toString());
FormulaRecord rec = new FormulaRecord();
rec.setRow(row);
rec.setColumn(col);
rec.setOptions(( short ) 2);
rec.setValue(0);
rec.setXFIndex(( short ) 0x0f);
Ptg[] ptg = FormulaUtil.parseFormula(formula);
int size = 0;
for (int k = 0; k < ptg.length; k++)
{
size += ptg[ k ].getSize();
rec.pushExpressionToken(ptg[ k ]);
}
rec.setExpressionLength(( short ) size);
return rec;
}
Attempts to parse the formula into PTGs and create a formula record
DOES NOT WORK YET |
protected Record createGridset() {
GridsetRecord retval = new GridsetRecord();
retval.setGridset(true);
return retval;
}
creates the Gridset record and sets it to true (user has mucked with the gridlines) |
protected Record createGuts() {
GutsRecord retval = new GutsRecord();
retval.setLeftRowGutter(( short ) 0);
retval.setTopColGutter(( short ) 0);
retval.setRowLevelMax(( short ) 0);
retval.setColLevelMax(( short ) 0);
return retval;
}
creates the Guts record and sets leftrow/topcol guttter and rowlevelmax/collevelmax to 0 |
protected Record createHCenter() {
HCenterRecord retval = new HCenterRecord();
retval.setHCenter(false);
return retval;
}
creates the HCenter Record and sets it to false (don't horizontally center) |
protected Record createHeader() {
HeaderRecord retval = new HeaderRecord();
retval.setHeaderLength(( byte ) 0);
retval.setHeader(null);
return retval;
}
creates the Header Record and sets it to nothing/0 length |
protected Record createIndex() {
IndexRecord retval = new IndexRecord();
retval.setFirstRow(0); // must be set explicitly
retval.setLastRowAdd1(0);
return retval;
}
creates the Index record - not currently used |
protected Record createIteration() {
IterationRecord retval = new IterationRecord();
retval.setIteration(false);
return retval;
}
creates the Iteration record and sets it to false (don't iteratively calculate formulas) |
public LabelSSTRecord createLabelSST(short row,
short col,
int index) {
log.debug((new StringBuffer("create labelsst row,col,index "))
.append(row).append(",").append(col).append(",").append(index)
.toString());
LabelSSTRecord rec = new LabelSSTRecord();
rec.setRow(row);
rec.setColumn(col);
rec.setSSTIndex(index);
rec.setXFIndex(( short ) 0x0f);
return rec;
}
Create a LABELSST Record (does not add it to the records contained in this sheet) |
public NumberRecord createNumber(short row,
short col,
double value) {
log.debug((new StringBuffer("create number row,col,value "))
.append(row).append(",").append(col).append(",").append(value)
.toString());
NumberRecord rec = new NumberRecord();
rec.setRow(( short ) row);
rec.setColumn(col);
rec.setValue(value);
rec.setXFIndex(( short ) 0x0f);
return rec;
}
Create a NUMBER Record (does not add it to the records contained in this sheet) |
protected Record createPrintGridlines() {
PrintGridlinesRecord retval = new PrintGridlinesRecord();
retval.setPrintGridlines(false);
return retval;
}
creates the PrintGridlines record and sets it to false (that makes for ugly sheets) |
protected Record createPrintHeaders() {
PrintHeadersRecord retval = new PrintHeadersRecord();
retval.setPrintHeaders(false);
return retval;
}
creates the PrintHeaders record and sets it to false (we don't create headers yet so why print them) |
protected Record createPrintSetup() {
PrintSetupRecord retval = new PrintSetupRecord();
retval.setPaperSize(( short ) 1);
retval.setScale(( short ) 100);
retval.setPageStart(( short ) 1);
retval.setFitWidth(( short ) 1);
retval.setFitHeight(( short ) 1);
retval.setOptions(( short ) 2);
retval.setHResolution(( short ) 300);
retval.setVResolution(( short ) 300);
retval.setHeaderMargin(( double ) 0.5);
retval.setFooterMargin(( double ) 0.5);
retval.setCopies(( short ) 0);
return retval;
}
creates the PrintSetup Record and sets it to defaults and marks it invalid |
protected Record createRefMode() {
RefModeRecord retval = new RefModeRecord();
retval.setMode(retval.USE_A1_MODE);
return retval;
}
creates the RefMode record and sets it to A1 Mode (default reference mode) |
public RowRecord createRow(int row) {
log.debug((new StringBuffer("create row number ")).append(row)
.toString());
RowRecord rowrec = new RowRecord();
rowrec.setRowNumber(( short ) row);
rowrec.setHeight(( short ) 0xff);
rowrec.setOptimize(( short ) 0x0);
rowrec.setOptionFlags(( short ) 0x0);
rowrec.setXFIndex(( short ) 0x0);
return rowrec;
}
Create a row record. (does not add it to the records contained in this sheet) |
protected Record createSaveRecalc() {
SaveRecalcRecord retval = new SaveRecalcRecord();
retval.setRecalc(true);
return retval;
}
creates the SaveRecalc record and sets it to true (recalculate before saving) |
protected Record createSelection() {
SelectionRecord retval = new SelectionRecord();
retval.setPane(( byte ) 0x3);
retval.setActiveCellCol(( short ) 0x0);
retval.setActiveCellRow(( short ) 0x0);
retval.setNumRefs(( short ) 0x0);
return retval;
}
Creates the Selection record and sets it to nothing selected |
public static Sheet createSheet() {
log.debug("Sheet createsheet from scratch called");
Sheet retval = new Sheet();
ArrayList records = new ArrayList(30);
records.add(retval.createBOF());
// records.add(retval.createIndex());
records.add(retval.createCalcMode());
records.add(retval.createCalcCount());
records.add(retval.createRefMode());
records.add(retval.createIteration());
records.add(retval.createDelta());
records.add(retval.createSaveRecalc());
records.add(retval.createPrintHeaders());
records.add(retval.createPrintGridlines());
records.add(retval.createGridset());
records.add(retval.createGuts());
retval.defaultrowheight =
( DefaultRowHeightRecord ) retval.createDefaultRowHeight();
records.add(retval.defaultrowheight);
records.add(retval.createWSBool());
records.add(retval.createHeader());
records.add(retval.createFooter());
records.add(retval.createHCenter());
records.add(retval.createVCenter());
records.add(retval.createPrintSetup());
retval.defaultcolwidth =
( DefaultColWidthRecord ) retval.createDefaultColWidth();
records.add(retval.defaultcolwidth);
retval.dims = ( DimensionsRecord ) retval.createDimensions();
retval.dimsloc = 19;
records.add(retval.dims);
records.add(retval.createWindowTwo());
retval.setLoc(records.size() - 1);
records.add(retval.createSelection());
records.add(retval.createEOF());
retval.records = records;
log.debug("Sheet createsheet from scratch exit");
return retval;
}
Creates a sheet with all the usual records minus values and the "index"
record (not required). Sets the location pointer to where the first value
records should go. Use this to create a sheet from "scratch". |
public static Sheet createSheet(Record[] records,
int sheetnum) {
log.debug("Sheet createSheet (exisiting file) assumed offset 0");
return createSheet(records, sheetnum, 0);
}
read support (offset = 0) Same as createSheet(Record[] recs, int, int)
only the record offset is assumed to be 0. |
public static Sheet createSheet(Record[] recs,
int sheetnum,
int offset) {
log.debug(
(new StringBuffer(
"Sheet createSheet (existing file) with ")).append(
recs.length).toString());
Sheet retval = new Sheet();
ArrayList records = new ArrayList(recs.length / 5);
for (int k = offset; k < recs.length; k++)
{
Record rec = recs[ k ];
if (rec.getSid() == LabelRecord.sid)
{
log.debug("Hit label record");
retval.containsLabels = true;
}
if (rec.getSid() == EOFRecord.sid)
{
log.debug("Hit EOF record at ");
records.add(rec);
break;
}
else if (rec.getSid() == DimensionsRecord.sid)
{
retval.dims = ( DimensionsRecord ) rec;
retval.dimsloc = k - offset;
}
else if (rec.getSid() == ColumnInfoRecord.sid)
{
if (retval.columnSizes == null)
{
retval.columnSizes = new ArrayList();
}
retval.columnSizes.add(( ColumnInfoRecord ) rec);
}
else if (rec.getSid() == DefaultColWidthRecord.sid)
{
retval.defaultcolwidth = ( DefaultColWidthRecord ) rec;
}
else if (rec.getSid() == DefaultRowHeightRecord.sid)
{
retval.defaultrowheight = ( DefaultRowHeightRecord ) rec;
}
records.add(rec);
}
retval.records = records;
log.debug("sheet createSheet (existing file) exited");
return retval;
}
read support (offset used as starting point for search) for low level
API. Pass in an array of Record objects, the sheet number (0 based) and
a record offset (should be the location of the sheets BOF record). A Sheet
object is constructed and passed back with all of its initialization set
to the passed in records and references to those records held. This function
is normally called via Workbook. |
protected Record createVCenter() {
VCenterRecord retval = new VCenterRecord();
retval.setVCenter(false);
return retval;
}
creates the VCenter Record and sets it to false (don't horizontally center) |
protected Record createWSBool() {
WSBoolRecord retval = new WSBoolRecord();
retval.setWSBool1(( byte ) 0x4);
retval.setWSBool2(( byte ) 0xffffffc1);
return retval;
}
creates the WSBoolRecord and sets its values to defaults |
protected Record createWindowTwo() {
WindowTwoRecord retval = new WindowTwoRecord();
retval.setOptions(( short ) 0x6b6);
retval.setTopRow(( short ) 0);
retval.setLeftCol(( short ) 0);
retval.setHeaderColor(0x40);
retval.setPageBreakZoom(( short ) 0);
retval.setNormalZoom(( short ) 0);
return retval;
}
creates the WindowTwo Record and sets it to:
options = 0x6b6
toprow = 0
leftcol = 0
headercolor = 0x40
pagebreakzoom = 0x0
normalzoom = 0x0 |
public short getColumnWidth(short column) {
short retval = 0;
ColumnInfoRecord ci = null;
int k = 0;
if (columnSizes != null)
{
for (k = 0; k < columnSizes.size(); k++)
{
ci = ( ColumnInfoRecord ) columnSizes.get(k);
if ((ci.getFirstColumn() >= column)
&& (ci.getLastColumn() < = column))
{
break;
}
ci = null;
}
}
if (ci != null)
{
retval = ci.getColumnWidth();
}
else
{
retval = defaultcolwidth.getColWidth();
}
return retval;
}
get the width of a given column in units of 1/20th of a point width (twips?) |
public short getDefaultColumnWidth() {
return defaultcolwidth.getColWidth();
}
get the default column width for the sheet (if the columns do not define their own width) |
public short getDefaultRowHeight() {
return defaultrowheight.getRowHeight();
}
get the default row height for the sheet (if the rows do not define their own height) |
public int getDimsLoc() {
log.debug((new StringBuffer("getDimsLoc dimsloc= ")).append(dimsloc)
.toString());
return dimsloc;
}
get the location of the DimensionsRecord (which is the last record before the value section) |
public int getLoc() {
log.debug((new StringBuffer("sheet.getLoc(): ")).append(loc)
.toString());
return loc;
}
Returns the location pointer to the first record to look for when adding rows/values |
public RowRecord getNextRow() {
log.debug((new StringBuffer("getNextRow loc= ")).append(loc)
.toString());
if (this.getLoc() < records.size())
{
for (int k = this.getLoc(); k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
this.setLoc(k + 1);
if (rec.getSid() == RowRecord.sid)
{
return ( RowRecord ) rec;
}
}
}
return null;
}
get the NEXT RowRecord (from LOC). The first record that is a Row record
(starting at LOC) will be returned.
This method is "loc" sensitive. Meaning you need to set LOC to where you
want it to start searching. If you don't know do this: setLoc(getDimsLoc).
When adding several rows you can just start at the last one by leaving loc
at what this sets it to. For this method, set loc to dimsloc to start with.
subsequent calls will return rows in (physical) sequence or NULL when you get to the end. |
public Record getNextRowOrValue() {
log.debug((new StringBuffer("getNextRow loc= ")).append(loc)
.toString());
if (this.getLoc() < records.size())
{
for (int k = this.getLoc(); k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
this.setLoc(k + 1);
if (rec.getSid() == RowRecord.sid)
{
return rec;
}
else if (rec.isValue())
{
return rec;
}
}
}
return null;
}
get the NEXT RowRecord or CellValueRecord(from LOC). The first record that
is a Row record or CellValueRecord(starting at LOC) will be returned.
This method is "loc" sensitive. Meaning you need to set LOC to where you
want it to start searching. If you don't know do this: setLoc(getDimsLoc).
When adding several rows you can just start at the last one by leaving loc
at what this sets it to. For this method, set loc to dimsloc to start with.
subsequent calls will return rows in (physical) sequence or NULL when you get to the end. |
public CellValueRecordInterface getNextValueRecord() {
log.debug((new StringBuffer("getNextValue loc= ")).append(loc)
.toString());
if (this.getLoc() < records.size())
{
for (int k = getLoc(); k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
this.setLoc(k + 1);
if (rec instanceof CellValueRecordInterface)
{
return ( CellValueRecordInterface ) rec;
}
}
}
return null;
}
get the NEXT value record (from LOC). The first record that is a value record
(starting at LOC) will be returned.
This method is "loc" sensitive. Meaning you need to set LOC to where you
want it to start searching. If you don't know do this: setLoc(getDimsLoc).
When adding several rows you can just start at the last one by leaving loc
at what this sets it to. For this method, set loc to dimsloc to start with,
subsequent calls will return values in (physical) sequence or NULL when you get to the end. |
public int getNumRecords() {
log.debug("Sheet.getNumRecords");
log.debug("returning:" + records.size());
return records.size();
}
Returns the number of low level binary records in this sheet. |
public int getPreOffset() {
return preoffset;
}
get the preoffset when using DBCELL records (currently unused) - this is
the position of this sheet within the whole file. |
public RowRecord getRow(short rownum) {
log.debug((new StringBuffer("getNextRow loc= ")).append(loc)
.toString());
if (this.getLoc() < records.size())
{
for (int k = this.getLoc(); k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
this.setLoc(k + 1);
if (rec.getSid() == RowRecord.sid)
{
if ((( RowRecord ) rec).getRowNumber() == rownum)
{
return ( RowRecord ) rec;
}
}
}
}
return null;
}
get the NEXT (from LOC) RowRecord where rownumber matches the given rownum.
The first record that is a Row record (starting at LOC) that has the
same rownum as the given rownum will be returned.
This method is "loc" sensitive. Meaning you need to set LOC to where you
want it to start searching. If you don't know do this: setLoc(getDimsLoc).
When adding several rows you can just start at the last one by leaving loc
at what this sets it to. For this method, set loc to dimsloc to start with.
subsequent calls will return rows in (physical) sequence or NULL when you get to the end. |
public void removeRow(RowRecord row) {
IndexRecord index = null;
setLoc(getDimsLoc());
for (int k = loc; k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
// checkDimsLoc(rec,k);
if (rec.getSid() == RowRecord.sid)
{
RowRecord rowrec = ( RowRecord ) rec;
if (rowrec.getRowNumber() == row.getRowNumber())
{
records.remove(k);
break;
}
}
if (rec.getSid() == WindowTwoRecord.sid)
{
break;
}
}
}
Removes a row record
This method is not loc sensitive, it resets loc to = dimsloc so no worries. |
public void removeValueRecord(short row,
CellValueRecordInterface col) {
log.debug((new StringBuffer("remove value record row,dimsloc "))
.append(row).append(",").append(dimsloc).toString());
loc = dimsloc;
for (int k = loc; k < records.size(); k++)
{
Record rec = ( Record ) records.get(k);
// checkDimsLoc(rec,k);
if (rec.isValue())
{
CellValueRecordInterface cell =
( CellValueRecordInterface ) rec;
if ((cell.getRow() == col.getRow())
&& (cell.getColumn() == col.getColumn()))
{
records.remove(k);
break;
}
}
}
}
remove a value record from the records array.
This method is not loc sensitive, it resets loc to = dimsloc so no worries. |
public void replaceValueRecord(CellValueRecordInterface newval) {
setLoc(dimsloc);
log.debug("replaceValueRecord ");
CellValueRecordInterface oldval = getNextValueRecord();
while (oldval != null)
{
if (oldval.isEqual(newval))
{
records.set(( short ) (getLoc() - 1), newval);
return;
}
oldval = getNextValueRecord();
}
addValueRecord(newval.getRow(), newval);
setLoc(dimsloc);
}
replace a value record from the records array.
This method is not loc sensitive, it resets loc to = dimsloc so no worries. |
public byte[] serialize() {
log.debug("Sheet.serialize");
// addDBCellRecords();
// setColumnWidth((short)0,(short)0x11db); was for testing
byte[] retval = null;
ArrayList bytes = new ArrayList(4096);
int arraysize = 0;
int pos = 0;
for (int k = 0; k < records.size(); k++)
{
bytes.add((( Record ) records.get(k)).serialize());
// byte[] temp = (byte[])bytes.get(bytes.size() -1 );
// log.debug((new StringBuffer("temporary array is ").append(temp.length));
}
for (int k = 0; k < bytes.size(); k++)
{
arraysize += (( byte [] ) bytes.get(k)).length;
log.debug((new StringBuffer("arraysize=")).append(arraysize)
.toString());
}
retval = new byte[ arraysize ];
for (int k = 0; k < bytes.size(); k++)
{
byte[] rec = (( byte [] ) bytes.get(k));
System.arraycopy(rec, 0, retval, pos, rec.length);
pos += rec.length;
}
log.debug((new StringBuffer("Sheet.serialize returning "))
.append(retval).toString());
return retval;
}
Serializes all records in the sheet into one big byte array. Use this to write
the sheet out. |
public void setColumnWidth(short column,
short width) {
ColumnInfoRecord ci = null;
int k = 0;
if (columnSizes == null)
{
columnSizes = new ArrayList();
}
int cioffset = getDimsLoc() - columnSizes.size();
for (k = 0; k < columnSizes.size(); k++)
{
ci = ( ColumnInfoRecord ) columnSizes.get(k);
if ((ci.getFirstColumn() >= column)
&& (ci.getLastColumn() < = column))
{
break;
}
ci = null;
}
if (ci != null)
{
if (ci.getColumnWidth() == width)
{
// do nothing...the cell's width is equal to what we're setting it to.
}
else if ((ci.getFirstColumn() == column)
&& (ci.getLastColumn() == column))
{ // if its only for this cell then
ci.setColumnWidth(width); // who cares, just change the width
}
else if ((ci.getFirstColumn() == column)
|| (ci.getLastColumn() == column))
{
// okay so the width is different but the first or last column == the column we'return setting
// we'll just divide the info and create a new one
if (ci.getFirstColumn() == column)
{
ci.setFirstColumn(( short ) (column + 1));
}
else
{
ci.setLastColumn(( short ) (column - 1));
}
ColumnInfoRecord nci = ( ColumnInfoRecord ) createColInfo();
nci.setFirstColumn(column);
nci.setLastColumn(column);
nci.setOptions(ci.getOptions());
nci.setXFIndex(ci.getXFIndex());
nci.setColumnWidth(width);
columnSizes.add(k, nci);
records.add((1 + getDimsLoc() - columnSizes.size()) + k, nci);
dimsloc++;
}
}
else
{
// okay so there ISN'T a column info record that cover's this column so lets create one!
ColumnInfoRecord nci = ( ColumnInfoRecord ) createColInfo();
nci.setFirstColumn(column);
nci.setLastColumn(column);
nci.setColumnWidth(width);
columnSizes.add(k, nci);
records.add((1 + getDimsLoc() - columnSizes.size()) + k, nci);
dimsloc++;
}
}
set the width for a given column in 1/20th of a character width units |
public void setDefaultColumnWidth(short dcw) {
defaultcolwidth.setColWidth(dcw);
}
set the default column width for the sheet (if the columns do not define their own width) |
public void setDefaultRowHeight(short dch) {
defaultrowheight.setRowHeight(dch);
}
set the default row height for the sheet (if the rows do not define their own height) |
public void setDimensions(short firstrow,
short firstcol,
short lastrow,
short lastcol) {
log.debug("Sheet.setDimensions");
log.debug((new StringBuffer("firstrow")).append(firstrow)
.append("firstcol").append(firstcol).append("lastrow")
.append(lastrow).append("lastcol").append(lastcol).toString());
dims.setFirstCol(firstcol);
dims.setFirstRow(firstrow);
dims.setLastCol(lastcol);
dims.setLastRow(lastrow);
log.debug("Sheet.setDimensions exiting");
}
Per an earlier reported bug in working with Andy Khan's excel read library. This
sets the values in the sheet's DimensionsRecord object to be correct. Excel doesn't
really care, but we want to play nice with other libraries. |
public void setLoc(int loc) {
log.debug((new StringBuffer("sheet.setLoc(): ")).append(loc)
.toString());
this.loc = loc;
}
set the locator for where we should look for the next value record. The
algorythm will actually start here and find the correct location so you
can set this to 0 and watch performance go down the tubes but it will work.
After a value is set this is automatically advanced. Its also set by the
create method. So you probably shouldn't mess with this unless you have
a compelling reason why or the help for the method you're calling says so.
Check the other methods for whether they care about
the loc pointer. Many of the "modify" and "remove" methods re-initialize this
to "dimsloc" which is the location of the Dimensions Record and presumably the
start of the value section (at or around 19 dec). |
public void setPreOffset(int offset) {
this.preoffset = offset;
}
Set the preoffset when using DBCELL records (currently unused) - this is
the position of this sheet within the whole file. |