Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-659571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-675852,675854-676200,676202,676204,676206-676220,676222-676309,676311-676456,676458-676994,676996-677027,677030-677040,677042-677056,677058-677375,677377-677968,677970-677971,677973,677975-677994,677996-678286,678288-678538,678540-680393,680395-680469,680471-680529,680531-680852,680854-681529,681531-681571,681573-682224,682226,682228,682231-682281,682283-682335,682337-682507,682509,682512-682517,682519-682532,682534-682619,682622-682777,682779-682998,683000-683019,683021-683286 via svnmerge from

https://svn.apache.org/repos/asf/poi/trunk

........
  r683023 | josh | 2008-08-06 00:03:33 +0100 (Wed, 06 Aug 2008) | 1 line
  
  Fix JDK 1.4 compilation (after r682511 /bug 45538)
........
  r683081 | josh | 2008-08-06 02:39:44 +0100 (Wed, 06 Aug 2008) | 1 line
  
  refactoring aggregate records to a separate hierarchy. just starting
........
  r683093 | josh | 2008-08-06 04:06:18 +0100 (Wed, 06 Aug 2008) | 1 line
  
  should have been submitted with r683081
........
  r683096 | josh | 2008-08-06 04:23:10 +0100 (Wed, 06 Aug 2008) | 1 line
  
  should have been submitted with r683081
........
  r683128 | josh | 2008-08-06 07:20:59 +0100 (Wed, 06 Aug 2008) | 1 line
  
  removed TODO comment and formatted
........
  r683132 | josh | 2008-08-06 07:27:39 +0100 (Wed, 06 Aug 2008) | 1 line
  
  Partial fix for bug 45570 - Converted instance BitField fields to static 
........
  r683167 | josh | 2008-08-06 09:42:40 +0100 (Wed, 06 Aug 2008) | 1 line
  
  Added conditional format records to BiffViewer
........


git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@683670 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-08-07 18:21:32 +00:00
parent a41c6a8e77
commit fae41b50c1
57 changed files with 2701 additions and 2504 deletions

View File

@ -459,7 +459,8 @@ under the License.
fork="yes" srcdir="${scratchpad.src.test}"> fork="yes" srcdir="${scratchpad.src.test}">
<classpath> <classpath>
<path refid="scratchpad.classpath"/> <path refid="scratchpad.classpath"/>
<pathelement path="${scratchpad.output.dir}"/> <pathelement location="${main.output.test.dir}"/>
<pathelement location="${scratchpad.output.dir}"/>
<pathelement location="${junit.jar1.dir}"/> <pathelement location="${junit.jar1.dir}"/>
</classpath> </classpath>
</javac> </javac>
@ -694,6 +695,7 @@ under the License.
<classpath> <classpath>
<path refid="scratchpad.classpath"/> <path refid="scratchpad.classpath"/>
<pathelement location="${main.output.dir}"/> <pathelement location="${main.output.dir}"/>
<pathelement location="${main.output.test.dir}"/>
<pathelement location="${scratchpad.output.dir}"/> <pathelement location="${scratchpad.output.dir}"/>
<pathelement location="${scratchpad.output.test.dir}"/> <pathelement location="${scratchpad.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/> <pathelement location="${junit.jar1.dir}"/>

View File

@ -129,6 +129,8 @@ public final class BiffViewer {
case BoolErrRecord.sid: return new BoolErrRecord(in); case BoolErrRecord.sid: return new BoolErrRecord(in);
case BottomMarginRecord.sid: return new BottomMarginRecord(in); case BottomMarginRecord.sid: return new BottomMarginRecord(in);
case BoundSheetRecord.sid: return new BoundSheetRecord(in); case BoundSheetRecord.sid: return new BoundSheetRecord(in);
case CFHeaderRecord.sid: return new CFHeaderRecord(in);
case CFRuleRecord.sid: return new CFRuleRecord(in);
case CalcCountRecord.sid: return new CalcCountRecord(in); case CalcCountRecord.sid: return new CalcCountRecord(in);
case CalcModeRecord.sid: return new CalcModeRecord(in); case CalcModeRecord.sid: return new CalcModeRecord(in);
case CategorySeriesAxisRecord.sid: return new CategorySeriesAxisRecord(in); case CategorySeriesAxisRecord.sid: return new CategorySeriesAxisRecord(in);
@ -288,10 +290,10 @@ public final class BiffViewer {
} }
PrintStream ps; PrintStream ps;
if (false) { // set to true to output to file if (false) { // set to true to output to file
OutputStream os = new FileOutputStream(inFileName + ".out"); OutputStream os = new FileOutputStream(inFileName + ".out");
ps = new PrintStream(os); ps = new PrintStream(os);
} else { } else {
ps = System.out; ps = System.out;
} }
BiffViewer viewer = new BiffViewer(inputFile, ps); BiffViewer viewer = new BiffViewer(inputFile, ps);

View File

@ -0,0 +1,326 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.model;
import java.util.List;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.CalcCountRecord;
import org.apache.poi.hssf.record.CalcModeRecord;
import org.apache.poi.hssf.record.DateWindow1904Record;
import org.apache.poi.hssf.record.DefaultRowHeightRecord;
import org.apache.poi.hssf.record.DeltaRecord;
import org.apache.poi.hssf.record.DimensionsRecord;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.GridsetRecord;
import org.apache.poi.hssf.record.GutsRecord;
import org.apache.poi.hssf.record.HorizontalPageBreakRecord;
import org.apache.poi.hssf.record.HyperlinkRecord;
import org.apache.poi.hssf.record.IndexRecord;
import org.apache.poi.hssf.record.IterationRecord;
import org.apache.poi.hssf.record.PaneRecord;
import org.apache.poi.hssf.record.PrecisionRecord;
import org.apache.poi.hssf.record.PrintGridlinesRecord;
import org.apache.poi.hssf.record.PrintHeadersRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.RefModeRecord;
import org.apache.poi.hssf.record.SCLRecord;
import org.apache.poi.hssf.record.SaveRecalcRecord;
import org.apache.poi.hssf.record.SelectionRecord;
import org.apache.poi.hssf.record.UncalcedRecord;
import org.apache.poi.hssf.record.VerticalPageBreakRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
import org.apache.poi.hssf.record.aggregates.DataValidityTable;
import org.apache.poi.hssf.record.aggregates.MergedCellsTable;
/**
* Finds correct insert positions for records in workbook streams<p/>
*
* See OOO excelfileformat.pdf sec. 4.2.5 'Record Order in a BIFF8 Workbook Stream'
*
* @author Josh Micich
*/
final class RecordOrderer {
// TODO - add UninterpretedRecord as base class for many of these
// unimplemented sids
// TODO - simplify logic using a generalised record ordering
private RecordOrderer() {
// no instances of this class
}
/**
* Adds the specified new record in the correct place in sheet records list
*
*/
public static void addNewSheetRecord(List sheetRecords, RecordBase newRecord) {
int index = findSheetInsertPos(sheetRecords, newRecord.getClass());
sheetRecords.add(index, newRecord);
}
private static int findSheetInsertPos(List records, Class recClass) {
if (recClass == DataValidityTable.class) {
return findDataValidationTableInsertPos(records);
}
if (recClass == MergedCellsTable.class) {
return findInsertPosForNewMergedRecordTable(records);
}
if (recClass == ConditionalFormattingTable.class) {
return findInsertPosForNewCondFormatTable(records);
}
if (recClass == GutsRecord.class) {
return getGutsRecordInsertPos(records);
}
if (recClass == HorizontalPageBreakRecord.class) {
return getPageBreakRecordInsertPos(records, true);
}
if (recClass == VerticalPageBreakRecord.class) {
return getPageBreakRecordInsertPos(records, false);
}
throw new RuntimeException("Unexpected record class (" + recClass.getName() + ")");
}
private static int getPageBreakRecordInsertPos(List records, boolean isHorizonal) {
int dimensionsIndex = getDimensionsIndex(records);
int i = dimensionsIndex-1;
while (i > 0) {
i--;
Object rb = records.get(i);
if (isPageBreakPriorRecord(rb, isHorizonal)) {
return i+1;
}
}
throw new RuntimeException("Did not find insert point for GUTS");
}
private static boolean isPageBreakPriorRecord(Object rb, boolean newRecIsHorizontal) {
if (rb instanceof Record) {
Record record = (Record) rb;
switch (record.getSid()) {
case BOFRecord.sid:
case IndexRecord.sid:
// calc settings block
case UncalcedRecord.sid:
case CalcCountRecord.sid:
case CalcModeRecord.sid:
case PrecisionRecord.sid:
case RefModeRecord.sid:
case DeltaRecord.sid:
case IterationRecord.sid:
case DateWindow1904Record.sid:
case SaveRecalcRecord.sid:
// end calc settings
case PrintHeadersRecord.sid:
case PrintGridlinesRecord.sid:
case GridsetRecord.sid:
case DefaultRowHeightRecord.sid:
case 0x0081: // SHEETPR
return true;
}
switch (record.getSid()) {
// page settings block
case HorizontalPageBreakRecord.sid:
if (!newRecIsHorizontal) {
return true;
}
return false;
case VerticalPageBreakRecord.sid:
return false;
// next is case HeaderRecord.sid: case FooterRecord.sid:
// then more records in page settings block
}
}
return false;
}
/**
* Find correct position to add new CFHeader record
*/
private static int findInsertPosForNewCondFormatTable(List records) {
for (int i = records.size() - 2; i >= 0; i--) { // -2 to skip EOF record
Object rb = records.get(i);
if (rb instanceof MergedCellsTable) {
return i + 1;
}
Record rec = (Record) rb;
switch (rec.getSid()) {
case WindowTwoRecord.sid:
case SCLRecord.sid:
case PaneRecord.sid:
case SelectionRecord.sid:
case 0x0099:// STANDARDWIDTH
// MergedCellsTable usually here
case 0x015f:// LABELRANGES
case 0x00ef:// PHONETICPR
return i + 1;
}
}
throw new RuntimeException("Did not find Window2 record");
}
private static int findInsertPosForNewMergedRecordTable(List records) {
for (int i = records.size() - 2; i >= 0; i--) { // -2 to skip EOF record
Object rb = records.get(i);
Record rec = (Record) rb;
switch (rec.getSid()) {
case WindowTwoRecord.sid:
case SCLRecord.sid:
case PaneRecord.sid:
case SelectionRecord.sid:
case 0x0099:// STANDARDWIDTH
return i + 1;
}
}
throw new RuntimeException("Did not find Window2 record");
}
/**
* Finds the index where the sheet validations header record should be inserted
* @param records the records for this sheet
*
* + WINDOW2
* o SCL
* o PANE
* oo SELECTION
* o STANDARDWIDTH
* oo MERGEDCELLS
* o LABELRANGES
* o PHONETICPR
* o Conditional Formatting Table
* o Hyperlink Table
* o Data Validity Table
* o SHEETLAYOUT
* o SHEETPROTECTION
* o RANGEPROTECTION
* + EOF
*/
private static int findDataValidationTableInsertPos(List records) {
int i = records.size() - 1;
if (!(records.get(i) instanceof EOFRecord)) {
throw new IllegalStateException("Last sheet record should be EOFRecord");
}
while (i > 0) {
i--;
Object rb = records.get(i);
if (isDVTPriorRecord(rb)) {
Record nextRec = (Record) records.get(i + 1);
if (!isDVTSubsequentRecord(nextRec.getSid())) {
throw new IllegalStateException("Unexpected (" + nextRec.getClass().getName()
+ ") found after (" + rb.getClass().getName() + ")");
}
return i+1;
}
Record rec = (Record) rb;
if (!isDVTSubsequentRecord(rec.getSid())) {
throw new IllegalStateException("Unexpected (" + rec.getClass().getName()
+ ") while looking for DV Table insert pos");
}
}
return 0;
}
private static boolean isDVTPriorRecord(Object rb) {
if (rb instanceof MergedCellsTable || rb instanceof ConditionalFormattingTable) {
return true;
}
short sid = ((Record)rb).getSid();
switch(sid) {
case WindowTwoRecord.sid:
case 0x00A0: // SCL
case PaneRecord.sid:
case SelectionRecord.sid:
case 0x0099: // STANDARDWIDTH
// MergedCellsTable
case 0x015F: // LABELRANGES
case 0x00EF: // PHONETICPR
// ConditionalFormattingTable
case HyperlinkRecord.sid:
case 0x0800: // QUICKTIP
return true;
}
return false;
}
private static boolean isDVTSubsequentRecord(short sid) {
switch(sid) {
case 0x0862: // SHEETLAYOUT
case 0x0867: // SHEETPROTECTION
case 0x0868: // RANGEPROTECTION
case EOFRecord.sid:
return true;
}
return false;
}
/**
* DIMENSIONS record is always present
*/
private static int getDimensionsIndex(List records) {
int nRecs = records.size();
for(int i=0; i<nRecs; i++) {
if(records.get(i) instanceof DimensionsRecord) {
return i;
}
}
// worksheet stream is seriously broken
throw new RuntimeException("DimensionsRecord not found");
}
private static int getGutsRecordInsertPos(List records) {
int dimensionsIndex = getDimensionsIndex(records);
int i = dimensionsIndex-1;
while (i > 0) {
i--;
Object rb = records.get(i);
if (isGutsPriorRecord(rb)) {
return i+1;
}
}
throw new RuntimeException("Did not find insert point for GUTS");
}
private static boolean isGutsPriorRecord(Object rb) {
if (rb instanceof Record) {
Record record = (Record) rb;
switch (record.getSid()) {
case BOFRecord.sid:
case IndexRecord.sid:
// calc settings block
case UncalcedRecord.sid:
case CalcCountRecord.sid:
case CalcModeRecord.sid:
case PrecisionRecord.sid:
case RefModeRecord.sid:
case DeltaRecord.sid:
case IterationRecord.sid:
case DateWindow1904Record.sid:
case SaveRecalcRecord.sid:
// end calc settings
case PrintHeadersRecord.sid:
case PrintGridlinesRecord.sid:
case GridsetRecord.sid:
return true;
// DefaultRowHeightRecord.sid is next
}
}
return false;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The area format record is used to define the colours and patterns for an area. * The area format record is used to define the colours and patterns for an area.
@ -30,16 +29,16 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class AreaFormatRecord public final class AreaFormatRecord extends Record {
extends Record public final static short sid = 0x100A;
{
public final static short sid = 0x100a; private static final BitField automatic = BitFieldFactory.getInstance(0x1);
private static final BitField invert = BitFieldFactory.getInstance(0x2);
private int field_1_foregroundColor; private int field_1_foregroundColor;
private int field_2_backgroundColor; private int field_2_backgroundColor;
private short field_3_pattern; private short field_3_pattern;
private short field_4_formatFlags; private short field_4_formatFlags;
private BitField automatic = BitFieldFactory.getInstance(0x1);
private BitField invert = BitFieldFactory.getInstance(0x2);
private short field_5_forecolorIndex; private short field_5_forecolorIndex;
private short field_6_backcolorIndex; private short field_6_backcolorIndex;
@ -297,10 +296,4 @@ public class AreaFormatRecord
{ {
return invert.isSet(field_4_formatFlags); return invert.isSet(field_4_formatFlags);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The area record is used to define a area chart. * The area record is used to define a area chart.
@ -30,14 +29,12 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class AreaRecord public final class AreaRecord extends Record {
extends Record
{
public final static short sid = 0x101A; public final static short sid = 0x101A;
private short field_1_formatFlags; private short field_1_formatFlags;
private BitField stacked = BitFieldFactory.getInstance(0x1); private static final BitField stacked = BitFieldFactory.getInstance(0x1);
private BitField displayAsPercentage = BitFieldFactory.getInstance(0x2); private static final BitField displayAsPercentage = BitFieldFactory.getInstance(0x2);
private BitField shadow = BitFieldFactory.getInstance(0x4); private static final BitField shadow = BitFieldFactory.getInstance(0x4);
public AreaRecord() public AreaRecord()
@ -197,10 +194,4 @@ public class AreaRecord
{ {
return shadow.isSet(field_1_formatFlags); return shadow.isSet(field_1_formatFlags);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The axis options record provides unit information and other various tidbits about the axis. * The axis options record provides unit information and other various tidbits about the axis.
@ -30,27 +29,27 @@ import org.apache.poi.util.*;
* @author Andrew C. Oliver(acoliver at apache.org) * @author Andrew C. Oliver(acoliver at apache.org)
*/ */
public class AxisOptionsRecord public final class AxisOptionsRecord extends Record {
extends Record public final static short sid = 0x1062;
{
public final static short sid = 0x1062; private static final BitField defaultMinimum = BitFieldFactory.getInstance(0x01);
private short field_1_minimumCategory; private static final BitField defaultMaximum = BitFieldFactory.getInstance(0x02);
private short field_2_maximumCategory; private static final BitField defaultMajor = BitFieldFactory.getInstance(0x04);
private short field_3_majorUnitValue; private static final BitField defaultMinorUnit = BitFieldFactory.getInstance(0x08);
private short field_4_majorUnit; private static final BitField isDate = BitFieldFactory.getInstance(0x10);
private short field_5_minorUnitValue; private static final BitField defaultBase = BitFieldFactory.getInstance(0x20);
private short field_6_minorUnit; private static final BitField defaultCross = BitFieldFactory.getInstance(0x40);
private short field_7_baseUnit; private static final BitField defaultDateSettings = BitFieldFactory.getInstance(0x80);
private short field_8_crossingPoint;
private short field_9_options; private short field_1_minimumCategory;
private BitField defaultMinimum = BitFieldFactory.getInstance(0x1); private short field_2_maximumCategory;
private BitField defaultMaximum = BitFieldFactory.getInstance(0x2); private short field_3_majorUnitValue;
private BitField defaultMajor = BitFieldFactory.getInstance(0x4); private short field_4_majorUnit;
private BitField defaultMinorUnit = BitFieldFactory.getInstance(0x8); private short field_5_minorUnitValue;
private BitField isDate = BitFieldFactory.getInstance(0x10); private short field_6_minorUnit;
private BitField defaultBase = BitFieldFactory.getInstance(0x20); private short field_7_baseUnit;
private BitField defaultCross = BitFieldFactory.getInstance(0x40); private short field_8_crossingPoint;
private BitField defaultDateSettings = BitFieldFactory.getInstance(0x80); private short field_9_options;
public AxisOptionsRecord() public AxisOptionsRecord()
@ -488,10 +487,4 @@ public class AxisOptionsRecord
{ {
return defaultDateSettings.isSet(field_9_options); return defaultDateSettings.isSet(field_9_options);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The bar record is used to define a bar chart. * The bar record is used to define a bar chart.
@ -30,17 +29,17 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class BarRecord public final class BarRecord extends Record {
extends Record public final static short sid = 0x1017;
{
public final static short sid = 0x1017; private static final BitField horizontal = BitFieldFactory.getInstance(0x1);
private static final BitField stacked = BitFieldFactory.getInstance(0x2);
private static final BitField displayAsPercentage = BitFieldFactory.getInstance(0x4);
private static final BitField shadow = BitFieldFactory.getInstance(0x8);
private short field_1_barSpace; private short field_1_barSpace;
private short field_2_categorySpace; private short field_2_categorySpace;
private short field_3_formatFlags; private short field_3_formatFlags;
private BitField horizontal = BitFieldFactory.getInstance(0x1);
private BitField stacked = BitFieldFactory.getInstance(0x2);
private BitField displayAsPercentage = BitFieldFactory.getInstance(0x4);
private BitField shadow = BitFieldFactory.getInstance(0x8);
public BarRecord() public BarRecord()
@ -264,10 +263,4 @@ public class BarRecord
{ {
return shadow.isSet(field_3_formatFlags); return shadow.isSet(field_3_formatFlags);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,10 +14,10 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil; import org.apache.poi.util.StringUtil;
@ -33,12 +32,10 @@ import org.apache.poi.util.StringUtil;
* @author Sergei Kozello (sergeikozello at mail.ru) * @author Sergei Kozello (sergeikozello at mail.ru)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class BoundSheetRecord extends Record {
public final static short sid = 0x0085;
public class BoundSheetRecord private static final BitField hiddenFlag = BitFieldFactory.getInstance(0x01);
extends Record
{
private static final short HIDDEN_FLAG_MASK = 0x01;
public final static short sid = 0x85;
private int field_1_position_of_BOF; private int field_1_position_of_BOF;
private short field_2_option_flags; private short field_2_option_flags;
private byte field_3_sheetname_length; private byte field_3_sheetname_length;
@ -305,10 +302,10 @@ public class BoundSheetRecord
} }
public boolean isHidden() { public boolean isHidden() {
return BitFieldFactory.getInstance(HIDDEN_FLAG_MASK).isSet(field_2_option_flags); return hiddenFlag.isSet(field_2_option_flags);
} }
public void setHidden(boolean hidden) { public void setHidden(boolean hidden) {
field_2_option_flags = BitFieldFactory.getInstance(HIDDEN_FLAG_MASK).setShortBoolean(field_2_option_flags, hidden); field_2_option_flags = hiddenFlag.setShortBoolean(field_2_option_flags, hidden);
} }
} }

View File

@ -31,8 +31,7 @@ import org.apache.poi.util.LittleEndian;
* Conditional Formatting Rule Record. * Conditional Formatting Rule Record.
* @author Dmitriy Kumshayev * @author Dmitriy Kumshayev
*/ */
public final class CFRuleRecord extends Record public final class CFRuleRecord extends Record {
{
public static final short sid = 0x01B1; public static final short sid = 0x01B1;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* This record refers to a category or series axis and is used to specify label/tickmark frequency. * This record refers to a category or series axis and is used to specify label/tickmark frequency.
@ -30,17 +29,17 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class CategorySeriesAxisRecord public final class CategorySeriesAxisRecord extends Record {
extends Record public final static short sid = 0x1020;
{
public final static short sid = 0x1020; private static final BitField valueAxisCrossing = BitFieldFactory.getInstance(0x1);
private static final BitField crossesFarRight = BitFieldFactory.getInstance(0x2);
private static final BitField reversed = BitFieldFactory.getInstance(0x4);
private short field_1_crossingPoint; private short field_1_crossingPoint;
private short field_2_labelFrequency; private short field_2_labelFrequency;
private short field_3_tickMarkFrequency; private short field_3_tickMarkFrequency;
private short field_4_options; private short field_4_options;
private BitField valueAxisCrossing = BitFieldFactory.getInstance(0x1);
private BitField crossesFarRight = BitFieldFactory.getInstance(0x2);
private BitField reversed = BitFieldFactory.getInstance(0x4);
public CategorySeriesAxisRecord() public CategorySeriesAxisRecord()
@ -268,10 +267,4 @@ public class CategorySeriesAxisRecord
{ {
return reversed.isSet(field_4_options); return reversed.isSet(field_4_options);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,12 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
/** /**
* Class ChartFormatRecord * Class ChartFormatRecord
@ -30,19 +28,17 @@ import org.apache.poi.util.BitFieldFactory;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
* @version %I%, %G% * @version %I%, %G%
*/ */
public final class ChartFormatRecord extends Record {
public class ChartFormatRecord
extends Record
{
public static final short sid = 0x1014; public static final short sid = 0x1014;
private static final BitField varyDisplayPattern = BitFieldFactory.getInstance(0x01);
// ignored? // ignored?
private int field1_x_position; // lower left private int field1_x_position; // lower left
private int field2_y_position; // lower left private int field2_y_position; // lower left
private int field3_width; private int field3_width;
private int field4_height; private int field4_height;
private short field5_grbit; private short field5_grbit;
private BitField varyDisplayPattern = BitFieldFactory.getInstance(0x01);
public ChartFormatRecord() public ChartFormatRecord()
{ {

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,63 +14,64 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The common object data record is used to store all common preferences for an excel object. * The common object data record is used to store all common preferences for an excel object.
* NOTE: This source is automatically generated please do not modify this file. Either subclass or * NOTE: This source is automatically generated please do not modify this file. Either subclass or
* remove the record in src/records/definitions. * remove the record in src/records/definitions.
*
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class CommonObjectDataSubRecord public final class CommonObjectDataSubRecord extends SubRecord {
extends SubRecord public final static short sid = 0x0015;
{
public final static short sid = 0x15; private static final BitField locked = BitFieldFactory.getInstance(0x0001);
private static final BitField printable = BitFieldFactory.getInstance(0x0010);
private static final BitField autofill = BitFieldFactory.getInstance(0x2000);
private static final BitField autoline = BitFieldFactory.getInstance(0x4000);
public final static short OBJECT_TYPE_GROUP = 0;
public final static short OBJECT_TYPE_LINE = 1;
public final static short OBJECT_TYPE_RECTANGLE = 2;
public final static short OBJECT_TYPE_OVAL = 3;
public final static short OBJECT_TYPE_ARC = 4;
public final static short OBJECT_TYPE_CHART = 5;
public final static short OBJECT_TYPE_TEXT = 6;
public final static short OBJECT_TYPE_BUTTON = 7;
public final static short OBJECT_TYPE_PICTURE = 8;
public final static short OBJECT_TYPE_POLYGON = 9;
public final static short OBJECT_TYPE_RESERVED1 = 10;
public final static short OBJECT_TYPE_CHECKBOX = 11;
public final static short OBJECT_TYPE_OPTION_BUTTON = 12;
public final static short OBJECT_TYPE_EDIT_BOX = 13;
public final static short OBJECT_TYPE_LABEL = 14;
public final static short OBJECT_TYPE_DIALOG_BOX = 15;
public final static short OBJECT_TYPE_SPINNER = 16;
public final static short OBJECT_TYPE_SCROLL_BAR = 17;
public final static short OBJECT_TYPE_LIST_BOX = 18;
public final static short OBJECT_TYPE_GROUP_BOX = 19;
public final static short OBJECT_TYPE_COMBO_BOX = 20;
public final static short OBJECT_TYPE_RESERVED2 = 21;
public final static short OBJECT_TYPE_RESERVED3 = 22;
public final static short OBJECT_TYPE_RESERVED4 = 23;
public final static short OBJECT_TYPE_RESERVED5 = 24;
public final static short OBJECT_TYPE_COMMENT = 25;
public final static short OBJECT_TYPE_RESERVED6 = 26;
public final static short OBJECT_TYPE_RESERVED7 = 27;
public final static short OBJECT_TYPE_RESERVED8 = 28;
public final static short OBJECT_TYPE_RESERVED9 = 29;
public final static short OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
private short field_1_objectType; private short field_1_objectType;
public final static short OBJECT_TYPE_GROUP = 0;
public final static short OBJECT_TYPE_LINE = 1;
public final static short OBJECT_TYPE_RECTANGLE = 2;
public final static short OBJECT_TYPE_OVAL = 3;
public final static short OBJECT_TYPE_ARC = 4;
public final static short OBJECT_TYPE_CHART = 5;
public final static short OBJECT_TYPE_TEXT = 6;
public final static short OBJECT_TYPE_BUTTON = 7;
public final static short OBJECT_TYPE_PICTURE = 8;
public final static short OBJECT_TYPE_POLYGON = 9;
public final static short OBJECT_TYPE_RESERVED1 = 10;
public final static short OBJECT_TYPE_CHECKBOX = 11;
public final static short OBJECT_TYPE_OPTION_BUTTON = 12;
public final static short OBJECT_TYPE_EDIT_BOX = 13;
public final static short OBJECT_TYPE_LABEL = 14;
public final static short OBJECT_TYPE_DIALOG_BOX = 15;
public final static short OBJECT_TYPE_SPINNER = 16;
public final static short OBJECT_TYPE_SCROLL_BAR = 17;
public final static short OBJECT_TYPE_LIST_BOX = 18;
public final static short OBJECT_TYPE_GROUP_BOX = 19;
public final static short OBJECT_TYPE_COMBO_BOX = 20;
public final static short OBJECT_TYPE_RESERVED2 = 21;
public final static short OBJECT_TYPE_RESERVED3 = 22;
public final static short OBJECT_TYPE_RESERVED4 = 23;
public final static short OBJECT_TYPE_RESERVED5 = 24;
public final static short OBJECT_TYPE_COMMENT = 25;
public final static short OBJECT_TYPE_RESERVED6 = 26;
public final static short OBJECT_TYPE_RESERVED7 = 27;
public final static short OBJECT_TYPE_RESERVED8 = 28;
public final static short OBJECT_TYPE_RESERVED9 = 29;
public final static short OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING = 30;
private short field_2_objectId; private short field_2_objectId;
private short field_3_option; private short field_3_option;
private BitField locked = BitFieldFactory.getInstance(0x1);
private BitField printable = BitFieldFactory.getInstance(0x10);
private BitField autofill = BitFieldFactory.getInstance(0x2000);
private BitField autoline = BitFieldFactory.getInstance(0x4000);
private int field_4_reserved1; private int field_4_reserved1;
private int field_5_reserved2; private int field_5_reserved2;
private int field_6_reserved3; private int field_6_reserved3;
@ -431,8 +431,4 @@ public class CommonObjectDataSubRecord
{ {
return autoline.isSet(field_3_option); return autoline.isSet(field_3_option);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The dat record is used to store options for the chart. * The dat record is used to store options for the chart.
@ -30,15 +29,15 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class DatRecord public final class DatRecord extends Record {
extends Record public final static short sid = 0x1063;
{
public final static short sid = 0x1063; private static final BitField horizontalBorder = BitFieldFactory.getInstance(0x1);
private static final BitField verticalBorder = BitFieldFactory.getInstance(0x2);
private static final BitField border = BitFieldFactory.getInstance(0x4);
private static final BitField showSeriesKey = BitFieldFactory.getInstance(0x8);
private short field_1_options; private short field_1_options;
private BitField horizontalBorder = BitFieldFactory.getInstance(0x1);
private BitField verticalBorder = BitFieldFactory.getInstance(0x2);
private BitField border = BitFieldFactory.getInstance(0x4);
private BitField showSeriesKey = BitFieldFactory.getInstance(0x8);
public DatRecord() public DatRecord()
@ -216,10 +215,4 @@ public class DatRecord
{ {
return showSeriesKey.isSet(field_1_options); return showSeriesKey.isSet(field_1_options);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,30 +14,30 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The data format record is used to index into a series. * The data format record is used to index into a series.
* NOTE: This source is automatically generated please do not modify this file. Either subclass or * NOTE: This source is automatically generated please do not modify this file. Either subclass or
* remove the record in src/records/definitions. * remove the record in src/records/definitions.
*
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class DataFormatRecord public final class DataFormatRecord extends Record {
extends Record public final static short sid = 0x1006;
{
public final static short sid = 0x1006; private static final BitField useExcel4Colors = BitFieldFactory.getInstance(0x1);
private short field_1_pointNumber;
private short field_2_seriesIndex; private short field_1_pointNumber;
private short field_3_seriesNumber; private short field_2_seriesIndex;
private short field_4_formatFlags; private short field_3_seriesNumber;
private BitField useExcel4Colors = BitFieldFactory.getInstance(0x1); private short field_4_formatFlags;
public DataFormatRecord() public DataFormatRecord()
@ -228,10 +227,4 @@ public class DataFormatRecord
{ {
return useExcel4Colors.isSet(field_4_formatFlags); return useExcel4Colors.isSet(field_4_formatFlags);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,7 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* FormulaRecord.java
*
* Created on October 28, 2001, 5:44 PM
*/
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.util.List; import java.util.List;
@ -39,24 +32,22 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class FormulaRecord public final class FormulaRecord
extends Record extends Record
implements CellValueRecordInterface, Comparable implements CellValueRecordInterface, Comparable
{ {
public static final short sid = public static final short sid = 0x0006; // docs say 406...because of a bug Microsoft support site article #Q184647)
0x06; // docs say 406...because of a bug Microsoft support site article #Q184647)
private static final BitField alwaysCalc = BitFieldFactory.getInstance(0x0001);
//private short field_1_row; private static final BitField calcOnLoad = BitFieldFactory.getInstance(0x0002);
private static final BitField sharedFormula = BitFieldFactory.getInstance(0x0008);
private int field_1_row; private int field_1_row;
private short field_2_column; private short field_2_column;
private short field_3_xf; private short field_3_xf;
private double field_4_value; private double field_4_value;
private short field_5_options; private short field_5_options;
private BitField alwaysCalc = BitFieldFactory.getInstance(0x0001);
private BitField calcOnLoad = BitFieldFactory.getInstance(0x0002);
private BitField sharedFormula = BitFieldFactory.getInstance(0x0008);
private int field_6_zero; private int field_6_zero;
private short field_7_expression_len; private short field_7_expression_len;
private Stack field_8_parsed_expr; private Stack field_8_parsed_expr;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The frame record indicates whether there is a border around the displayed text of a chart. * The frame record indicates whether there is a border around the displayed text of a chart.
@ -30,16 +29,16 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class FrameRecord public final class FrameRecord extends Record {
extends Record public final static short sid = 0x1032;
{
public final static short sid = 0x1032; private static final BitField autoSize = BitFieldFactory.getInstance(0x1);
private static final BitField autoPosition = BitFieldFactory.getInstance(0x2);
private short field_1_borderType; private short field_1_borderType;
public final static short BORDER_TYPE_REGULAR = 0; public final static short BORDER_TYPE_REGULAR = 0;
public final static short BORDER_TYPE_SHADOW = 1; public final static short BORDER_TYPE_SHADOW = 1;
private short field_2_options; private short field_2_options;
private BitField autoSize = BitFieldFactory.getInstance(0x1);
private BitField autoPosition = BitFieldFactory.getInstance(0x2);
public FrameRecord() public FrameRecord()
@ -211,10 +210,4 @@ public class FrameRecord
{ {
return autoPosition.isSet(field_2_options); return autoPosition.isSet(field_2_options);
} }
}
} // END OF CLASS

View File

@ -1,60 +1,67 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0 The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
/** import java.util.Iterator;
* HorizontalPageBreak record that stores page breaks at rows
* <p> /**
* This class is just used so that SID compares work properly in the RecordFactory * HorizontalPageBreak (0x001B) record that stores page breaks at rows <p/>
* @see PageBreakRecord *
* @author Danny Mui (dmui at apache dot org) * @see PageBreakRecord
*/ * @author Danny Mui (dmui at apache dot org)
public class HorizontalPageBreakRecord extends PageBreakRecord { */
public final class HorizontalPageBreakRecord extends PageBreakRecord {
public static final short sid = 0x001B;
public static final short sid = PageBreakRecord.HORIZONTAL_SID;
/** /**
* * Creates an empty horizontal page break record
*/ */
public HorizontalPageBreakRecord() { public HorizontalPageBreakRecord() {
super(); //
} }
/** /**
* @param sid * @param in
*/ * the RecordInputstream to read the record from
public HorizontalPageBreakRecord(short sid) {
super(sid);
}
/**
* @param in the RecordInputstream to read the record from
*/ */
public HorizontalPageBreakRecord(RecordInputStream in) { public HorizontalPageBreakRecord(RecordInputStream in) {
super(in); super(in);
} }
/* (non-Javadoc) protected void validateSid(short id) {
* @see org.apache.poi.hssf.record.Record#getSid() if (id != getSid()) {
*/ throw new RecordFormatException(
"NOT A HorizontalPageBreak or VerticalPageBreak RECORD!! " + id);
}
}
public short getSid() { public short getSid() {
return sid; return sid;
} }
public Object clone() {
PageBreakRecord result = new HorizontalPageBreakRecord();
Iterator iterator = getBreaksIterator();
while (iterator.hasNext()) {
Break original = (Break) iterator.next();
result.addBreak(original.main, original.subFrom, original.subTo);
}
return result;
}
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* Defines a legend for a chart. * Defines a legend for a chart.
@ -30,10 +29,16 @@ import org.apache.poi.util.*;
* @author Andrew C. Oliver (acoliver at apache.org) * @author Andrew C. Oliver (acoliver at apache.org)
*/ */
public class LegendRecord public final class LegendRecord extends Record {
extends Record public final static short sid = 0x1015;
{
public final static short sid = 0x1015; private static final BitField autoPosition = BitFieldFactory.getInstance(0x01);
private static final BitField autoSeries = BitFieldFactory.getInstance(0x02);
private static final BitField autoXPositioning = BitFieldFactory.getInstance(0x04);
private static final BitField autoYPositioning = BitFieldFactory.getInstance(0x08);
private static final BitField vertical = BitFieldFactory.getInstance(0x10);
private static final BitField dataTable = BitFieldFactory.getInstance(0x20);
private int field_1_xAxisUpperLeft; private int field_1_xAxisUpperLeft;
private int field_2_yAxisUpperLeft; private int field_2_yAxisUpperLeft;
private int field_3_xSize; private int field_3_xSize;
@ -50,12 +55,6 @@ public class LegendRecord
public final static byte SPACING_MEDIUM = 1; public final static byte SPACING_MEDIUM = 1;
public final static byte SPACING_OPEN = 2; public final static byte SPACING_OPEN = 2;
private short field_7_options; private short field_7_options;
private BitField autoPosition = BitFieldFactory.getInstance(0x1);
private BitField autoSeries = BitFieldFactory.getInstance(0x2);
private BitField autoXPositioning = BitFieldFactory.getInstance(0x4);
private BitField autoYPositioning = BitFieldFactory.getInstance(0x8);
private BitField vertical = BitFieldFactory.getInstance(0x10);
private BitField dataTable = BitFieldFactory.getInstance(0x20);
public LegendRecord() public LegendRecord()
@ -437,10 +436,4 @@ public class LegendRecord
{ {
return dataTable.isSet(field_7_options); return dataTable.isSet(field_7_options);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* Describes a line format record. The line format record controls how a line on a chart appears. * Describes a line format record. The line format record controls how a line on a chart appears.
@ -30,10 +29,13 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class LineFormatRecord public final class LineFormatRecord extends Record {
extends Record public final static short sid = 0x1007;
{
public final static short sid = 0x1007; private static final BitField auto = BitFieldFactory.getInstance(0x1);
private static final BitField drawTicks = BitFieldFactory.getInstance(0x4);
private static final BitField unknown = BitFieldFactory.getInstance(0x4);
private int field_1_lineColor; private int field_1_lineColor;
private short field_2_linePattern; private short field_2_linePattern;
public final static short LINE_PATTERN_SOLID = 0; public final static short LINE_PATTERN_SOLID = 0;
@ -51,9 +53,6 @@ public class LineFormatRecord
public final static short WEIGHT_MEDIUM = 1; public final static short WEIGHT_MEDIUM = 1;
public final static short WEIGHT_WIDE = 2; public final static short WEIGHT_WIDE = 2;
private short field_4_format; private short field_4_format;
private BitField auto = BitFieldFactory.getInstance(0x1);
private BitField drawTicks = BitFieldFactory.getInstance(0x4);
private BitField unknown = BitFieldFactory.getInstance(0x4);
private short field_5_colourPaletteIndex; private short field_5_colourPaletteIndex;
@ -342,10 +341,4 @@ public class LineFormatRecord
{ {
return unknown.isSet(field_4_format); return unknown.isSet(field_4_format);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* Describes a linked data record. This record referes to the series data or text. * Describes a linked data record. This record referes to the series data or text.
@ -30,10 +29,11 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class LinkedDataRecord public final class LinkedDataRecord extends Record {
extends Record public final static short sid = 0x1051;
{
public final static short sid = 0x1051; private static final BitField customNumberFormat= BitFieldFactory.getInstance(0x1);
private byte field_1_linkType; private byte field_1_linkType;
public final static byte LINK_TYPE_TITLE_OR_TEXT = 0; public final static byte LINK_TYPE_TITLE_OR_TEXT = 0;
public final static byte LINK_TYPE_VALUES = 1; public final static byte LINK_TYPE_VALUES = 1;
@ -45,7 +45,6 @@ public class LinkedDataRecord
public final static byte REFERENCE_TYPE_NOT_USED = 3; public final static byte REFERENCE_TYPE_NOT_USED = 3;
public final static byte REFERENCE_TYPE_ERROR_REPORTED = 4; public final static byte REFERENCE_TYPE_ERROR_REPORTED = 4;
private short field_3_options; private short field_3_options;
private BitField customNumberFormat = BitFieldFactory.getInstance(0x1);
private short field_4_indexNumberFmtRecord; private short field_4_indexNumberFmtRecord;
private LinkedDataFormulaField field_5_formulaOfLink; private LinkedDataFormulaField field_5_formulaOfLink;
@ -86,7 +85,7 @@ public class LinkedDataRecord
field_2_referenceType = in.readByte(); field_2_referenceType = in.readByte();
field_3_options = in.readShort(); field_3_options = in.readShort();
field_4_indexNumberFmtRecord = in.readShort(); field_4_indexNumberFmtRecord = in.readShort();
field_5_formulaOfLink = new org.apache.poi.hssf.record.LinkedDataFormulaField(); field_5_formulaOfLink = new LinkedDataFormulaField();
field_5_formulaOfLink.fillField(in); field_5_formulaOfLink.fillField(in);
} }
@ -156,7 +155,7 @@ public class LinkedDataRecord
rec.field_2_referenceType = field_2_referenceType; rec.field_2_referenceType = field_2_referenceType;
rec.field_3_options = field_3_options; rec.field_3_options = field_3_options;
rec.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord; rec.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord;
rec.field_5_formulaOfLink = ((org.apache.poi.hssf.record.LinkedDataFormulaField)field_5_formulaOfLink.clone());; rec.field_5_formulaOfLink = ((LinkedDataFormulaField)field_5_formulaOfLink.clone());;
return rec; return rec;
} }
@ -286,10 +285,4 @@ public class LinkedDataRecord
{ {
return customNumberFormat.isSet(field_3_options); return customNumberFormat.isSet(field_3_options);
} }
}
} // END OF CLASS

View File

@ -32,68 +32,51 @@ import org.apache.poi.util.LittleEndian;
*/ */
public final class MergeCellsRecord extends Record { public final class MergeCellsRecord extends Record {
public final static short sid = 0x00E5; public final static short sid = 0x00E5;
private CellRangeAddressList _regions; /** sometimes the regions array is shared with other MergedCellsRecords */
private CellRangeAddress[] _regions;
private final int _startIndex;
private final int _numberOfRegions;
/** public MergeCellsRecord(CellRangeAddress[] regions, int startIndex, int numberOfRegions) {
* Creates an empty <tt>MergedCellsRecord</tt> _regions = regions;
*/ _startIndex = startIndex;
public MergeCellsRecord() { _numberOfRegions = numberOfRegions;
_regions = new CellRangeAddressList();
} }
/** /**
* Constructs a MergedCellsRecord and sets its fields appropriately * Constructs a MergedCellsRecord and sets its fields appropriately
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public MergeCellsRecord(RecordInputStream in) { public MergeCellsRecord(RecordInputStream in) {
super(in); int nRegions = in.readUShort();
CellRangeAddress[] cras = new CellRangeAddress[nRegions];
for (int i = 0; i < nRegions; i++) {
cras[i] = new org.apache.poi.hssf.util.CellRangeAddress(in);
}
_numberOfRegions = nRegions;
_startIndex = 0;
_regions = cras;
} }
protected void fillFields(RecordInputStream in) { protected void fillFields(RecordInputStream in) {
_regions = new org.apache.poi.hssf.util.CellRangeAddressList(in); throw new RuntimeException("obsolete");
} }
/** /**
* get the number of merged areas. If this drops down to 0 you should just go * get the number of merged areas. If this drops down to 0 you should just go
* ahead and delete the record. * ahead and delete the record.
* @return number of areas * @return number of areas
*/ */
public short getNumAreas() { public short getNumAreas() {
return (short)_regions.countRanges(); return (short)_numberOfRegions;
}
/**
* Add an area to consider a merged cell. The index returned is only gauranteed to
* be correct provided you do not add ahead of or remove ahead of it (in which case
* you should increment or decrement appropriately....in other words its an arrayList)
*
* @param firstRow - the upper left hand corner's row
* @param firstCol - the upper left hand corner's col
* @param lastRow - the lower right hand corner's row
* @param lastCol - the lower right hand corner's col
* @return new index of said area (don't depend on it if you add/remove)
*/
public void addArea(int firstRow, int firstCol, int lastRow, int lastCol) {
_regions.addCellRangeAddress(firstRow, firstCol, lastRow, lastCol);
}
/**
* essentially unmerge the cells in the "area" stored at the passed in index
* @param areaIndex
*/
public void removeAreaAt(int areaIndex) {
_regions.remove(areaIndex);
} }
/** /**
* @return MergedRegion at the given index representing the area that is Merged (r1,c1 - r2,c2) * @return MergedRegion at the given index representing the area that is Merged (r1,c1 - r2,c2)
*/ */
public CellRangeAddress getAreaAt(int index) { public CellRangeAddress getAreaAt(int index) {
return _regions.getCellRangeAddress(index); return _regions[_startIndex + index];
} }
public int getRecordSize() { public int getRecordSize() {
return 4 + _regions.getSize(); return 4 + CellRangeAddressList.getEncodedSize(_numberOfRegions);
} }
public short getSid() { public short getSid() {
@ -101,11 +84,16 @@ public final class MergeCellsRecord extends Record {
} }
public int serialize(int offset, byte [] data) { public int serialize(int offset, byte [] data) {
int dataSize = _regions.getSize(); int dataSize = CellRangeAddressList.getEncodedSize(_numberOfRegions);
LittleEndian.putShort(data, offset + 0, sid); LittleEndian.putUShort(data, offset + 0, sid);
LittleEndian.putUShort(data, offset + 2, dataSize); LittleEndian.putUShort(data, offset + 2, dataSize);
_regions.serialize(offset + 4, data); int nItems = _numberOfRegions;
LittleEndian.putUShort(data, offset + 4, nItems);
int pos = 6;
for (int i = 0; i < _numberOfRegions; i++) {
pos += _regions[_startIndex + i].serialize(offset+pos, data);
}
return 4 + dataSize; return 4 + dataSize;
} }
@ -113,17 +101,16 @@ public final class MergeCellsRecord extends Record {
StringBuffer retval = new StringBuffer(); StringBuffer retval = new StringBuffer();
retval.append("[MERGEDCELLS]").append("\n"); retval.append("[MERGEDCELLS]").append("\n");
retval.append(" .sid =").append(sid).append("\n");
retval.append(" .numregions =").append(getNumAreas()) retval.append(" .numregions =").append(getNumAreas())
.append("\n"); .append("\n");
for (int k = 0; k < _regions.countRanges(); k++) { for (int k = 0; k < _numberOfRegions; k++) {
CellRangeAddress region = _regions.getCellRangeAddress(k); CellRangeAddress region = _regions[_startIndex + k];
retval.append(" .rowfrom =").append(region.getFirstRow()) retval.append(" .rowfrom =").append(region.getFirstRow())
.append("\n"); .append("\n");
retval.append(" .colfrom =").append(region.getFirstColumn())
.append("\n");
retval.append(" .rowto =").append(region.getLastRow()) retval.append(" .rowto =").append(region.getLastRow())
.append("\n");
retval.append(" .colfrom =").append(region.getFirstColumn())
.append("\n"); .append("\n");
retval.append(" .colto =").append(region.getLastColumn()) retval.append(" .colto =").append(region.getLastColumn())
.append("\n"); .append("\n");
@ -140,13 +127,11 @@ public final class MergeCellsRecord extends Record {
} }
public Object clone() { public Object clone() {
MergeCellsRecord rec = new MergeCellsRecord(); int nRegions = _numberOfRegions;
for (int k = 0; k < _regions.countRanges(); k++) { CellRangeAddress[] clonedRegions = new CellRangeAddress[nRegions];
CellRangeAddress oldRegion = _regions.getCellRangeAddress(k); for (int i = 0; i < clonedRegions.length; i++) {
rec.addArea(oldRegion.getFirstRow(), oldRegion.getFirstColumn(), clonedRegions[i] = _regions[_startIndex + i].copy();
oldRegion.getLastRow(), oldRegion.getLastColumn()); }
} return new MergeCellsRecord(clonedRegions, 0, nRegions);
return rec;
} }
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,11 +14,10 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -29,140 +27,128 @@ import org.apache.poi.util.LittleEndian;
/** /**
* <p>Record that contains the functionality page breaks (horizontal and vertical)</p> * <p>Record that contains the functionality page breaks (horizontal and vertical)</p>
* *
* <p>The other two classes just specifically set the SIDS for record creation.</p> * <p>The other two classes just specifically set the SIDS for record creation.</p>
* *
* <p>REFERENCE: Microsoft Excel SDK page 322 and 420</p> * <p>REFERENCE: Microsoft Excel SDK page 322 and 420</p>
* *
* @see HorizontalPageBreakRecord * @see HorizontalPageBreakRecord
* @see VerticalPageBreakRecord * @see VerticalPageBreakRecord
* @author Danny Mui (dmui at apache dot org) * @author Danny Mui (dmui at apache dot org)
*/ */
public class PageBreakRecord extends Record { public abstract class PageBreakRecord extends Record {
public static final short HORIZONTAL_SID = (short)0x1B; private static final boolean IS_EMPTY_RECORD_WRITTEN = false;
public static final short VERTICAL_SID = (short)0x1A; private static final int[] EMPTY_INT_ARRAY = { };
public short sid;
private short numBreaks; private List _breaks;
private List breaks; private Map _breakMap;
private Map BreakMap;
/** /**
* Since both records store 2byte integers (short), no point in * Since both records store 2byte integers (short), no point in
* differentiating it in the records. * differentiating it in the records.
* <p> * <p>
* The subs (rows or columns, don't seem to be able to set but excel sets * The subs (rows or columns, don't seem to be able to set but excel sets
* them automatically) * them automatically)
*/ */
public class Break public class Break {
{
public short main; public static final int ENCODED_SIZE = 6;
public short subFrom; public int main;
public short subTo; public int subFrom;
public int subTo;
public Break(short main, short subFrom, short subTo) public Break(int main, int subFrom, int subTo)
{ {
this.main = main; this.main = main;
this.subFrom = subFrom; this.subFrom = subFrom;
this.subTo = subTo; this.subTo = subTo;
} }
public Break(RecordInputStream in) {
main = in.readUShort() - 1;
subFrom = in.readUShort();
subTo = in.readUShort();
}
public int serialize(int offset, byte[] data) {
LittleEndian.putUShort(data, offset + 0, main + 1);
LittleEndian.putUShort(data, offset + 2, subFrom);
LittleEndian.putUShort(data, offset + 4, subTo);
return ENCODED_SIZE;
}
} }
public PageBreakRecord() protected PageBreakRecord() {
{ _breaks = new ArrayList();
_breakMap = new HashMap();
} }
/** protected PageBreakRecord(RecordInputStream in) {
*
* @param sid
*/
public PageBreakRecord(short sid) {
super();
this.sid = sid;
}
public PageBreakRecord(RecordInputStream in)
{
super(in); super(in);
this.sid = in.getSid();
} }
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
short loadedBreaks = in.readShort(); int nBreaks = in.readShort();
setNumBreaks(loadedBreaks); _breaks = new ArrayList(nBreaks + 2);
for(int k = 0; k < loadedBreaks; k++) _breakMap = new HashMap();
{
addBreak((short)(in.readShort()-1), in.readShort(), in.readShort()); for(int k = 0; k < nBreaks; k++) {
Break br = new Break(in);
_breaks.add(br);
_breakMap.put(new Integer(br.main), br);
} }
} }
public short getSid() private int getDataSize() {
{ return 2 + _breaks.size() * Break.ENCODED_SIZE;
return sid; }
public int getRecordSize() {
int nBreaks = _breaks.size();
if (!IS_EMPTY_RECORD_WRITTEN && nBreaks < 1) {
return 0;
}
return 4 + getDataSize();
} }
public int serialize(int offset, byte data[])
{ public final int serialize(int offset, byte data[]) {
int recordsize = getRecordSize(); int nBreaks = _breaks.size();
if (!IS_EMPTY_RECORD_WRITTEN && nBreaks < 1) {
return 0;
}
int dataSize = getDataSize();
LittleEndian.putUShort(data, offset + 0, getSid());
LittleEndian.putUShort(data, offset + 2, dataSize);
LittleEndian.putUShort(data, offset + 4, nBreaks);
int pos = 6; int pos = 6;
LittleEndian.putShort(data, offset + 0, getSid()); for (int i=0; i<nBreaks; i++) {
LittleEndian.putShort(data, offset + 2, (short)(recordsize - 4)); Break br = (Break)_breaks.get(i);
LittleEndian.putShort(data, offset + 4, getNumBreaks()); pos += br.serialize(offset+pos, data);
for(Iterator iterator = getBreaksIterator(); iterator.hasNext();)
{
Break Break = (Break)iterator.next();
LittleEndian.putShort(data, offset + pos, (short)(Break.main + 1));
pos += 2;
LittleEndian.putShort(data, offset + pos, Break.subFrom);
pos += 2;
LittleEndian.putShort(data, offset + pos, Break.subTo);
pos += 2;
} }
return recordsize; return 4 + dataSize;
} }
protected void validateSid(short id) public int getNumBreaks() {
{ return _breaks.size();
if(id != HORIZONTAL_SID && id != VERTICAL_SID)
throw new RecordFormatException("NOT A HorizontalPageBreak or VerticalPageBreak RECORD!! " + id);
else
return;
} }
public short getNumBreaks() public final Iterator getBreaksIterator() {
{ return _breaks.iterator();
return breaks != null ? (short)breaks.size() : numBreaks;
}
public void setNumBreaks(short numBreaks)
{
this.numBreaks = numBreaks;
}
public Iterator getBreaksIterator()
{
if(breaks == null)
return Collections.EMPTY_LIST.iterator();
else
return breaks.iterator();
} }
public String toString() public String toString()
{ {
StringBuffer retval = new StringBuffer(); StringBuffer retval = new StringBuffer();
if (getSid() != HORIZONTAL_SID && getSid()!= VERTICAL_SID)
return "[INVALIDPAGEBREAK]\n .sid ="+getSid()+"[INVALIDPAGEBREAK]";
String label; String label;
String mainLabel; String mainLabel;
String subLabel; String subLabel;
if (getSid() == HORIZONTAL_SID) { if (getSid() == HorizontalPageBreakRecord.sid) {
label = "HORIZONTALPAGEBREAK"; label = "HORIZONTALPAGEBREAK";
mainLabel = "row"; mainLabel = "row";
subLabel = "col"; subLabel = "col";
@ -171,7 +157,7 @@ public class PageBreakRecord extends Record {
mainLabel = "column"; mainLabel = "column";
subLabel = "row"; subLabel = "row";
} }
retval.append("["+label+"]").append("\n"); retval.append("["+label+"]").append("\n");
retval.append(" .sid =").append(getSid()).append("\n"); retval.append(" .sid =").append(getSid()).append("\n");
retval.append(" .numbreaks =").append(getNumBreaks()).append("\n"); retval.append(" .numbreaks =").append(getNumBreaks()).append("\n");
@ -179,7 +165,7 @@ public class PageBreakRecord extends Record {
for(int k = 0; k < getNumBreaks(); k++) for(int k = 0; k < getNumBreaks(); k++)
{ {
Break region = (Break)iterator.next(); Break region = (Break)iterator.next();
retval.append(" .").append(mainLabel).append(" (zero-based) =").append(region.main).append("\n"); retval.append(" .").append(mainLabel).append(" (zero-based) =").append(region.main).append("\n");
retval.append(" .").append(subLabel).append("From =").append(region.subFrom).append("\n"); retval.append(" .").append(subLabel).append("From =").append(region.subFrom).append("\n");
retval.append(" .").append(subLabel).append("To =").append(region.subTo).append("\n"); retval.append(" .").append(subLabel).append("To =").append(region.subTo).append("\n");
@ -192,46 +178,33 @@ public class PageBreakRecord extends Record {
/** /**
* Adds the page break at the specified parameters * Adds the page break at the specified parameters
* @param main Depending on sid, will determine row or column to put page break (zero-based) * @param main Depending on sid, will determine row or column to put page break (zero-based)
* @param subFrom No user-interface to set (defaults to minumum, 0) * @param subFrom No user-interface to set (defaults to minimum, 0)
* @param subTo No user-interface to set * @param subTo No user-interface to set
*/ */
public void addBreak(short main, short subFrom, short subTo) public void addBreak(int main, int subFrom, int subTo) {
{
if(breaks == null)
{
breaks = new ArrayList(getNumBreaks() + 10);
BreakMap = new HashMap();
}
Integer key = new Integer(main); Integer key = new Integer(main);
Break region = (Break)BreakMap.get(key); Break region = (Break)_breakMap.get(key);
if(region != null) if(region == null) {
{ region = new Break(main, subFrom, subTo);
_breakMap.put(key, region);
_breaks.add(region);
} else {
region.main = main; region.main = main;
region.subFrom = subFrom; region.subFrom = subFrom;
region.subTo = subTo; region.subTo = subTo;
} else
{
region = new Break(main, subFrom, subTo);
breaks.add(region);
} }
BreakMap.put(key, region);
} }
/** /**
* Removes the break indicated by the parameter * Removes the break indicated by the parameter
* @param main (zero-based) * @param main (zero-based)
*/ */
public void removeBreak(short main) public final void removeBreak(int main) {
{
Integer rowKey = new Integer(main); Integer rowKey = new Integer(main);
Break region = (Break)BreakMap.get(rowKey); Break region = (Break)_breakMap.get(rowKey);
breaks.remove(region); _breaks.remove(region);
BreakMap.remove(rowKey); _breakMap.remove(rowKey);
}
public int getRecordSize()
{
return 6 + getNumBreaks() * 6;
} }
/** /**
@ -239,26 +212,21 @@ public class PageBreakRecord extends Record {
* @param main FIXME: Document this! * @param main FIXME: Document this!
* @return The Break or null if no break exists at the row/col specified. * @return The Break or null if no break exists at the row/col specified.
*/ */
public Break getBreak(short main) public final Break getBreak(int main) {
{
if (BreakMap == null)
return null;
Integer rowKey = new Integer(main); Integer rowKey = new Integer(main);
return (Break)BreakMap.get(rowKey); return (Break)_breakMap.get(rowKey);
} }
/* Clones the page break record public final int[] getBreaks() {
* @see java.lang.Object#clone() int count = getNumBreaks();
*/ if (count < 1) {
public Object clone() { return EMPTY_INT_ARRAY;
PageBreakRecord record = new PageBreakRecord(getSid()); }
Iterator iterator = getBreaksIterator(); int[] result = new int[count];
while (iterator.hasNext()) { for (int i=0; i<count; i++) {
Break original = (Break)iterator.next(); Break breakItem = (Break)_breaks.get(i);
record.addBreak(original.main, original.subFrom, original.subTo); result[i] = breakItem.main;
} }
return record; return result;
} }
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
@ -32,15 +30,13 @@ import java.io.ByteArrayInputStream;
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public abstract class Record extends RecordBase {
public abstract class Record
{
/** /**
* instantiates a blank record strictly for ID matching * instantiates a blank record strictly for ID matching
*/ */
public Record() protected Record()
{ {
} }
@ -49,7 +45,7 @@ public abstract class Record
* *
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public Record(RecordInputStream in) protected Record(RecordInputStream in)
{ {
validateSid(in.getSid()); validateSid(in.getSid());
fillFields(in); fillFields(in);
@ -89,17 +85,6 @@ public abstract class Record
return retval; return retval;
} }
/**
* called by the class that is responsible for writing this sucker.
* Subclasses should implement this so that their data is passed back in a
* byte array.
*
* @param offset to begin writing at
* @param data byte array containing instance data
* @return number of bytes written
*/
public abstract int serialize(int offset, byte [] data);
/** /**
* gives the current serialized size of the record. Should include the sid and reclength (4 bytes). * gives the current serialized size of the record. Should include the sid and reclength (4 bytes).

View File

@ -0,0 +1,42 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record;
/**
* Common base class of {@link Record} and {@link RecordAggregate}
*
* @author Josh Micich
*/
public abstract class RecordBase {
/**
* called by the class that is responsible for writing this sucker.
* Subclasses should implement this so that their data is passed back in a
* byte array.
*
* @param offset to begin writing at
* @param data byte array containing instance data
* @return number of bytes written
*/
public abstract int serialize(int offset, byte[] data);
/**
* gives the current serialized size of the record. Should include the sid
* and reclength (4 bytes).
*/
public abstract int getRecordSize();
}

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The series label record defines the type of label associated with the data format record. * The series label record defines the type of label associated with the data format record.
@ -30,18 +29,17 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class SeriesLabelsRecord public final class SeriesLabelsRecord extends Record {
extends Record public final static short sid = 0x100c;
{
public final static short sid = 0x100c;
private short field_1_formatFlags;
private BitField showActual = BitFieldFactory.getInstance(0x1);
private BitField showPercent = BitFieldFactory.getInstance(0x2);
private BitField labelAsPercentage = BitFieldFactory.getInstance(0x4);
private BitField smoothedLine = BitFieldFactory.getInstance(0x8);
private BitField showLabel = BitFieldFactory.getInstance(0x10);
private BitField showBubbleSizes = BitFieldFactory.getInstance(0x20);
private static final BitField showActual = BitFieldFactory.getInstance(0x01);
private static final BitField showPercent = BitFieldFactory.getInstance(0x02);
private static final BitField labelAsPercentage = BitFieldFactory.getInstance(0x04);
private static final BitField smoothedLine = BitFieldFactory.getInstance(0x08);
private static final BitField showLabel = BitFieldFactory.getInstance(0x10);
private static final BitField showBubbleSizes = BitFieldFactory.getInstance(0x20);
private short field_1_formatFlags;
public SeriesLabelsRecord() public SeriesLabelsRecord()
{ {
@ -256,10 +254,4 @@ public class SeriesLabelsRecord
{ {
return showBubbleSizes.isSet(field_1_formatFlags); return showBubbleSizes.isSet(field_1_formatFlags);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* Describes a chart sheet properties record. * Describes a chart sheet properties record.
@ -30,16 +29,16 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class SheetPropertiesRecord public final class SheetPropertiesRecord extends Record {
extends Record public final static short sid = 0x1044;
{
public final static short sid = 0x1044; private static final BitField chartTypeManuallyFormatted = BitFieldFactory.getInstance(0x01);
private static final BitField plotVisibleOnly = BitFieldFactory.getInstance(0x02);
private static final BitField doNotSizeWithWindow = BitFieldFactory.getInstance(0x04);
private static final BitField defaultPlotDimensions = BitFieldFactory.getInstance(0x08);
private static final BitField autoPlotArea = BitFieldFactory.getInstance(0x10);
private short field_1_flags; private short field_1_flags;
private BitField chartTypeManuallyFormatted = BitFieldFactory.getInstance(0x1);
private BitField plotVisibleOnly = BitFieldFactory.getInstance(0x2);
private BitField doNotSizeWithWindow = BitFieldFactory.getInstance(0x4);
private BitField defaultPlotDimensions = BitFieldFactory.getInstance(0x8);
private BitField autoPlotArea = BitFieldFactory.getInstance(0x10);
private byte field_2_empty; private byte field_2_empty;
public final static byte EMPTY_NOT_PLOTTED = 0; public final static byte EMPTY_NOT_PLOTTED = 0;
public final static byte EMPTY_ZERO = 1; public final static byte EMPTY_ZERO = 1;
@ -274,10 +273,4 @@ public class SheetPropertiesRecord
{ {
return autoPlotArea.isSet(field_1_flags); return autoPlotArea.isSet(field_1_flags);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,14 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
/** /**
* Title: Style Record<P> * Title: Style Record<P>
@ -32,11 +30,11 @@ import org.apache.poi.util.BitFieldFactory;
* @author aviks : string fixes for UserDefined Style * @author aviks : string fixes for UserDefined Style
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class StyleRecord extends Record {
public final static short sid = 0x0293;
private static final BitField fHighByte = BitFieldFactory.getInstance(0x01);
public class StyleRecord
extends Record
{
public final static short sid = 0x293;
public final static short STYLE_USER_DEFINED = 0; public final static short STYLE_USER_DEFINED = 0;
public final static short STYLE_BUILT_IN = 1; public final static short STYLE_BUILT_IN = 1;
@ -50,7 +48,6 @@ public class StyleRecord
// only for user defined styles // only for user defined styles
private short field_2_name_length; //OO doc says 16 bit length, so we believe private short field_2_name_length; //OO doc says 16 bit length, so we believe
private byte field_3_string_options; private byte field_3_string_options;
private BitField fHighByte;
private String field_4_name; private String field_4_name;
public StyleRecord() public StyleRecord()
@ -77,8 +74,6 @@ public class StyleRecord
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
fHighByte = BitFieldFactory.getInstance(0x01); //have to init here, since we are being called
//from super, and class level init hasnt been done.
field_1_xf_index = in.readShort(); field_1_xf_index = in.readShort();
if (getType() == STYLE_BUILT_IN) if (getType() == STYLE_BUILT_IN)
{ {

View File

@ -14,8 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record;
import org.apache.poi.hssf.record.formula.TblPtg;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
/** /**
* TableRecord - The record specifies a data table. * TableRecord - The record specifies a data table.
* This record is preceded by a single Formula record that * This record is preceded by a single Formula record that
@ -24,15 +29,18 @@
* *
* See p536 of the June 08 binary docs * See p536 of the June 08 binary docs
*/ */
package org.apache.poi.hssf.record; public final class TableRecord extends Record {
import org.apache.poi.hssf.record.formula.TblPtg;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian;
public class TableRecord extends Record {
public static final short sid = 566; public static final short sid = 566;
private static final BitField alwaysCalc = BitFieldFactory.getInstance(0x0001);
private static final BitField reserved1 = BitFieldFactory.getInstance(0x0002);
private static final BitField rowOrColInpCell = BitFieldFactory.getInstance(0x0004);
private static final BitField oneOrTwoVar = BitFieldFactory.getInstance(0x0008);
private static final BitField rowDeleted = BitFieldFactory.getInstance(0x0010);
private static final BitField colDeleted = BitFieldFactory.getInstance(0x0020);
private static final BitField reserved2 = BitFieldFactory.getInstance(0x0040);
private static final BitField reserved3 = BitFieldFactory.getInstance(0x0080);
private short field_1_ref_rowFirst; private short field_1_ref_rowFirst;
private short field_2_ref_rowLast; private short field_2_ref_rowLast;
private short field_3_ref_colFirst; private short field_3_ref_colFirst;
@ -45,14 +53,6 @@ public class TableRecord extends Record {
private short field_9_rowInputCol; private short field_9_rowInputCol;
private short field_10_colInputCol; private short field_10_colInputCol;
private BitField alwaysCalc = BitFieldFactory.getInstance(0x0001);
private BitField reserved1 = BitFieldFactory.getInstance(0x0002);
private BitField rowOrColInpCell = BitFieldFactory.getInstance(0x0004);
private BitField oneOrTwoVar = BitFieldFactory.getInstance(0x0008);
private BitField rowDeleted = BitFieldFactory.getInstance(0x0010);
private BitField colDeleted = BitFieldFactory.getInstance(0x0020);
private BitField reserved2 = BitFieldFactory.getInstance(0x0040);
private BitField reserved3 = BitFieldFactory.getInstance(0x0080);
protected void fillFields(RecordInputStream in) { protected void fillFields(RecordInputStream in) {
field_1_ref_rowFirst = in.readShort(); field_1_ref_rowFirst = in.readShort();

View File

@ -32,25 +32,25 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class TextObjectBaseRecord public class TextObjectBaseRecord extends Record {
extends Record
{
public final static short sid = 0x1B6; public final static short sid = 0x1B6;
private static final BitField reserved1 = BitFieldFactory.getInstance(0x0001);
private static final BitField HorizontalTextAlignment = BitFieldFactory.getInstance(0x000E);
private static final BitField VerticalTextAlignment = BitFieldFactory.getInstance(0x0070);
private static final BitField reserved2 = BitFieldFactory.getInstance(0x0180);
private static final BitField textLocked = BitFieldFactory.getInstance(0x0200);
private static final BitField reserved3 = BitFieldFactory.getInstance(0xFC00);
private short field_1_options; private short field_1_options;
private BitField reserved1 = BitFieldFactory.getInstance(0x1);
private BitField HorizontalTextAlignment = BitFieldFactory.getInstance(0x000E);
public final static short HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED = 1; public final static short HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED = 1;
public final static short HORIZONTAL_TEXT_ALIGNMENT_CENTERED = 2; public final static short HORIZONTAL_TEXT_ALIGNMENT_CENTERED = 2;
public final static short HORIZONTAL_TEXT_ALIGNMENT_RIGHT_ALIGNED = 3; public final static short HORIZONTAL_TEXT_ALIGNMENT_RIGHT_ALIGNED = 3;
public final static short HORIZONTAL_TEXT_ALIGNMENT_JUSTIFIED = 4; public final static short HORIZONTAL_TEXT_ALIGNMENT_JUSTIFIED = 4;
private BitField VerticalTextAlignment = BitFieldFactory.getInstance(0x0070);
public final static short VERTICAL_TEXT_ALIGNMENT_TOP = 1; public final static short VERTICAL_TEXT_ALIGNMENT_TOP = 1;
public final static short VERTICAL_TEXT_ALIGNMENT_CENTER = 2; public final static short VERTICAL_TEXT_ALIGNMENT_CENTER = 2;
public final static short VERTICAL_TEXT_ALIGNMENT_BOTTOM = 3; public final static short VERTICAL_TEXT_ALIGNMENT_BOTTOM = 3;
public final static short VERTICAL_TEXT_ALIGNMENT_JUSTIFY = 4; public final static short VERTICAL_TEXT_ALIGNMENT_JUSTIFY = 4;
private BitField reserved2 = BitFieldFactory.getInstance(0x0180);
private BitField textLocked = BitFieldFactory.getInstance(0x200);
private BitField reserved3 = BitFieldFactory.getInstance(0xFC00);
private short field_2_textOrientation; private short field_2_textOrientation;
public final static short TEXT_ORIENTATION_NONE = 0; public final static short TEXT_ORIENTATION_NONE = 0;
public final static short TEXT_ORIENTATION_TOP_TO_BOTTOM = 1; public final static short TEXT_ORIENTATION_TOP_TO_BOTTOM = 1;
@ -452,10 +452,4 @@ public class TextObjectBaseRecord
{ {
return reserved3.getShortValue(field_1_options); return reserved3.getShortValue(field_1_options);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The text record is used to define text stored on a chart. * The text record is used to define text stored on a chart.
@ -30,10 +29,26 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class TextRecord public final class TextRecord extends Record {
extends Record
{
public final static short sid = 0x1025; public final static short sid = 0x1025;
private static final BitField dataLabelPlacement = BitFieldFactory.getInstance(0x000F);
private static final BitField autoColor = BitFieldFactory.getInstance(0x0001);
private static final BitField showKey = BitFieldFactory.getInstance(0x0002);
private static final BitField showValue = BitFieldFactory.getInstance(0x0004);
private static final BitField vertical = BitFieldFactory.getInstance(0x0008);
private static final BitField autoGeneratedText = BitFieldFactory.getInstance(0x0010);
private static final BitField generated = BitFieldFactory.getInstance(0x0020);
private static final BitField autoLabelDeleted = BitFieldFactory.getInstance(0x0040);
private static final BitField autoBackground = BitFieldFactory.getInstance(0x0080);
private static final BitField rotation = BitFieldFactory.getInstance(0x0700);
private static final BitField showCategoryLabelAsPercentage = BitFieldFactory.getInstance(0x0800);
private static final BitField showValueAsPercentage = BitFieldFactory.getInstance(0x1000);
private static final BitField showBubbleSizes = BitFieldFactory.getInstance(0x2000);
private static final BitField showLabel = BitFieldFactory.getInstance(0x4000);
private byte field_1_horizontalAlignment; private byte field_1_horizontalAlignment;
public final static byte HORIZONTAL_ALIGNMENT_LEFT = 1; public final static byte HORIZONTAL_ALIGNMENT_LEFT = 1;
public final static byte HORIZONTAL_ALIGNMENT_CENTER = 2; public final static byte HORIZONTAL_ALIGNMENT_CENTER = 2;
@ -53,26 +68,12 @@ public class TextRecord
private int field_7_width; private int field_7_width;
private int field_8_height; private int field_8_height;
private short field_9_options1; private short field_9_options1;
private BitField autoColor = BitFieldFactory.getInstance(0x1);
private BitField showKey = BitFieldFactory.getInstance(0x2);
private BitField showValue = BitFieldFactory.getInstance(0x4);
private BitField vertical = BitFieldFactory.getInstance(0x8);
private BitField autoGeneratedText = BitFieldFactory.getInstance(0x10);
private BitField generated = BitFieldFactory.getInstance(0x20);
private BitField autoLabelDeleted = BitFieldFactory.getInstance(0x40);
private BitField autoBackground = BitFieldFactory.getInstance(0x80);
private BitField rotation = BitFieldFactory.getInstance(0x0700);
public final static short ROTATION_NONE = 0; public final static short ROTATION_NONE = 0;
public final static short ROTATION_TOP_TO_BOTTOM = 1; public final static short ROTATION_TOP_TO_BOTTOM = 1;
public final static short ROTATION_ROTATED_90_DEGREES = 2; public final static short ROTATION_ROTATED_90_DEGREES = 2;
public final static short ROTATION_ROTATED_90_DEGREES_CLOCKWISE = 3; public final static short ROTATION_ROTATED_90_DEGREES_CLOCKWISE = 3;
private BitField showCategoryLabelAsPercentage = BitFieldFactory.getInstance(0x800);
private BitField showValueAsPercentage = BitFieldFactory.getInstance(0x1000);
private BitField showBubbleSizes = BitFieldFactory.getInstance(0x2000);
private BitField showLabel = BitFieldFactory.getInstance(0x4000);
private short field_10_indexOfColorValue; private short field_10_indexOfColorValue;
private short field_11_options2; private short field_11_options2;
private BitField dataLabelPlacement = BitFieldFactory.getInstance(0x000F);
public final static short DATA_LABEL_PLACEMENT_CHART_DEPENDENT = 0; public final static short DATA_LABEL_PLACEMENT_CHART_DEPENDENT = 0;
public final static short DATA_LABEL_PLACEMENT_OUTSIDE = 1; public final static short DATA_LABEL_PLACEMENT_OUTSIDE = 1;
public final static short DATA_LABEL_PLACEMENT_INSIDE = 2; public final static short DATA_LABEL_PLACEMENT_INSIDE = 2;
@ -740,10 +741,4 @@ public class TextRecord
{ {
return dataLabelPlacement.getShortValue(field_11_options2); return dataLabelPlacement.getShortValue(field_11_options2);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The Tick record defines how tick marks and label positioning/formatting * The Tick record defines how tick marks and label positioning/formatting
@ -30,10 +29,14 @@ import org.apache.poi.util.*;
* @author Andrew C. Oliver(acoliver at apache.org) * @author Andrew C. Oliver(acoliver at apache.org)
*/ */
public class TickRecord public final class TickRecord extends Record {
extends Record public final static short sid = 0x101E;
{
public final static short sid = 0x101e; private static final BitField autoTextColor = BitFieldFactory.getInstance(0x1);
private static final BitField autoTextBackground = BitFieldFactory.getInstance(0x2);
private static final BitField rotation = BitFieldFactory.getInstance(0x1c);
private static final BitField autorotate = BitFieldFactory.getInstance(0x20);
private byte field_1_majorTickType; private byte field_1_majorTickType;
private byte field_2_minorTickType; private byte field_2_minorTickType;
private byte field_3_labelPosition; private byte field_3_labelPosition;
@ -44,10 +47,6 @@ public class TickRecord
private int field_8_zero3; private int field_8_zero3;
private int field_9_zero4; private int field_9_zero4;
private short field_10_options; private short field_10_options;
private BitField autoTextColor = BitFieldFactory.getInstance(0x1);
private BitField autoTextBackground = BitFieldFactory.getInstance(0x2);
private BitField rotation = BitFieldFactory.getInstance(0x1c);
private BitField autorotate = BitFieldFactory.getInstance(0x20);
private short field_11_tickColor; private short field_11_tickColor;
private short field_12_zero5; private short field_12_zero5;
@ -442,10 +441,4 @@ public class TickRecord
{ {
return autorotate.isSet(field_10_options); return autorotate.isSet(field_10_options);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,13 +14,13 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.*; import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian;
/** /**
* The value range record defines the range of the value axis. * The value range record defines the range of the value axis.
@ -30,25 +29,25 @@ import org.apache.poi.util.*;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class ValueRangeRecord public final class ValueRangeRecord extends Record {
extends Record public final static short sid = 0x101f;
{
public final static short sid = 0x101f; private static final BitField automaticMinimum = BitFieldFactory.getInstance(0x0001);
private static final BitField automaticMaximum = BitFieldFactory.getInstance(0x0002);
private static final BitField automaticMajor = BitFieldFactory.getInstance(0x0004);
private static final BitField automaticMinor = BitFieldFactory.getInstance(0x0008);
private static final BitField automaticCategoryCrossing = BitFieldFactory.getInstance(0x0010);
private static final BitField logarithmicScale = BitFieldFactory.getInstance(0x0020);
private static final BitField valuesInReverse = BitFieldFactory.getInstance(0x0040);
private static final BitField crossCategoryAxisAtMaximum = BitFieldFactory.getInstance(0x0080);
private static final BitField reserved = BitFieldFactory.getInstance(0x0100);
private double field_1_minimumAxisValue; private double field_1_minimumAxisValue;
private double field_2_maximumAxisValue; private double field_2_maximumAxisValue;
private double field_3_majorIncrement; private double field_3_majorIncrement;
private double field_4_minorIncrement; private double field_4_minorIncrement;
private double field_5_categoryAxisCross; private double field_5_categoryAxisCross;
private short field_6_options; private short field_6_options;
private BitField automaticMinimum = BitFieldFactory.getInstance(0x1);
private BitField automaticMaximum = BitFieldFactory.getInstance(0x2);
private BitField automaticMajor = BitFieldFactory.getInstance(0x4);
private BitField automaticMinor = BitFieldFactory.getInstance(0x8);
private BitField automaticCategoryCrossing = BitFieldFactory.getInstance(0x10);
private BitField logarithmicScale = BitFieldFactory.getInstance(0x20);
private BitField valuesInReverse = BitFieldFactory.getInstance(0x40);
private BitField crossCategoryAxisAtMaximum = BitFieldFactory.getInstance(0x80);
private BitField reserved = BitFieldFactory.getInstance(0x100);
public ValueRangeRecord() public ValueRangeRecord()
@ -432,10 +431,4 @@ public class ValueRangeRecord
{ {
return reserved.isSet(field_6_options); return reserved.isSet(field_6_options);
} }
}
} // END OF CLASS

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,46 +14,53 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import java.util.Iterator;
/** /**
* VerticalPageBreak record that stores page breaks at columns * VerticalPageBreak (0x001A) record that stores page breaks at columns<p/>
* <p> *
* This class is just used so that SID compares work properly in the RecordFactory
* @see PageBreakRecord * @see PageBreakRecord
* @author Danny Mui (dmui at apache dot org) * @author Danny Mui (dmui at apache dot org)
*/ */
public class VerticalPageBreakRecord extends PageBreakRecord { public final class VerticalPageBreakRecord extends PageBreakRecord {
public static final short sid = PageBreakRecord.VERTICAL_SID; public static final short sid = 0x001A;
/** /**
* * Creates an empty vertical page break record
*/ */
public VerticalPageBreakRecord() { public VerticalPageBreakRecord() {
super();
} }
/** /**
* @param sid * @param in the RecordInputstream to read the record from
*/
public VerticalPageBreakRecord(short sid) {
super(sid);
}
/**
* @param in the RecordInputstream to read the record from
*/ */
public VerticalPageBreakRecord(RecordInputStream in) { public VerticalPageBreakRecord(RecordInputStream in) {
super(in); super(in);
} }
/* (non-Javadoc) protected void validateSid(short id) {
* @see org.apache.poi.hssf.record.Record#getSid() if (id != getSid()) {
*/ throw new RecordFormatException(
"NOT A HorizontalPageBreak or VerticalPageBreak RECORD!! " + id);
}
}
public short getSid() { public short getSid() {
return sid; return sid;
} }
public Object clone() {
PageBreakRecord result = new VerticalPageBreakRecord();
Iterator iterator = getBreaksIterator();
while (iterator.hasNext()) {
Break original = (Break) iterator.next();
result.addBreak(original.main, original.subFrom, original.subTo);
}
return result;
}
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -15,7 +14,6 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
@ -31,34 +29,27 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class WindowTwoRecord extends Record {
public class WindowTwoRecord public final static short sid = 0x023E;
extends Record
{
public final static short sid = 0x23e;
private short field_1_options;
// bitfields // bitfields
private BitField displayFormulas = BitFieldFactory.getInstance(0x01); private static final BitField displayFormulas = BitFieldFactory.getInstance(0x01);
private BitField displayGridlines = BitFieldFactory.getInstance(0x02); private static final BitField displayGridlines = BitFieldFactory.getInstance(0x02);
private BitField displayRowColHeadings = BitFieldFactory.getInstance(0x04); private static final BitField displayRowColHeadings = BitFieldFactory.getInstance(0x04);
private BitField freezePanes = BitFieldFactory.getInstance(0x08); private static final BitField freezePanes = BitFieldFactory.getInstance(0x08);
private BitField displayZeros = BitFieldFactory.getInstance(0x10); private static final BitField displayZeros = BitFieldFactory.getInstance(0x10);
private BitField defaultHeader = /** if false use color in field 4 if true use default foreground for headers */
BitFieldFactory.getInstance(0x20); // if false use color in field 4 private static final BitField defaultHeader = BitFieldFactory.getInstance(0x20);
private static final BitField arabic = BitFieldFactory.getInstance(0x040);
// if true use default foreground private static final BitField displayGuts = BitFieldFactory.getInstance(0x080);
// for headers private static final BitField freezePanesNoSplit = BitFieldFactory.getInstance(0x100);
private BitField arabic = private static final BitField selected = BitFieldFactory.getInstance(0x200);
BitFieldFactory.getInstance(0x40); // for our desert dwelling friends private static final BitField active = BitFieldFactory.getInstance(0x400);
private BitField displayGuts = BitFieldFactory.getInstance(0x80); private static final BitField savedInPageBreakPreview = BitFieldFactory.getInstance(0x800);
private BitField freezePanesNoSplit = BitFieldFactory.getInstance(0x100);
private BitField selected = BitFieldFactory.getInstance(0x200);
private BitField active = BitFieldFactory.getInstance(0x400);
private BitField savedInPageBreakPreview = BitFieldFactory.getInstance(0x800);
// 4-7 reserved // 4-7 reserved
// end bitfields // end bitfields
private short field_1_options;
private short field_2_top_row; private short field_2_top_row;
private short field_3_left_col; private short field_3_left_col;
private int field_4_header_color; private int field_4_header_color;

View File

@ -14,20 +14,20 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record.aggregates; package org.apache.poi.hssf.record.aggregates;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.CFHeaderRecord; import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.CFRuleRecord; import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.ss.util.Region; import org.apache.poi.ss.util.Region;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/** /**
* CFRecordsAggregate - aggregates Conditional Formatting records CFHeaderRecord * CFRecordsAggregate - aggregates Conditional Formatting records CFHeaderRecord
@ -37,15 +37,12 @@ import org.apache.poi.util.POILogger;
* @author Dmitriy Kumshayev * @author Dmitriy Kumshayev
* *
*/ */
public final class CFRecordsAggregate extends Record public final class CFRecordsAggregate extends Record {
{
/** Excel allows up to 3 conditional formating rules */ /** Excel allows up to 3 conditional formating rules */
private static final int MAX_CONDTIONAL_FORMAT_RULES = 3; private static final int MAX_CONDTIONAL_FORMAT_RULES = 3;
public final static short sid = -2008; // not a real BIFF record public final static short sid = -2008; // not a real BIFF record
private static POILogger log = POILogFactory.getLogger(CFRecordsAggregate.class);
private final CFHeaderRecord header; private final CFHeaderRecord header;
/** List of CFRuleRecord objects */ /** List of CFRuleRecord objects */
@ -79,9 +76,8 @@ public final class CFRecordsAggregate extends Record
* @param offset - position of {@link CFHeaderRecord} object in the list of Record objects * @param offset - position of {@link CFHeaderRecord} object in the list of Record objects
* @return CFRecordsAggregate object * @return CFRecordsAggregate object
*/ */
public static CFRecordsAggregate createCFAggregate(List recs, int pOffset) public static CFRecordsAggregate createCFAggregate(RecordStream rs) {
{ Record rec = rs.getNext();
Record rec = ( Record ) recs.get(pOffset);
if (rec.getSid() != CFHeaderRecord.sid) { if (rec.getSid() != CFHeaderRecord.sid) {
throw new IllegalStateException("next record sid was " + rec.getSid() throw new IllegalStateException("next record sid was " + rec.getSid()
+ " instead of " + CFHeaderRecord.sid + " as expected"); + " instead of " + CFHeaderRecord.sid + " as expected");
@ -91,35 +87,10 @@ public final class CFRecordsAggregate extends Record
int nRules = header.getNumberOfConditionalFormats(); int nRules = header.getNumberOfConditionalFormats();
CFRuleRecord[] rules = new CFRuleRecord[nRules]; CFRuleRecord[] rules = new CFRuleRecord[nRules];
int offset = pOffset; for (int i = 0; i < rules.length; i++) {
int countFound = 0; rules[i] = (CFRuleRecord) rs.getNext();
while (countFound < rules.length) {
offset++;
if(offset>=recs.size()) {
break;
}
rec = (Record)recs.get(offset);
if(rec instanceof CFRuleRecord) {
rules[countFound] = (CFRuleRecord) rec;
countFound++;
} else {
break;
}
}
if (countFound < nRules)
{ // TODO -(MAR-2008) can this ever happen? write junit
if (log.check(POILogger.DEBUG))
{
log.log(POILogger.DEBUG, "Expected " + nRules + " Conditional Formats, "
+ "but found " + countFound + " rules");
}
header.setNumberOfConditionalFormats(nRules);
CFRuleRecord[] lessRules = new CFRuleRecord[countFound];
System.arraycopy(rules, 0, lessRules, 0, countFound);
rules = lessRules;
} }
return new CFRecordsAggregate(header, rules); return new CFRecordsAggregate(header, rules);
} }

View File

@ -1,72 +1,52 @@
/* /* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and See the License for the specific language governing permissions and
* limitations under the License. limitations under the License.
*/ ==================================================================== */
package org.apache.poi.hssf.record.aggregates; package org.apache.poi.hssf.record.aggregates;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.ColumnInfoRecord; import org.apache.poi.hssf.record.ColumnInfoRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/** /**
* @author Glen Stampoultzis * @author Glen Stampoultzis
* @version $Id$ * @version $Id$
*/ */
public class ColumnInfoRecordsAggregate public final class ColumnInfoRecordsAggregate extends RecordAggregate {
extends Record private final List records;
{
// int size = 0;
List records = null;
public ColumnInfoRecordsAggregate() /**
{ * Creates an empty aggregate
records = new ArrayList(); */
} public ColumnInfoRecordsAggregate() {
records = new ArrayList();
/** You never fill an aggregate */ }
protected void fillFields(RecordInputStream in) public ColumnInfoRecordsAggregate(RecordStream rs) {
{ this();
}
while(rs.peekNextClass() == ColumnInfoRecord.class) {
/** Not required by an aggregate */ records.add(rs.getNext());
protected void validateSid(short id) }
{ if (records.size() < 1) {
} throw new RuntimeException("No column info records found");
}
/** It's an aggregate... just made something up */ }
public short getSid()
{
return -1012;
}
public int getRecordSize()
{
int size = 0;
for ( Iterator iterator = records.iterator(); iterator.hasNext(); )
size += ( (ColumnInfoRecord) iterator.next() ).getRecordSize();
return size;
}
public Iterator getIterator()
{
return records.iterator();
}
/** /**
* Performs a deep clone of the record * Performs a deep clone of the record
@ -105,25 +85,14 @@ public class ColumnInfoRecordsAggregate
return records.size(); return records.size();
} }
/** public void visitContainedRecords(RecordVisitor rv) {
* called by the class that is responsible for writing this sucker. int nItems = records.size();
* Subclasses should implement this so that their data is passed back in a if (nItems < 1) {
* byte array. return;
* }
* @param offset offset to begin writing at for(int i=0; i<nItems; i++) {
* @param data byte array containing instance data rv.visitRecord((Record)records.get(i));
* @return number of bytes written }
*/
public int serialize(int offset, byte [] data)
{
Iterator itr = records.iterator();
int pos = offset;
while (itr.hasNext())
{
pos += (( Record ) itr.next()).serialize(pos, data);
}
return pos - offset;
} }
public int findStartOfColumnOutlineGroup(int idx) public int findStartOfColumnOutlineGroup(int idx)
@ -178,8 +147,7 @@ public class ColumnInfoRecordsAggregate
return idx; return idx;
} }
public ColumnInfoRecord getColInfo(int idx) private ColumnInfoRecord getColInfo(int idx) {
{
return (ColumnInfoRecord) records.get( idx ); return (ColumnInfoRecord) records.get( idx );
} }
@ -191,7 +159,7 @@ public class ColumnInfoRecordsAggregate
columnInfo.setHidden( hidden ); columnInfo.setHidden( hidden );
if (idx + 1 < records.size()) if (idx + 1 < records.size())
{ {
ColumnInfoRecord nextColumnInfo = (ColumnInfoRecord) records.get( idx + 1 ); ColumnInfoRecord nextColumnInfo = getColInfo(idx + 1);
if (columnInfo.getLastColumn() + 1 == nextColumnInfo.getFirstColumn()) if (columnInfo.getLastColumn() + 1 == nextColumnInfo.getFirstColumn())
{ {
if (nextColumnInfo.getOutlineLevel() < level) if (nextColumnInfo.getOutlineLevel() < level)
@ -279,7 +247,7 @@ public class ColumnInfoRecordsAggregate
return; return;
// Find the start of the group. // Find the start of the group.
ColumnInfoRecord columnInfo = (ColumnInfoRecord) records.get( findStartOfColumnOutlineGroup( idx ) ); ColumnInfoRecord columnInfo = getColInfo( findStartOfColumnOutlineGroup( idx ) );
// Hide all the columns until the end of the group // Hide all the columns until the end of the group
columnInfo = writeHidden( columnInfo, idx, true ); columnInfo = writeHidden( columnInfo, idx, true );
@ -331,7 +299,7 @@ public class ColumnInfoRecordsAggregate
* @see org.apache.poi.hssf.record.ColumnInfoRecord * @see org.apache.poi.hssf.record.ColumnInfoRecord
* @return record containing a ColumnInfoRecord * @return record containing a ColumnInfoRecord
*/ */
public static Record createColInfo() public static ColumnInfoRecord createColInfo()
{ {
ColumnInfoRecord retval = new ColumnInfoRecord(); ColumnInfoRecord retval = new ColumnInfoRecord();
@ -452,7 +420,7 @@ public class ColumnInfoRecordsAggregate
ci.setCollapsed( collapsed.booleanValue() ); ci.setCollapsed( collapsed.booleanValue() );
} }
public int findColumnIdx(int column, int fromIdx) private int findColumnIdx(int column, int fromIdx)
{ {
if (column < 0) if (column < 0)
throw new IllegalArgumentException( "column parameter out of range: " + column ); throw new IllegalArgumentException( "column parameter out of range: " + column );
@ -462,7 +430,7 @@ public class ColumnInfoRecordsAggregate
ColumnInfoRecord ci; ColumnInfoRecord ci;
for (int k = fromIdx; k < records.size(); k++) for (int k = fromIdx; k < records.size(); k++)
{ {
ci = ( ColumnInfoRecord ) records.get(k); ci = getColInfo(k);
if ((ci.getFirstColumn() <= column) if ((ci.getFirstColumn() <= column)
&& (column <= ci.getLastColumn())) && (column <= ci.getLastColumn()))
{ {
@ -477,8 +445,8 @@ public class ColumnInfoRecordsAggregate
{ {
if (columnIdx == 0) if (columnIdx == 0)
return; return;
ColumnInfoRecord previousCol = (ColumnInfoRecord) records.get( columnIdx - 1); ColumnInfoRecord previousCol = getColInfo( columnIdx - 1);
ColumnInfoRecord currentCol = (ColumnInfoRecord) records.get( columnIdx ); ColumnInfoRecord currentCol = getColInfo( columnIdx );
boolean adjacentColumns = previousCol.getLastColumn() == currentCol.getFirstColumn() - 1; boolean adjacentColumns = previousCol.getLastColumn() == currentCol.getFirstColumn() - 1;
if (!adjacentColumns) if (!adjacentColumns)
return; return;
@ -513,7 +481,7 @@ public class ColumnInfoRecordsAggregate
int columnIdx = findColumnIdx( i, Math.max(0,fromIdx) ); int columnIdx = findColumnIdx( i, Math.max(0,fromIdx) );
if (columnIdx != -1) if (columnIdx != -1)
{ {
level = ((ColumnInfoRecord)records.get( columnIdx )).getOutlineLevel(); level = getColInfo(columnIdx).getOutlineLevel();
if (indent) level++; else level--; if (indent) level++; else level--;
level = Math.max(0, level); level = Math.max(0, level);
level = Math.min(7, level); level = Math.min(7, level);
@ -525,6 +493,30 @@ public class ColumnInfoRecordsAggregate
} }
} }
/**
* Finds the <tt>ColumnInfoRecord</tt> which contains the specified columnIndex
* @param columnIndex index of the column (not the index of the ColumnInfoRecord)
* @return <code>null</code> if no column info found for the specified column
*/
public ColumnInfoRecord findColumnInfo(int columnIndex) {
int nInfos = records.size();
for(int i=0; i< nInfos; i++) {
ColumnInfoRecord ci = getColInfo(i);
if (ci.getFirstColumn() <= columnIndex && columnIndex <= ci.getLastColumn()) {
return ci;
}
}
return null;
}
public int getMaxOutlineLevel() {
int result = 0;
int count=records.size();
for (int i=0; i<count; i++) {
ColumnInfoRecord columnInfoRecord = getColInfo(i);
result = Math.max(columnInfoRecord.getOutlineLevel(), result);
}
return result;
}
} }

View File

@ -0,0 +1,88 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record.aggregates;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.Record;
/**
* Holds all the conditional formatting for a workbook sheet.<p/>
*
* See OOO exelfileformat.pdf sec 4.12 'Conditional Formatting Table'
*
* @author Josh Micich
*/
public final class ConditionalFormattingTable extends RecordAggregate {
private final List _cfHeaders;
/**
* Creates an empty ConditionalFormattingTable
*/
public ConditionalFormattingTable() {
_cfHeaders = new ArrayList();
}
public ConditionalFormattingTable(RecordStream rs) {
List temp = new ArrayList();
while (rs.peekNextClass() == CFHeaderRecord.class) {
temp.add(CFRecordsAggregate.createCFAggregate(rs));
}
_cfHeaders = temp;
}
public void visitContainedRecords(RecordVisitor rv) {
for (int i = 0; i < _cfHeaders.size(); i++) {
rv.visitRecord((Record) _cfHeaders.get(i));
}
}
/**
* @return index of the newly added CF header aggregate
*/
public int add(CFRecordsAggregate cfAggregate) {
_cfHeaders.add(cfAggregate);
return _cfHeaders.size() - 1;
}
public int size() {
return _cfHeaders.size();
}
public CFRecordsAggregate get(int index) {
checkIndex(index);
return (CFRecordsAggregate) _cfHeaders.get(index);
}
public void remove(int index) {
checkIndex(index);
_cfHeaders.remove(index);
}
private void checkIndex(int index) {
if (index < 0 || index >= _cfHeaders.size()) {
throw new IllegalArgumentException("Specified CF index " + index
+ " is outside the allowable range (0.." + (_cfHeaders.size() - 1) + ")");
}
}
}

View File

@ -21,17 +21,9 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.DVALRecord; import org.apache.poi.hssf.record.DVALRecord;
import org.apache.poi.hssf.record.DVRecord; import org.apache.poi.hssf.record.DVRecord;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.HyperlinkRecord;
import org.apache.poi.hssf.record.MergeCellsRecord;
import org.apache.poi.hssf.record.PaneRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.SelectionRecord;
import org.apache.poi.hssf.record.WindowTwoRecord;
/** /**
* Manages the DVALRecord and DVRecords for a single sheet<br/> * Manages the DVALRecord and DVRecords for a single sheet<br/>
@ -40,7 +32,6 @@ import org.apache.poi.hssf.record.WindowTwoRecord;
*/ */
public final class DataValidityTable extends RecordAggregate { public final class DataValidityTable extends RecordAggregate {
private static final short sid = -0x01B2; // not a real record
private final DVALRecord _headerRec; private final DVALRecord _headerRec;
/** /**
* The list of data validations for the current sheet. * The list of data validations for the current sheet.
@ -57,120 +48,21 @@ public final class DataValidityTable extends RecordAggregate {
_validationList = temp; _validationList = temp;
} }
private DataValidityTable() { public DataValidityTable() {
_headerRec = new DVALRecord(); _headerRec = new DVALRecord();
_validationList = new ArrayList(); _validationList = new ArrayList();
} }
public short getSid() { public void visitContainedRecords(RecordVisitor rv) {
return sid; if (_validationList.isEmpty()) {
} return;
}
public int serialize(int offset, byte[] data) { rv.visitRecord(_headerRec);
int result = _headerRec.serialize(offset, data);
for (int i = 0; i < _validationList.size(); i++) { for (int i = 0; i < _validationList.size(); i++) {
result += ((Record) _validationList.get(i)).serialize(offset + result, data); rv.visitRecord((Record) _validationList.get(i));
} }
return result;
}
public int getRecordSize() {
int result = _headerRec.getRecordSize();
for (int i = _validationList.size() - 1; i >= 0; i--) {
result += ((Record) _validationList.get(i)).getRecordSize();
}
return result;
}
/**
* Creates a new <tt>DataValidityTable</tt> and inserts it in the right
* place in the sheetRecords list.
*/
public static DataValidityTable createForSheet(List sheetRecords) {
int index = findDVTableInsertPos(sheetRecords);
DataValidityTable result = new DataValidityTable();
sheetRecords.add(index, result);
return result;
} }
/**
* Finds the index where the sheet validations header record should be inserted
* @param records the records for this sheet
*
* + WINDOW2
* o SCL
* o PANE
* oo SELECTION
* o STANDARDWIDTH
* oo MERGEDCELLS
* o LABELRANGES
* o PHONETICPR
* o Conditional Formatting Table
* o Hyperlink Table
* o Data Validity Table
* o SHEETLAYOUT
* o SHEETPROTECTION
* o RANGEPROTECTION
* + EOF
*/
private static int findDVTableInsertPos(List records) {
int i = records.size() - 1;
if (!(records.get(i) instanceof EOFRecord)) {
throw new IllegalStateException("Last sheet record should be EOFRecord");
}
while (i > 0) {
i--;
Record rec = (Record) records.get(i);
if (isPriorRecord(rec.getSid())) {
Record nextRec = (Record) records.get(i + 1);
if (!isSubsequentRecord(nextRec.getSid())) {
throw new IllegalStateException("Unexpected (" + nextRec.getClass().getName()
+ ") found after (" + rec.getClass().getName() + ")");
}
return i;
}
if (!isSubsequentRecord(rec.getSid())) {
throw new IllegalStateException("Unexpected (" + rec.getClass().getName()
+ ") while looking for DV Table insert pos");
}
}
return 0;
}
// TODO - add UninterpretedRecord as base class for many of these
// unimplemented sids
private static boolean isPriorRecord(short sid) {
switch(sid) {
case WindowTwoRecord.sid:
case 0x00A0: // SCL
case PaneRecord.sid:
case SelectionRecord.sid:
case 0x0099: // STANDARDWIDTH
case MergeCellsRecord.sid:
case 0x015F: // LABELRANGES
case 0x00EF: // PHONETICPR
case CFHeaderRecord.sid:
case CFRuleRecord.sid:
case HyperlinkRecord.sid:
case 0x0800: // QUICKTIP
return true;
}
return false;
}
private static boolean isSubsequentRecord(short sid) {
switch(sid) {
case 0x0862: // SHEETLAYOUT
case 0x0867: // SHEETPROTECTION
case 0x0868: // RANGEPROTECTION
case EOFRecord.sid:
return true;
}
return false;
}
public void addDataValidation(DVRecord dvRecord) { public void addDataValidation(DVRecord dvRecord) {
_validationList.add(dvRecord); _validationList.add(dvRecord);
_headerRec.setDVRecNo(_validationList.size()); _headerRec.setDVRecNo(_validationList.size());

View File

@ -0,0 +1,122 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record.aggregates;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.MergeCellsRecord;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.CellRangeAddressList;
/**
*
* @author Josh Micich
*/
public final class MergedCellsTable extends RecordAggregate {
private static int MAX_MERGED_REGIONS = 1027; // enforced by the 8224 byte limit
private final List _mergedRegions;
/**
* Creates an empty aggregate
*/
public MergedCellsTable() {
_mergedRegions = new ArrayList();
}
public MergedCellsTable(RecordStream rs) {
List temp = new ArrayList();
while (rs.peekNextClass() == MergeCellsRecord.class) {
MergeCellsRecord mcr = (MergeCellsRecord) rs.getNext();
int nRegions = mcr.getNumAreas();
for (int i = 0; i < nRegions; i++) {
temp.add(mcr.getAreaAt(i));
}
}
_mergedRegions = temp;
}
public int getRecordSize() {
// a bit cheaper than the default impl
int nRegions = _mergedRegions.size();
if (nRegions < 1) {
// no need to write a single empty MergeCellsRecord
return 0;
}
int nMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
int result = nMergedCellsRecords
* (4 + CellRangeAddressList.getEncodedSize(MAX_MERGED_REGIONS)) + 4
+ CellRangeAddressList.getEncodedSize(nLeftoverMergedRegions);
return result;
}
public void visitContainedRecords(RecordVisitor rv) {
int nRegions = _mergedRegions.size();
if (nRegions < 1) {
// no need to write a single empty MergeCellsRecord
return;
}
int nFullMergedCellsRecords = nRegions / MAX_MERGED_REGIONS;
int nLeftoverMergedRegions = nRegions % MAX_MERGED_REGIONS;
CellRangeAddress[] cras = new CellRangeAddress[nRegions];
_mergedRegions.toArray(cras);
for (int i = 0; i < nFullMergedCellsRecords; i++) {
int startIx = i * MAX_MERGED_REGIONS;
rv.visitRecord(new MergeCellsRecord(cras, startIx, MAX_MERGED_REGIONS));
}
if (nLeftoverMergedRegions > 0) {
int startIx = nFullMergedCellsRecords * MAX_MERGED_REGIONS;
rv.visitRecord(new MergeCellsRecord(cras, startIx, nLeftoverMergedRegions));
}
}
public void add(MergeCellsRecord mcr) {
_mergedRegions.add(mcr);
}
public CellRangeAddress get(int index) {
checkIndex(index);
return (CellRangeAddress) _mergedRegions.get(index);
}
public void remove(int index) {
checkIndex(index);
_mergedRegions.remove(index);
}
private void checkIndex(int index) {
if (index < 0 || index >= _mergedRegions.size()) {
throw new IllegalArgumentException("Specified CF index " + index
+ " is outside the allowable range (0.." + (_mergedRegions.size() - 1) + ")");
}
}
public void addArea(int rowFrom, int colFrom, int rowTo, int colTo) {
_mergedRegions.add(new CellRangeAddress(rowFrom, rowTo, colFrom, colTo));
}
public int getNumberOfMergedRegions() {
return _mergedRegions.size();
}
}

View File

@ -18,6 +18,7 @@
package org.apache.poi.hssf.record.aggregates; package org.apache.poi.hssf.record.aggregates;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
/** /**
@ -27,15 +28,66 @@ import org.apache.poi.hssf.record.RecordInputStream;
* *
* @author Josh Micich * @author Josh Micich
*/ */
public abstract class RecordAggregate extends Record { public abstract class RecordAggregate extends RecordBase {
// TODO - convert existing aggregate classes to proper subclasses of this one // TODO - delete these methods when all subclasses have been converted
protected final void validateSid(short id) { protected final void validateSid(short id) {
// TODO - break class hierarchy and make separate from Record
throw new RuntimeException("Should not be called"); throw new RuntimeException("Should not be called");
} }
protected final void fillFields(RecordInputStream in) { protected final void fillFields(RecordInputStream in) {
throw new RuntimeException("Should not be called"); throw new RuntimeException("Should not be called");
} }
// force subclassses to provide better implementation than default public final short getSid() {
public abstract int getRecordSize(); throw new RuntimeException("Should not be called");
}
public abstract void visitContainedRecords(RecordVisitor rv);
public final int serialize(int offset, byte[] data) {
SerializingRecordVisitor srv = new SerializingRecordVisitor(data, offset);
visitContainedRecords(srv);
return srv.countBytesWritten();
}
public int getRecordSize() {
RecordSizingVisitor rsv = new RecordSizingVisitor();
visitContainedRecords(rsv);
return rsv.getTotalSize();
}
public interface RecordVisitor {
void visitRecord(Record r);
}
private static final class SerializingRecordVisitor implements RecordVisitor {
private final byte[] _data;
private final int _startOffset;
private int _countBytesWritten;
public SerializingRecordVisitor(byte[] data, int startOffset) {
_data = data;
_startOffset = startOffset;
_countBytesWritten = 0;
}
public int countBytesWritten() {
return _countBytesWritten;
}
public void visitRecord(Record r) {
int currentOffset = _startOffset + _countBytesWritten;
_countBytesWritten += r.serialize(currentOffset, _data);
}
}
private static final class RecordSizingVisitor implements RecordVisitor {
private int _totalSize;
public RecordSizingVisitor() {
_totalSize = 0;
}
public int getTotalSize() {
return _totalSize;
}
public void visitRecord(Record r) {
_totalSize += r.getRecordSize();
}
}
} }

View File

@ -25,7 +25,6 @@ import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
* Title: Area 3D Ptg - 3D reference (Sheet + Area)<P> * Title: Area 3D Ptg - 3D reference (Sheet + Area)<P>
* Description: Defined a area in Extern Sheet. <P> * Description: Defined a area in Extern Sheet. <P>
@ -38,14 +37,16 @@ import org.apache.poi.util.LittleEndian;
public final class Area3DPtg extends OperandPtg implements AreaI { public final class Area3DPtg extends OperandPtg implements AreaI {
public final static byte sid = 0x3b; public final static byte sid = 0x3b;
private final static int SIZE = 11; // 10 + 1 for Ptg private final static int SIZE = 11; // 10 + 1 for Ptg
private static final BitField rowRelative = BitFieldFactory.getInstance(0x8000);
private static final BitField colRelative = BitFieldFactory.getInstance(0x4000);
private short field_1_index_extern_sheet; private short field_1_index_extern_sheet;
private int field_2_first_row; private int field_2_first_row;
private int field_3_last_row; private int field_3_last_row;
private int field_4_first_column; private int field_4_first_column;
private int field_5_last_column; private int field_5_last_column;
private BitField rowRelative = BitFieldFactory.getInstance( 0x8000 );
private BitField colRelative = BitFieldFactory.getInstance( 0x4000 );
/** Creates new AreaPtg */ /** Creates new AreaPtg */
public Area3DPtg() public Area3DPtg()

View File

@ -36,6 +36,10 @@ import org.apache.poi.util.LittleEndian;
*/ */
public final class Ref3DPtg extends OperandPtg { public final class Ref3DPtg extends OperandPtg {
public final static byte sid = 0x3a; public final static byte sid = 0x3a;
private static final BitField rowRelative = BitFieldFactory.getInstance(0x8000);
private static final BitField colRelative = BitFieldFactory.getInstance(0x4000);
private final static int SIZE = 7; // 6 + 1 for Ptg private final static int SIZE = 7; // 6 + 1 for Ptg
private short field_1_index_extern_sheet; private short field_1_index_extern_sheet;
/** The row index - zero based unsigned 16 bit value */ /** The row index - zero based unsigned 16 bit value */
@ -46,8 +50,6 @@ public final class Ref3DPtg extends OperandPtg {
* - bit 15 - isColumnRelative * - bit 15 - isColumnRelative
*/ */
private int field_3_column; private int field_3_column;
private BitField rowRelative = BitFieldFactory.getInstance(0x8000);
private BitField colRelative = BitFieldFactory.getInstance(0x4000);
/** Creates new AreaPtg */ /** Creates new AreaPtg */
public Ref3DPtg() {} public Ref3DPtg() {}

View File

@ -48,6 +48,7 @@ import org.apache.poi.hssf.record.NoteRecord;
import org.apache.poi.hssf.record.NumberRecord; import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.StringRecord; import org.apache.poi.hssf.record.StringRecord;
import org.apache.poi.hssf.record.SubRecord; import org.apache.poi.hssf.record.SubRecord;
import org.apache.poi.hssf.record.TextObjectRecord; import org.apache.poi.hssf.record.TextObjectRecord;
@ -1154,7 +1155,7 @@ public class HSSFCell implements Cell
HSSFComment comment = null; HSSFComment comment = null;
HashMap txshapes = new HashMap(); //map shapeId and TextObjectRecord HashMap txshapes = new HashMap(); //map shapeId and TextObjectRecord
for (Iterator it = sheet.getRecords().iterator(); it.hasNext(); ) { for (Iterator it = sheet.getRecords().iterator(); it.hasNext(); ) {
Record rec = ( Record ) it.next(); RecordBase rec = (RecordBase) it.next();
if (rec instanceof NoteRecord){ if (rec instanceof NoteRecord){
NoteRecord note = (NoteRecord)rec; NoteRecord note = (NoteRecord)rec;
if (note.getRow() == row && note.getColumn() == column){ if (note.getRow() == row && note.getColumn() == column){
@ -1196,7 +1197,7 @@ public class HSSFCell implements Cell
*/ */
public HSSFHyperlink getHyperlink(){ public HSSFHyperlink getHyperlink(){
for (Iterator it = sheet.getRecords().iterator(); it.hasNext(); ) { for (Iterator it = sheet.getRecords().iterator(); it.hasNext(); ) {
Record rec = ( Record ) it.next(); RecordBase rec = (RecordBase) it.next();
if (rec instanceof HyperlinkRecord){ if (rec instanceof HyperlinkRecord){
HyperlinkRecord link = (HyperlinkRecord)rec; HyperlinkRecord link = (HyperlinkRecord)rec;
if(link.getFirstColumn() == record.getColumn() && link.getFirstRow() == record.getRow()){ if(link.getFirstColumn() == record.getColumn() && link.getFirstRow() == record.getRow()){

View File

@ -1464,43 +1464,19 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
} }
/** /**
* Retrieves all the horizontal page breaks * @return row indexes of all the horizontal page breaks, never <code>null</code>
* @return all the horizontal page breaks, or null if there are no row page breaks
*/ */
public int[] getRowBreaks(){ public int[] getRowBreaks(){
//we can probably cache this information, but this should be a sparsely used function //we can probably cache this information, but this should be a sparsely used function
int count = sheet.getNumRowBreaks(); return sheet.getRowBreaks();
if (count > 0) {
int[] returnValue = new int[count];
Iterator iterator = sheet.getRowBreaks();
int i = 0;
while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
returnValue[i++] = breakItem.main;
}
return returnValue;
}
return null;
} }
/** /**
* Retrieves all the vertical page breaks * @return column indexes of all the vertical page breaks, never <code>null</code>
* @return all the vertical page breaks, or null if there are no column page breaks
*/ */
public short[] getColumnBreaks(){ public int[] getColumnBreaks(){
//we can probably cache this information, but this should be a sparsely used function //we can probably cache this information, but this should be a sparsely used function
int count = sheet.getNumColumnBreaks(); return sheet.getColumnBreaks();
if (count > 0) {
short[] returnValue = new short[count];
Iterator iterator = sheet.getColumnBreaks();
int i = 0;
while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
returnValue[i++] = breakItem.main;
}
return returnValue;
}
return null;
} }

View File

@ -99,7 +99,14 @@ public class CellRangeAddressList {
} }
public int getSize() { public int getSize() {
return 2 + CellRangeAddress.getEncodedSize(_list.size()); return getEncodedSize(_list.size());
}
/**
* @return the total size of for the specified number of ranges,
* including the initial 2 byte range count
*/
public static int getEncodedSize(int numberOfRanges) {
return 2 + CellRangeAddress.getEncodedSize(numberOfRanges);
} }
public int serialize(int offset, byte[] data) { public int serialize(int offset, byte[] data) {

View File

@ -631,7 +631,7 @@ public interface Sheet extends Iterable<Row> {
* Retrieves all the vertical page breaks * Retrieves all the vertical page breaks
* @return all the vertical page breaks, or null if there are no column page breaks * @return all the vertical page breaks, or null if there are no column page breaks
*/ */
short[] getColumnBreaks(); int[] getColumnBreaks();
/** /**
* Sets a page break at the indicated column * Sets a page break at the indicated column

View File

@ -312,15 +312,15 @@ public class XSSFSheet implements Sheet {
return null; return null;
} }
public short[] getColumnBreaks() { public int[] getColumnBreaks() {
CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray(); CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray();
if (brkArray.length == 0) { if (brkArray.length == 0) {
return null; return null;
} }
short[] breaks = new short[brkArray.length]; int[] breaks = new int[brkArray.length];
for (int i = 0 ; i < brkArray.length ; i++) { for (int i = 0 ; i < brkArray.length ; i++) {
CTBreak brk = brkArray[i]; CTBreak brk = brkArray[i];
breaks[i] = (short) brk.getId(); breaks[i] = (int)brk.getId();
} }
return breaks; return breaks;
} }

File diff suppressed because it is too large Load Diff

View File

@ -14,26 +14,18 @@
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.usermodel; package org.apache.poi.hssf.usermodel;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.hssf.record.SeriesRecord;
import junit.framework.TestCase; import junit.framework.TestCase;
public class TestHSSFChart extends TestCase { import org.apache.poi.hssf.HSSFTestDataSamples;
private String dirName; import org.apache.poi.hssf.record.SeriesRecord;
protected void setUp() throws Exception { public final class TestHSSFChart extends TestCase {
dirName = System.getProperty("HSSF.testdata.path");
}
public void testSingleChart() throws Exception { public void testSingleChart() throws Exception {
HSSFWorkbook wb = new HSSFWorkbook( HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithChart.xls");
new FileInputStream(new File(dirName, "WithChart.xls"))
);
HSSFSheet s1 = wb.getSheetAt(0); HSSFSheet s1 = wb.getSheetAt(0);
HSSFSheet s2 = wb.getSheetAt(1); HSSFSheet s2 = wb.getSheetAt(1);
@ -62,9 +54,7 @@ public class TestHSSFChart extends TestCase {
} }
public void testTwoCharts() throws Exception { public void testTwoCharts() throws Exception {
HSSFWorkbook wb = new HSSFWorkbook( HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithTwoCharts.xls");
new FileInputStream(new File(dirName, "WithTwoCharts.xls"))
);
HSSFSheet s1 = wb.getSheetAt(0); HSSFSheet s1 = wb.getSheetAt(0);
HSSFSheet s2 = wb.getSheetAt(1); HSSFSheet s2 = wb.getSheetAt(1);
@ -96,9 +86,7 @@ public class TestHSSFChart extends TestCase {
} }
public void testThreeCharts() throws Exception { public void testThreeCharts() throws Exception {
HSSFWorkbook wb = new HSSFWorkbook( HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("WithThreeCharts.xls");
new FileInputStream(new File(dirName, "WithThreeCharts.xls"))
);
HSSFSheet s1 = wb.getSheetAt(0); HSSFSheet s1 = wb.getSheetAt(0);
HSSFSheet s2 = wb.getSheetAt(1); HSSFSheet s2 = wb.getSheetAt(1);

View File

@ -32,7 +32,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
*/ */
public final class TestExcelExtractor extends TestCase { public final class TestExcelExtractor extends TestCase {
private static final ExcelExtractor createExtractor(String sampleFileName) { private static ExcelExtractor createExtractor(String sampleFileName) {
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName); InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
@ -192,18 +192,16 @@ public final class TestExcelExtractor extends TestCase {
* Embded in a non-excel file * Embded in a non-excel file
*/ */
public void testWithEmbeded() throws Exception { public void testWithEmbeded() throws Exception {
// TODO - encapsulate sys prop 'POIFS.testdata.path' similar to HSSFTestDataSamples
String pdirname = System.getProperty("POIFS.testdata.path"); String pdirname = System.getProperty("POIFS.testdata.path");
String filename = pdirname + "/word_with_embeded.doc"; String filename = pdirname + "/word_with_embeded.doc";
POIFSFileSystem fs = new POIFSFileSystem( POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(filename) new FileInputStream(filename)
); );
DirectoryNode objPool = (DirectoryNode) DirectoryNode objPool = (DirectoryNode) fs.getRoot().getEntry("ObjectPool");
fs.getRoot().getEntry("ObjectPool"); DirectoryNode dirA = (DirectoryNode) objPool.getEntry("_1269427460");
DirectoryNode dirA = (DirectoryNode) DirectoryNode dirB = (DirectoryNode) objPool.getEntry("_1269427461");
objPool.getEntry("_1269427460");
DirectoryNode dirB = (DirectoryNode)
objPool.getEntry("_1269427461");
HSSFWorkbook wbA = new HSSFWorkbook(dirA, fs, true); HSSFWorkbook wbA = new HSSFWorkbook(dirA, fs, true);
HSSFWorkbook wbB = new HSSFWorkbook(dirB, fs, true); HSSFWorkbook wbB = new HSSFWorkbook(dirB, fs, true);
@ -224,16 +222,15 @@ public final class TestExcelExtractor extends TestCase {
* Excel embeded in excel * Excel embeded in excel
*/ */
public void testWithEmbededInOwn() throws Exception { public void testWithEmbededInOwn() throws Exception {
// TODO - encapsulate sys prop 'POIFS.testdata.path' similar to HSSFTestDataSamples
String pdirname = System.getProperty("POIFS.testdata.path"); String pdirname = System.getProperty("POIFS.testdata.path");
String filename = pdirname + "/excel_with_embeded.xls"; String filename = pdirname + "/excel_with_embeded.xls";
POIFSFileSystem fs = new POIFSFileSystem( POIFSFileSystem fs = new POIFSFileSystem(
new FileInputStream(filename) new FileInputStream(filename)
); );
DirectoryNode dirA = (DirectoryNode) DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B5");
fs.getRoot().getEntry("MBD0000A3B5"); DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B4");
DirectoryNode dirB = (DirectoryNode)
fs.getRoot().getEntry("MBD0000A3B4");
HSSFWorkbook wbA = new HSSFWorkbook(dirA, fs, true); HSSFWorkbook wbA = new HSSFWorkbook(dirA, fs, true);
HSSFWorkbook wbB = new HSSFWorkbook(dirB, fs, true); HSSFWorkbook wbB = new HSSFWorkbook(dirB, fs, true);
@ -260,15 +257,15 @@ public final class TestExcelExtractor extends TestCase {
* Test that we get text from headers and footers * Test that we get text from headers and footers
*/ */
public void test45538() throws Exception { public void test45538() throws Exception {
String[] files = new String[] { String[] files = {
"45538_classic_Footer.xls", "45538_form_Footer.xls", "45538_classic_Footer.xls", "45538_form_Footer.xls",
"45538_classic_Header.xls", "45538_form_Header.xls" "45538_classic_Header.xls", "45538_form_Header.xls"
}; };
for(int i=0; i<files.length; i++) { for(int i=0; i<files.length; i++) {
ExcelExtractor extractor = createExtractor(files[i]); ExcelExtractor extractor = createExtractor(files[i]);
String text = extractor.getText(); String text = extractor.getText();
assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc")); assertTrue("Unable to find expected word in text\n" + text, text.indexOf("testdoc") >=0);
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase")); assertTrue("Unable to find expected word in text\n" + text, text.indexOf("test phrase") >= 0);
} }
} }
} }

View File

@ -17,20 +17,31 @@
package org.apache.poi.hssf.model; package org.apache.poi.hssf.model;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.eventmodel.ERFListener; import org.apache.poi.hssf.eventmodel.ERFListener;
import org.apache.poi.hssf.eventmodel.EventRecordFactory; import org.apache.poi.hssf.eventmodel.EventRecordFactory;
import org.apache.poi.hssf.record.*; import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.ColumnInfoRecord;
import org.apache.poi.hssf.record.DimensionsRecord;
import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.IndexRecord;
import org.apache.poi.hssf.record.MergeCellsRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.StringRecord;
import org.apache.poi.hssf.record.UncalcedRecord;
import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate; import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate; import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate; import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
import org.apache.poi.hssf.util.CellRangeAddress;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/** /**
* Unit test for the Sheet class. * Unit test for the Sheet class.
@ -55,10 +66,24 @@ public final class TestSheet extends TestCase {
assertTrue( sheet.records.get(pos++) instanceof EOFRecord ); assertTrue( sheet.records.get(pos++) instanceof EOFRecord );
} }
private static final class MergedCellListener implements ERFListener {
private int _count;
public MergedCellListener() {
_count = 0;
}
public boolean processRecord(Record rec) {
_count++;
return true;
}
public int getCount() {
return _count;
}
}
public void testAddMergedRegion() { public void testAddMergedRegion() {
Sheet sheet = Sheet.createSheet(); Sheet sheet = Sheet.createSheet();
int regionsToAdd = 4096; int regionsToAdd = 4096;
int startRecords = sheet.getRecords().size();
//simple test that adds a load of regions //simple test that adds a load of regions
for (int n = 0; n < regionsToAdd; n++) for (int n = 0; n < regionsToAdd; n++)
@ -71,11 +96,18 @@ public final class TestSheet extends TestCase {
assertTrue(sheet.getNumMergedRegions() == regionsToAdd); assertTrue(sheet.getNumMergedRegions() == regionsToAdd);
//test that the regions were spread out over the appropriate number of records //test that the regions were spread out over the appropriate number of records
int recordsAdded = sheet.getRecords().size() - startRecords; byte[] sheetData = new byte[sheet.getSize()];
sheet.serialize(0, sheetData);
MergedCellListener mcListener = new MergedCellListener();
EventRecordFactory erf = new EventRecordFactory(mcListener, new short[] { MergeCellsRecord.sid, });
// POIFSFileSystem poifs = new POIFSFileSystem(new ByteArrayInputStream(sheetData));
erf.processRecords(new ByteArrayInputStream(sheetData));
int recordsAdded = mcListener.getCount();
int recordsExpected = regionsToAdd/1027; int recordsExpected = regionsToAdd/1027;
if ((regionsToAdd % 1027) != 0) if ((regionsToAdd % 1027) != 0)
recordsExpected++; recordsExpected++;
assertTrue("The " + regionsToAdd + " merged regions should have been spread out over " + recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected); assertTrue("The " + regionsToAdd + " merged regions should have been spread out over "
+ recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
// Check we can't add one with invalid date // Check we can't add one with invalid date
try { try {
sheet.addMergedRegion(10, (short)10, 9, (short)12); sheet.addMergedRegion(10, (short)10, 9, (short)12);
@ -97,22 +129,23 @@ public final class TestSheet extends TestCase {
Sheet sheet = Sheet.createSheet(); Sheet sheet = Sheet.createSheet();
int regionsToAdd = 4096; int regionsToAdd = 4096;
for (int n = 0; n < regionsToAdd; n++) for (int n = 0; n < regionsToAdd; n++) {
sheet.addMergedRegion(0, (short) 0, 1, (short) 1); sheet.addMergedRegion(n, 0, n, 1);
}
int records = sheet.getRecords().size(); int nSheetRecords = sheet.getRecords().size();
//remove a third from the beginning //remove a third from the beginning
for (int n = 0; n < regionsToAdd/3; n++) for (int n = 0; n < regionsToAdd/3; n++)
{ {
sheet.removeMergedRegion(0); sheet.removeMergedRegion(0);
//assert they have been deleted //assert they have been deleted
assertTrue("Num of regions should be " + (regionsToAdd - n - 1) + " not " + sheet.getNumMergedRegions(), sheet.getNumMergedRegions() == regionsToAdd - n - 1); assertEquals("Num of regions", regionsToAdd - n - 1, sheet.getNumMergedRegions());
} }
//assert any record removing was done // merge records are removed from within the MergedCellsTable,
int recordsRemoved = (regionsToAdd/3)/1027; //doesn't work for particular values of regionsToAdd // so the sheet record count should not change
assertTrue("Expected " + recordsRemoved + " record to be removed from the starting " + records + ". Currently there are " + sheet.getRecords().size() + " records", records - sheet.getRecords().size() == recordsRemoved); assertEquals("Sheet Records", nSheetRecords, sheet.getRecords().size());
} }
/** /**
@ -125,8 +158,11 @@ public final class TestSheet extends TestCase {
public void testMovingMergedRegion() { public void testMovingMergedRegion() {
List records = new ArrayList(); List records = new ArrayList();
MergeCellsRecord merged = new MergeCellsRecord(); CellRangeAddress[] cras = {
merged.addArea(0, (short)0, 1, (short)2); new CellRangeAddress(0, 1, 0, 2),
};
MergeCellsRecord merged = new MergeCellsRecord(cras, 0, cras.length);
records.add(new DimensionsRecord());
records.add(new RowRecord(0)); records.add(new RowRecord(0));
records.add(new RowRecord(1)); records.add(new RowRecord(1));
records.add(new RowRecord(2)); records.add(new RowRecord(2));
@ -155,6 +191,7 @@ public final class TestSheet extends TestCase {
public void testRowAggregation() { public void testRowAggregation() {
List records = new ArrayList(); List records = new ArrayList();
records.add(new DimensionsRecord());
records.add(new RowRecord(0)); records.add(new RowRecord(0));
records.add(new RowRecord(1)); records.add(new RowRecord(1));
records.add(new StringRecord()); records.add(new StringRecord());
@ -196,10 +233,9 @@ public final class TestSheet extends TestCase {
boolean is0 = false; boolean is0 = false;
boolean is11 = false; boolean is11 = false;
Iterator iterator = sheet.getRowBreaks(); int[] rowBreaks = sheet.getRowBreaks();
while (iterator.hasNext()) { for (int i = 0; i < rowBreaks.length; i++) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); int main = rowBreaks[i];
int main = breakItem.main;
if (main != 0 && main != 10 && main != 11) fail("Invalid page break"); if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
if (main == 0) is0 = true; if (main == 0) is0 = true;
if (main == 10) is10= true; if (main == 10) is10= true;
@ -253,10 +289,9 @@ public final class TestSheet extends TestCase {
boolean is1 = false; boolean is1 = false;
boolean is15 = false; boolean is15 = false;
Iterator iterator = sheet.getColumnBreaks(); int[] colBreaks = sheet.getColumnBreaks();
while (iterator.hasNext()) { for (int i = 0; i < colBreaks.length; i++) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); int main = colBreaks[i];
int main = breakItem.main;
if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break"); if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break");
if (main == 0) is0 = true; if (main == 0) is0 = true;
if (main == 1) is1 = true; if (main == 1) is1 = true;
@ -297,9 +332,8 @@ public final class TestSheet extends TestCase {
xfindex = sheet.getXFIndexForColAt((short) 1); xfindex = sheet.getXFIndexForColAt((short) 1);
assertEquals(DEFAULT_IDX, xfindex); assertEquals(DEFAULT_IDX, xfindex);
// TODO change return type to ColumnInfoRecord ColumnInfoRecord nci = ColumnInfoRecordsAggregate.createColInfo();
ColumnInfoRecord nci = (ColumnInfoRecord)ColumnInfoRecordsAggregate.createColInfo(); sheet._columnInfos.insertColumn(nci);
sheet.columns.insertColumn(nci);
// single column ColumnInfoRecord // single column ColumnInfoRecord
nci.setFirstColumn((short) 2); nci.setFirstColumn((short) 2);
@ -361,6 +395,7 @@ public final class TestSheet extends TestCase {
List records = new ArrayList(); List records = new ArrayList();
records.add(new BOFRecord()); records.add(new BOFRecord());
records.add(new UncalcedRecord()); records.add(new UncalcedRecord());
records.add(new DimensionsRecord());
records.add(new EOFRecord()); records.add(new EOFRecord());
Sheet sheet = Sheet.createSheet(records, 0, 0); Sheet sheet = Sheet.createSheet(records, 0, 0);
@ -369,7 +404,7 @@ public final class TestSheet extends TestCase {
if (serializedSize != estimatedSize) { if (serializedSize != estimatedSize) {
throw new AssertionFailedError("Identified bug 45066 b"); throw new AssertionFailedError("Identified bug 45066 b");
} }
assertEquals(50, serializedSize); assertEquals(68, serializedSize);
} }
/** /**
@ -393,7 +428,7 @@ public final class TestSheet extends TestCase {
int dbCellRecordPos = getDbCellRecordPos(sheet); int dbCellRecordPos = getDbCellRecordPos(sheet);
if (dbCellRecordPos == 264) { if (dbCellRecordPos == 252) {
// The overt symptom of the bug // The overt symptom of the bug
// DBCELL record pos is calculated wrong if VRA comes before RRA // DBCELL record pos is calculated wrong if VRA comes before RRA
throw new AssertionFailedError("Identified bug 45145"); throw new AssertionFailedError("Identified bug 45145");
@ -405,7 +440,7 @@ public final class TestSheet extends TestCase {
assertEquals(RowRecordsAggregate.class, recs.get(rraIx).getClass()); assertEquals(RowRecordsAggregate.class, recs.get(rraIx).getClass());
assertEquals(ValueRecordsAggregate.class, recs.get(rraIx+1).getClass()); assertEquals(ValueRecordsAggregate.class, recs.get(rraIx+1).getClass());
assertEquals(254, dbCellRecordPos); assertEquals(242, dbCellRecordPos);
} }
/** /**

View File

@ -29,8 +29,7 @@ public final class TestSheetAdditional extends TestCase {
public void testGetCellWidth() { public void testGetCellWidth() {
Sheet sheet = Sheet.createSheet(); Sheet sheet = Sheet.createSheet();
// TODO change return type to ColumnInfoRecord ColumnInfoRecord nci = ColumnInfoRecordsAggregate.createColInfo();
ColumnInfoRecord nci = (ColumnInfoRecord)ColumnInfoRecordsAggregate.createColInfo();
// Prepare test model // Prepare test model
nci.setFirstColumn((short)5); nci.setFirstColumn((short)5);
@ -38,7 +37,7 @@ public final class TestSheetAdditional extends TestCase {
nci.setColumnWidth((short)100); nci.setColumnWidth((short)100);
sheet.columns.insertColumn(nci); sheet._columnInfos.insertColumn(nci);
assertEquals((short)100,sheet.getColumnWidth((short)5)); assertEquals((short)100,sheet.getColumnWidth((short)5));
assertEquals((short)100,sheet.getColumnWidth((short)6)); assertEquals((short)100,sheet.getColumnWidth((short)6));
@ -58,6 +57,3 @@ public final class TestSheetAdditional extends TestCase {
} }
} }

View File

@ -33,8 +33,8 @@ public final class TestMergeCellsRecord extends TestCase {
* @throws Exception * @throws Exception
*/ */
public void testCloneReferences() throws Exception { public void testCloneReferences() throws Exception {
MergeCellsRecord merge = new MergeCellsRecord(); CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), };
merge.addArea(0, (short)0, 1, (short)2); MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
MergeCellsRecord clone = (MergeCellsRecord)merge.clone(); MergeCellsRecord clone = (MergeCellsRecord)merge.clone();
assertNotSame("Merged and cloned objects are the same", merge, clone); assertNotSame("Merged and cloned objects are the same", merge, clone);
@ -47,7 +47,6 @@ public final class TestMergeCellsRecord extends TestCase {
assertEquals("New Clone Col From doesnt match", mergeRegion.getFirstColumn(), cloneRegion.getFirstColumn()); assertEquals("New Clone Col From doesnt match", mergeRegion.getFirstColumn(), cloneRegion.getFirstColumn());
assertEquals("New Clone Col To doesnt match", mergeRegion.getLastColumn(), cloneRegion.getLastColumn()); assertEquals("New Clone Col To doesnt match", mergeRegion.getLastColumn(), cloneRegion.getLastColumn());
merge.removeAreaAt(0); assertFalse(merge.getAreaAt(0) == clone.getAreaAt(0));
assertNotNull("Clone's item not removed", clone.getAreaAt(0));
} }
} }

View File

@ -24,6 +24,7 @@ import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.CFHeaderRecord; import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.CFRuleRecord; import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.RecordFactory; import org.apache.poi.hssf.record.RecordFactory;
@ -59,7 +60,7 @@ public final class TestCFRecordsAggregate extends TestCase
recs.add(rule2); recs.add(rule2);
recs.add(rule3); recs.add(rule3);
CFRecordsAggregate record; CFRecordsAggregate record;
record = CFRecordsAggregate.createCFAggregate(recs, 0); record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
// Serialize // Serialize
byte [] serializedRecord = record.serialize(); byte [] serializedRecord = record.serialize();
@ -81,7 +82,7 @@ public final class TestCFRecordsAggregate extends TestCase
assertEquals(2, cellRanges.length); assertEquals(2, cellRanges.length);
assertEquals(3, header.getNumberOfConditionalFormats()); assertEquals(3, header.getNumberOfConditionalFormats());
record = CFRecordsAggregate.createCFAggregate(recs, 0); record = CFRecordsAggregate.createCFAggregate(new RecordStream(recs, 0));
record = record.cloneCFAggregate(); record = record.cloneCFAggregate();

View File

@ -19,42 +19,39 @@ package org.apache.poi.hssf.record.aggregates;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.record.ColumnInfoRecord; import org.apache.poi.hssf.record.ColumnInfoRecord;
import org.apache.poi.hssf.record.RecordBase;
/** /**
* @author Glen Stampoultzis * @author Glen Stampoultzis
*/ */
public final class TestColumnInfoRecordsAggregate extends TestCase public final class TestColumnInfoRecordsAggregate extends TestCase {
{
ColumnInfoRecordsAggregate columnInfoRecordsAggregate;
public void testGetRecordSize() throws Exception public void testGetRecordSize() {
{ ColumnInfoRecordsAggregate agg = new ColumnInfoRecordsAggregate();
columnInfoRecordsAggregate = new ColumnInfoRecordsAggregate(); agg.insertColumn(createColumn(1, 3));
columnInfoRecordsAggregate.insertColumn( createColumn( (short)1, (short)3 )); agg.insertColumn(createColumn(4, 7));
columnInfoRecordsAggregate.insertColumn( createColumn( (short)4, (short)7 )); agg.insertColumn(createColumn(8, 8));
columnInfoRecordsAggregate.insertColumn( createColumn( (short)8, (short)8 )); agg.groupColumnRange((short) 2, (short) 5, true);
// columnInfoRecordsAggregate.setColumn( (short)2, new Short( (short)200 ), new Integer( 1 ), new Boolean( true ), null); assertEquals(6, agg.getNumColumns());
columnInfoRecordsAggregate.groupColumnRange( (short)2, (short)5, true );
assertEquals(6, columnInfoRecordsAggregate.getNumColumns());
assertEquals(columnInfoRecordsAggregate.getRecordSize(), columnInfoRecordsAggregate.serialize().length); confirmSerializedSize(agg);
columnInfoRecordsAggregate = new ColumnInfoRecordsAggregate(); agg = new ColumnInfoRecordsAggregate();
columnInfoRecordsAggregate.groupColumnRange( (short)3, (short)6, true ); agg.groupColumnRange((short) 3, (short) 6, true);
confirmSerializedSize(agg);
}
assertEquals(columnInfoRecordsAggregate.getRecordSize(), serializedSize()); private static void confirmSerializedSize(RecordBase cirAgg) {
} int estimatedSize = cirAgg.getRecordSize();
byte[] buf = new byte[estimatedSize];
int serializedSize = cirAgg.serialize(0, buf);
assertEquals(estimatedSize, serializedSize);
}
private int serializedSize() private static ColumnInfoRecord createColumn(int firstCol, int lastCol) {
{ ColumnInfoRecord columnInfoRecord = new ColumnInfoRecord();
return columnInfoRecordsAggregate.serialize(0, new byte[columnInfoRecordsAggregate.getRecordSize()]); columnInfoRecord.setFirstColumn((short) firstCol);
} columnInfoRecord.setLastColumn((short) lastCol);
return columnInfoRecord;
private ColumnInfoRecord createColumn( short firstCol, short lastCol ) }
{
ColumnInfoRecord columnInfoRecord = new ColumnInfoRecord( );
columnInfoRecord.setFirstColumn(firstCol);
columnInfoRecord.setLastColumn(lastCol);
return columnInfoRecord;
}
} }

View File

@ -660,7 +660,7 @@ public final class TestBugs extends TestCase {
HSSFSheet sheet = wb.getSheetAt( 0 ); HSSFSheet sheet = wb.getSheetAt( 0 );
int[] breaks = sheet.getRowBreaks(); int[] breaks = sheet.getRowBreaks();
assertNull(breaks); assertEquals(0, breaks.length);
//add 3 row breaks //add 3 row breaks
for (int j = 1; j <= 3; j++) { for (int j = 1; j <= 3; j++) {