ASF Bugzilla – Attachment 4631 Details for
Bug 16557
[PATCH] Support Print Areas and Repeating Rows/Columns
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Diff file for changes
printarea.diff (text/plain), 97.73 KB, created by
Danny Mui
on 2003-01-29 20:13:28 UTC
(
hide
)
Description:
Diff file for changes
Filename:
MIME Type:
Creator:
Danny Mui
Created:
2003-01-29 20:13:28 UTC
Size:
97.73 KB
patch
obsolete
>? src/java/org/apache/poi/hssf/usermodel/HSSFPrintTitles.java >? src/testcases/org/apache/poi/hssf/data/SimpleNamed.xls >? src/testcases/org/apache/poi/hssf/record/formula/TestArea3DPtg.java >Index: src/java/org/apache/poi/hssf/model/Workbook.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/model/Workbook.java,v >retrieving revision 1.24 >diff -u -r1.24 Workbook.java >--- src/java/org/apache/poi/hssf/model/Workbook.java 2 Jan 2003 11:17:57 -0000 1.24 >+++ src/java/org/apache/poi/hssf/model/Workbook.java 29 Jan 2003 17:00:51 -0000 >@@ -136,7 +136,7 @@ > protected ArrayList formats = new ArrayList(); > > protected ArrayList names = new ArrayList(); >- >+ > protected int protpos = 0; // holds the position of the protect record. > protected int bspos = 0; // holds the position of the last bound sheet. > protected int tabpos = 0; // holds the position of the tabid record >@@ -147,6 +147,7 @@ > private int backuppos = 0; // holds the position of the backup record. > private int namepos = 0; // holds the position of last name record > private int supbookpos = 0; // holds the position of sup book >+ private int externsheetpos = 0; //holds the position of the last external sheet representation > private int palettepos = 0; // hold the position of the palette, if applicable > private short maxformatid = -1; // holds the max format id > private boolean uses1904datewindowing = false; // whether 1904 date windowing is being used >@@ -342,8 +343,13 @@ > records.add( bsr ); > retval.boundsheets.add( bsr ); > retval.bspos = records.size() - 1; >- } >+ } >+ //slot the external sheet references here >+ retval.externsheetpos = records.size() -1; > records.add( retval.createCountry() ); >+ >+ retval.namepos = records.size()-1; >+ > retval.sst = (SSTRecord) retval.createSST(); > records.add( retval.sst ); > records.add( retval.createExtendedSST() ); >@@ -494,6 +500,8 @@ > /** > * if we're trying to address one more sheet than we have, go ahead and add it! if we're > * trying to address >1 more than we have throw an exception! >+ * <P> >+ * Since the extern sheets and names should come after bound sheets, advance those pointers too. > */ > > private void checkSheets(int sheetnum) { >@@ -505,6 +513,9 @@ > ( BoundSheetRecord ) createBoundSheet(sheetnum); > > records.add(++bspos, bsr); >+ this.externsheetpos++; >+ this.namepos++; >+ > boundsheets.add(bsr); > fixTabIdRecord(); > } >@@ -1809,6 +1820,23 @@ > return name; > } > >+ /**Generates a NameRecord to represent a built-in region >+ * @return a new NameRecord unless the index is invalid >+ */ >+ public NameRecord createBuiltInName(byte builtInName, int index) >+ { >+ if (index == -1 || index+1 > (int)Short.MAX_VALUE) return null; >+ >+ //for sheet specific stuff, the index is one-based >+ NameRecord name = new NameRecord(builtInName, (short)(index+1)); >+ >+ records.add(++namepos, name); >+ names.add(name); >+ >+ return name; >+ } >+ >+ > /** removes the name > * @param namenum name index > */ >@@ -1822,20 +1850,34 @@ > } > > /** creates a new extern sheet record >+ * <p> >+ * Since external workbook references are not supported, only one >+ * supbookrecord will be maintained through this function. >+ * <p> >+ * Need to slot the extern sheets after the bound sheets > * @return the new extern sheet record > */ > protected ExternSheetRecord createExternSheet(){ >- ExternSheetRecord rec = new ExternSheetRecord(); >- >- records.add(supbookpos + 1 , rec); >- > //We also adds the supBook for internal reference >- SupBookRecord supbook = new SupBookRecord(); >- >- supbook.setNumberOfSheets((short)getNumSheets()); >- //supbook.setFlag(); >- >- records.add(supbookpos + 1 , supbook); >+ SupBookRecord supbook = null; >+ >+ //only do this once >+ if (!(records.get(supbookpos) instanceof SupBookRecord)) >+ { >+ supbook = new SupBookRecord(); >+ supbook.setNumberOfSheets((short)getNumSheets()); >+ //supbook.setFlag(); >+ records.add(bspos + 1 , supbook); >+ this.supbookpos = bspos+1; >+ >+ //names and extern sheets go after sup book records >+ this.externsheetpos = supbookpos+1; >+ this.namepos++; >+ >+ } >+ >+ ExternSheetRecord rec = new ExternSheetRecord(); >+ records.add(++this.externsheetpos , rec); > > return rec; > } >@@ -1949,6 +1991,28 @@ > return null; > } > >+ /**Retrieves the Builtin NameRecord that matches the name and index >+ * There shouldn't be too many names to make the sequential search too slow >+ * @param name byte representation of the builtin name to match >+ * @param sheetIndex zero-based sheet reference >+ * @return null if no builtin NameRecord matches >+ */ >+ public NameRecord getSpecificBuiltinRecord(byte name, int sheetIndex) >+ { >+ Iterator iterator = names.iterator(); >+ while (iterator.hasNext()) { >+ NameRecord record = ( NameRecord ) iterator.next(); >+ >+ //print areas are one based >+ if (record.getBuiltInName() == name && record.getIndexToSheet() == sheetIndex+1) { >+ return record; >+ } >+ } >+ >+ return null; >+ >+ } >+ > public List getRecords() > { > return records; >Index: src/java/org/apache/poi/hssf/record/NameRecord.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/NameRecord.java,v >retrieving revision 1.7 >diff -u -r1.7 NameRecord.java >--- src/java/org/apache/poi/hssf/record/NameRecord.java 27 Dec 2002 10:54:08 -0000 1.7 >+++ src/java/org/apache/poi/hssf/record/NameRecord.java 29 Jan 2003 17:00:51 -0000 >@@ -55,9 +55,12 @@ > > package org.apache.poi.hssf.record; > >+ > import org.apache.poi.util.HexDump; > import org.apache.poi.util.LittleEndian; > import org.apache.poi.util.StringUtil; >+import org.apache.poi.util.POILogFactory; >+import org.apache.poi.util.POILogger; > import java.util.Stack; > import org.apache.poi.hssf.record.formula.Ptg; > import org.apache.poi.hssf.record.formula.Area3DPtg; >@@ -79,6 +82,56 @@ > /** > */ > public final static short sid = 0x18; //Docs says that it is 0x218 >+ >+ /**Included for completeness sake, not tested >+ */ >+ public final static byte BUILTIN_CONSOLIDATE_AREA = (byte)1; >+ >+ /**Included for completeness sake, not tested >+ */ >+ public final static byte BUILTIN_AUTO_OPEN = (byte)2; >+ >+ /**Included for completeness sake, not tested >+ */ >+ public final static byte BUILTIN_AUTO_CLOSE = (byte)3; >+ >+ /**Included for completeness sake, not tested >+ */ >+ public final static byte BUILTIN_DATABASE = (byte)4; >+ >+ /**Included for completeness sake, not tested >+ */ >+ public final static byte BUILTIN_CRITERIA = (byte)5; >+ >+ public final static byte BUILTIN_PRINT_AREA = (byte)6; >+ public final static byte BUILTIN_PRINT_TITLE = (byte)7; >+ >+ /**Included for completeness sake, not tested >+ */ >+ public final static byte BUILTIN_RECORDER = (byte)8; >+ >+ /**Included for completeness sake, not tested >+ */ >+ public final static byte BUILTIN_DATA_FORM = (byte)9; >+ >+ /**Included for completeness sake, not tested >+ */ >+ >+ public final static byte BUILTIN_AUTO_ACTIVATE = (byte)10; >+ >+ /**Included for completeness sake, not tested >+ */ >+ >+ public final static byte BUILTIN_AUTO_DEACTIVATE = (byte)11; >+ >+ /**Included for completeness sake, not tested >+ */ >+ public final static byte BUILTIN_SHEET_TITLE = (byte)12; >+ >+ >+ >+ private static POILogger log = POILogFactory.getLogger(NameRecord.class); >+ > private short field_1_option_flag; > private byte field_2_keyboard_shortcut; > private byte field_3_length_name_text; >@@ -110,6 +163,19 @@ > field_17_status_bar_text = new String(); > } > >+ /**Constructor to create a built-in named region >+ * The sheet indices should be known and protected from intervention. >+ */ >+ public NameRecord(byte builtin, short index) >+ { >+ super(); >+ this.field_12_builtIn_name = builtin; >+ this.setOptionFlag((short)(this.getOptionFlag() | (short)0x20)); >+ this.setNameTextLength((byte)1); >+ this.setIndexToSheet(index); >+ >+ } >+ > /** > * Constructs a Name record and sets its fields appropriately. > * >@@ -246,6 +312,14 @@ > field_17_status_bar_text = text; > } > >+ /** Gets the Built In Name >+ * @return the built in Name >+ */ >+ public byte getBuiltInName() >+ { >+ return this.field_12_builtIn_name; >+ } >+ > /** gets the option flag > * @return option flag > */ >@@ -278,7 +352,9 @@ > * @return index to extern sheet > */ > public short getIndexToSheet(){ >- return field_5_index_to_sheet; >+ //return field_5_index_to_sheet; >+ //field 5 is unused, 6 is the real offset >+ return this.field_6_equals_to_index_to_sheet; > } > > /** gets the custom menu length >@@ -316,11 +392,36 @@ > return field_11_compressed_unicode_flag; > } > >+ /**Creates a human readable name for built in types >+ * @return Unknown if the built-in name cannot be translated >+ */ >+ protected String translateBuiltInName(byte name) >+ { >+ switch (name) >+ { >+ case NameRecord.BUILTIN_AUTO_ACTIVATE : return "Auto_Activate"; >+ case NameRecord.BUILTIN_AUTO_CLOSE : return "Auto_Close"; >+ case NameRecord.BUILTIN_AUTO_DEACTIVATE : return "Auto_Deactivate"; >+ case NameRecord.BUILTIN_AUTO_OPEN : return "Auto_Open"; >+ case NameRecord.BUILTIN_CONSOLIDATE_AREA : return "Consolidate_Area"; >+ case NameRecord.BUILTIN_CRITERIA : return "Criteria"; >+ case NameRecord.BUILTIN_DATABASE : return "Database"; >+ case NameRecord.BUILTIN_DATA_FORM : return "Data_Form"; >+ case NameRecord.BUILTIN_PRINT_AREA : return "Print_Area"; >+ case NameRecord.BUILTIN_PRINT_TITLE : return "Print_Titles"; >+ case NameRecord.BUILTIN_RECORDER : return "Recorder"; >+ case NameRecord.BUILTIN_SHEET_TITLE : return "Sheet_Title"; >+ >+ } >+ >+ return "Unknown"; >+ } >+ > /** gets the name > * @return name > */ > public String getNameText(){ >- return field_12_name_text; >+ return this.isBuiltInName() ? this.translateBuiltInName(this.getBuiltInName()) : field_12_name_text; > } > > /** gets the definition, reference (Formula) >@@ -386,37 +487,31 @@ > data[6 + offset] = getKeyboardShortcut(); > data[7 + offset] = getNameTextLength(); > LittleEndian.putShort(data, 8 + offset, getDefinitionTextLength()); >- LittleEndian.putShort(data, 10 + offset, getIndexToSheet()); >+ //LittleEndian.putShort(data, 10 + offset, getIndexToSheet()); >+ //offset 10 is unused >+ LittleEndian.putShort(data, 10 + offset, (short)0); > LittleEndian.putShort(data, 12 + offset, getIndexToSheet()); >+ > data [14 + offset] = getCustomMenuLength(); > data [15 + offset] = getDescriptionTextLength(); > data [16 + offset] = getHelpTopicLength(); > data [17 + offset] = getStatusBarLength(); > data [18 + offset] = getCompressedUnicodeFlag(); >+ LittleEndian.putShort(data, 2 + offset, (short)( 15 + getTextsLength() + getReferenceSize())); > >- if ( ( field_1_option_flag & (short)0x20 ) != 0 ) { >- LittleEndian.putShort(data, 2 + offset, (short)( 16 + field_13_raw_name_definition.length )); >- >- data [19 + offset] = field_12_builtIn_name; >- System.arraycopy( field_13_raw_name_definition, 0, data, 20 + offset, field_13_raw_name_definition.length ); >- >- return 20 + field_13_raw_name_definition.length; >- } >- else { >- LittleEndian.putShort(data, 2 + offset, (short)( 15 + getTextsLength())); >- >- >+ this.serializeNameReference(data, 19 + (int)this.getNameTextLength()+offset); >+ >+ //no need to put other text into the array and set the name >+ if (this.isBuiltInName()) { >+ data [19 + offset] = this.getBuiltInName(); >+ } >+ else >+ { > StringUtil.putCompressedUnicode(getNameText(), data , 19 + offset); > > int start_of_name_definition = 19 + field_3_length_name_text; >- if (this.field_13_name_definition != null) { >- serializePtgs(data, start_of_name_definition + offset); >- } else { >- System.arraycopy(field_13_raw_name_definition,0,data >- ,start_of_name_definition + offset,field_13_raw_name_definition.length); >- } > >- int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition; >+ int start_of_custom_menu_text = start_of_name_definition + getReferenceSize(); > StringUtil.putCompressedUnicode(getCustomMenuText(), data , start_of_custom_menu_text + offset); > > int start_of_description_text = start_of_custom_menu_text + field_8_length_description_text; >@@ -427,46 +522,115 @@ > > int start_of_status_bar_text = start_of_help_topic_text + field_10_length_status_bar_text; > StringUtil.putCompressedUnicode(getStatusBarText(), data , start_of_status_bar_text + offset); >- >- return getRecordSize(); >- } >+ } >+ >+ return getRecordSize(); > } > >- private void serializePtgs(byte [] data, int offset) { >+ /**Serialize Cell Range References to the array >+ * @return the amount of bytes written >+ */ >+ private int serializePtgs(byte [] data, int offset) { > int pos = offset; > >- for (int k = 0; k < field_13_name_definition.size(); k++) { >- Ptg ptg = ( Ptg ) field_13_name_definition.get(k); >+ for (int k = 0; k < this.getNameDefinition().size(); k++) { >+ Ptg ptg = ( Ptg ) this.getNameDefinition().get(k); > > ptg.writeBytes(data, pos); > pos += ptg.getSize(); > } >+ return pos - offset; > } > >- >+ /**Put the name reference into the byte array >+ * @param data the byte array to place the data of this reference >+ * @param offset the offset to start writing data >+ * @return the number of bytes used to serialize the reference >+ */ >+ private int serializeNameReference(byte[] data, int offset) >+ { >+ >+ if (this.getNameDefinition() != null) { >+ return this.serializePtgs(data, offset); >+ } >+ else >+ { >+ //no formula defined, put the raw definition in >+ if (this.getRawNameDefinitionLength() == 0) { >+ //no forumla, no raw name definition, what's the point of a name record? >+ throw new IllegalArgumentException("No Cell Reference Found (PTG or Raw) for sheet indexed "+this.getIndexToSheet()); >+ } >+ System.arraycopy( this.getRawNameDefinition(), 0, data, 19 + (int)this.getNameTextLength(), this.getRawNameDefinitionLength()); >+ >+ return this.getRawNameDefinitionLength(); >+ } >+ } >+ > /** gets the length of all texts > * @return total length > */ > public int getTextsLength(){ > int result; > >- result = getNameTextLength() + getDefinitionTextLength() + getDescriptionTextLength() + >+ result = getNameTextLength() + getDescriptionTextLength() + > getHelpTopicLength() + getStatusBarLength(); > > > return result; > } > >+ /**@return The byte array representation of the cell range, a null is never returned >+ */ >+ public byte[] getRawNameDefinition() >+ { >+ return this.field_13_raw_name_definition == null ? new byte[0] : this.field_13_raw_name_definition; >+ } >+ >+ /**Convenience method to get the length of the byte array >+ * @return number of bytes used in the raw byte array representation of the cell range >+ */ >+ public int getRawNameDefinitionLength() >+ { >+ return this.getRawNameDefinition().length; >+ } >+ > /** returns the record size > */ > public int getRecordSize(){ > int result; > >- result = 19 + getTextsLength(); >- >+ result = 19 + getTextsLength()+getReferenceSize(); >+ > return result; > } > >+ /**Determines the size of the cell range >+ * @return PtgSize gets precedences if available >+ */ >+ protected int getReferenceSize() >+ { >+ int ptgSize = getPtgSize(); >+ int rawDefinitionSize = this.getRawNameDefinitionLength(); >+ >+ return ptgSize == 0 ? rawDefinitionSize : ptgSize; >+ } >+ >+ /**Counts the number of bytes the field range reference utilizes >+ * @return the size of the data used to reference a cell range >+ */ >+ protected int getPtgSize() >+ { >+ int result = 0; >+ if (getNameDefinition() == null) return result; >+ >+ for (int k = 0; k < this.getNameDefinition().size(); k++) { >+ Ptg ptg = ( Ptg ) this.getNameDefinition().get(k); >+ >+ result += ptg.getSize(); >+ } >+ return result; >+ } >+ > /** gets the extern sheet number > * @return extern sheet index > */ >@@ -485,6 +649,13 @@ > return result; > } > >+ /**Convenience Function to determine if the name is a built-in name >+ */ >+ public boolean isBuiltInName() >+ { >+ return ((this.getOptionFlag() & (short)0x20) != 0); >+ } >+ > /** sets the extern sheet number > * @param externSheetNumber extern sheet number > */ >@@ -559,9 +730,7 @@ > } > > if (ra.hasRange()) { >- ptg = new Area3DPtg(); >- ((Area3DPtg) ptg).setExternSheetIndex(externSheetIndex); >- ((Area3DPtg) ptg).setArea(ref); >+ ptg = new Area3DPtg(ref, externSheetIndex); > this.setDefinitionTextLength((short)ptg.getSize()); > } else { > ptg = new Ref3DPtg(); >@@ -576,7 +745,7 @@ > > /** > * called by the constructor, should set class level fields. Should throw >- * runtime exception for bad/icomplete data. >+ * runtime exception for bad/incomplete data. > * > * @param data raw data > * @param size size of data >@@ -593,37 +762,28 @@ > field_8_length_description_text = data [11 + offset]; > field_9_length_help_topic_text = data [12 + offset]; > field_10_length_status_bar_text = data [13 + offset]; >- > >- if ( ( field_1_option_flag & (short)0x20 ) != 0 ) { >- // DEBUG >- // System.out.println( "Built-in name" ); >+ int start_of_name_definition = 15 + field_3_length_name_text; >+ field_13_name_definition = getParsedExpressionTokens(data, field_4_length_name_definition, >+ offset, start_of_name_definition); >+ >+ if (this.isBuiltInName()) { > > field_11_compressed_unicode_flag = data[ 14 + offset ]; > field_12_builtIn_name = data[ 15 + offset ]; > >- if ( (field_12_builtIn_name & (short)0x07) != 0 ) { >- field_12_name_text = "Print_Titles"; >- >- // DEBUG >- // System.out.println( field_12_name_text ); >+ //no need to store the area, translated when the name is requested >+ //field_12_name_text = "Print_Area"; > >- field_13_raw_name_definition = new byte[ field_4_length_name_definition ]; >- System.arraycopy( data, 16 + offset, field_13_raw_name_definition, 0, field_13_raw_name_definition.length ); >+ field_13_raw_name_definition = new byte[ field_4_length_name_definition ]; >+ System.arraycopy( data, 16 + offset, field_13_raw_name_definition, 0, field_13_raw_name_definition.length ); > >- // DEBUG >- // System.out.println( HexDump.toHex( field_13_raw_name_definition ) ); >- } > } > else { > > field_11_compressed_unicode_flag= data [14 + offset]; > field_12_name_text = new String(data, 15 + offset, > LittleEndian.ubyteToInt(field_3_length_name_text)); >- >- int start_of_name_definition = 15 + field_3_length_name_text; >- field_13_name_definition = getParsedExpressionTokens(data, field_4_length_name_definition, >- offset, start_of_name_definition); > > int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition; > field_14_custom_menu_text = new String(data, start_of_custom_menu_text + offset, >@@ -753,7 +913,7 @@ > .append("\n"); > buffer.append(" .Name (Unicode flag) = ").append( field_11_compressed_unicode_flag ) > .append("\n"); >- buffer.append(" .Name (Unicode text) = ").append( field_12_name_text ) >+ buffer.append(" .Name (Unicode text) = ").append( this.getNameText() ) > .append("\n"); > buffer.append(" .Formula data (RPN token array without size field) = ").append( HexDump.toHex( > ((field_13_raw_name_definition != null) ? field_13_raw_name_definition : new byte[0] ) ) ) >Index: src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java,v >retrieving revision 1.11 >diff -u -r1.11 Area3DPtg.java >--- src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java 20 Oct 2002 06:16:34 -0000 1.11 >+++ src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java 29 Jan 2003 17:00:52 -0000 >@@ -93,16 +93,7 @@ > > public Area3DPtg( String arearef, short externIdx ) > { >- AreaReference ar = new AreaReference( arearef ); >- >- setFirstRow( (short) ar.getCells()[0].getRow() ); >- setFirstColumn( (short) ar.getCells()[0].getCol() ); >- setLastRow( (short) ar.getCells()[1].getRow() ); >- setLastColumn( (short) ar.getCells()[1].getCol() ); >- setFirstColRelative( !ar.getCells()[0].isColAbsolute() ); >- setLastColRelative( !ar.getCells()[1].isColAbsolute() ); >- setFirstRowRelative( !ar.getCells()[0].isRowAbsolute() ); >- setLastRowRelative( !ar.getCells()[1].isRowAbsolute() ); >+ setArea(arearef); > setExternSheetIndex( externIdx ); > > } >@@ -287,16 +278,16 @@ > > public void setArea( String ref ) > { >- RangeAddress ra = new RangeAddress( ref ); >- >- String from = ra.getFromCell(); >- String to = ra.getToCell(); >- >- setFirstColumn( (short) ( ra.getXPosition( from ) - 1 ) ); >- setFirstRow( (short) ( ra.getYPosition( from ) - 1 ) ); >- setLastColumn( (short) ( ra.getXPosition( to ) - 1 ) ); >- setLastRow( (short) ( ra.getYPosition( to ) - 1 ) ); >+ AreaReference ar = new AreaReference( ref ); > >+ setFirstRow( (short) ar.getCells()[0].getRow() ); >+ setFirstColumn( (short) ar.getCells()[0].getCol() ); >+ setLastRow( (short) ar.getCells()[1].getRow() ); >+ setLastColumn( (short) ar.getCells()[1].getCol() ); >+ setFirstColRelative( !ar.getCells()[0].isColAbsolute() ); >+ setLastColRelative( !ar.getCells()[1].isColAbsolute() ); >+ setFirstRowRelative( !ar.getCells()[0].isRowAbsolute() ); >+ setLastRowRelative( !ar.getCells()[1].isRowAbsolute() ); > } > > public String toFormulaString( SheetReferences refs ) >@@ -359,3 +350,4 @@ > > > } >+ >Index: src/java/org/apache/poi/hssf/usermodel/HSSFName.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFName.java,v >retrieving revision 1.6 >diff -u -r1.6 HSSFName.java >--- src/java/org/apache/poi/hssf/usermodel/HSSFName.java 27 Dec 2002 10:51:33 -0000 1.6 >+++ src/java/org/apache/poi/hssf/usermodel/HSSFName.java 29 Jan 2003 17:00:52 -0000 >@@ -66,10 +66,10 @@ > */ > > public class HSSFName { >- private Workbook book; >- private NameRecord name; >+ protected Workbook book; >+ protected NameRecord name; > >- /** Creates new HSSFName - called by HSSFWorkbook to create a sheet from >+ /** Creates new HSSFName - called by HSSFWorkbook to create a Name from > * scratch. > * > * @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createName() >@@ -106,6 +106,24 @@ > return result; > } > >+ /** >+ * Retrieves the index that this name refers (one-based) >+ * @return int >+ */ >+ public int getSheetIndex() >+ { >+ return (int)name.getIndexToSheet(); >+ } >+ >+ /** >+ * Retrieves the built-in name >+ * @return byte >+ */ >+ public byte getBuiltInName() >+ { >+ return name.getBuiltInName(); >+ } >+ > /** > * sets the name of the named range > * @param nameName named range name to set >@@ -133,6 +151,7 @@ > > /** > * sets the sheet name which this named range referenced to >+ * Names associated to specific sheets are assigned in the built-in names > * @param sheetName the sheet name of the reference > */ > >@@ -148,6 +167,10 @@ > > /** > * sets the reference of this named range >+ * <p> >+ * Excel Expects a Range, even for single cell references, >+ * <p> >+ * i.e. $A should be $A:$A > * @param ref the reference to set > */ > >@@ -161,11 +184,8 @@ > setSheetName(sheetName); > } > >- if (ra.getFromCell().equals(ra.getToCell()) == false) { >- name.setAreaReference(ra.getFromCell() + ":" + ra.getToCell()); >- } else { >- name.setAreaReference(ra.getFromCell()); >- } >+ >+ name.setAreaReference(ref); > > } > >Index: src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v >retrieving revision 1.19 >diff -u -r1.19 HSSFWorkbook.java >--- src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java 2 Jan 2003 11:17:57 -0000 1.19 >+++ src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java 29 Jan 2003 17:00:53 -0000 >@@ -137,7 +137,7 @@ > private POIFSFileSystem poifs; > > private static POILogger log = POILogFactory.getLogger(HSSFWorkbook.class); >- >+ > /** > * Creates new HSSFWorkbook from scratch (start here!) > * >@@ -206,7 +206,27 @@ > } > > for (int i = 0 ; i < workbook.getNumNames() ; ++i){ >- HSSFName name = new HSSFName(workbook, workbook.getNameRecord(i)); >+ NameRecord nameRecord = workbook.getNameRecord(i); >+ //if more types we should implement a factory for this in the >+ //org.apache.poi.hssf.usermodel package if it fits in there >+ //generate the correct class for storage because they are serialized/presented >+ //differently but are inherently names >+ >+ HSSFName name = null; >+ >+ if (!nameRecord.isBuiltInName()) >+ name = new HSSFName(workbook, nameRecord); >+ else { >+ switch (nameRecord.getBuiltInName()) >+ { >+ case NameRecord.BUILTIN_PRINT_TITLE: >+ name = new HSSFPrintTitles(workbook, nameRecord); >+ break; >+ default : >+ name = new HSSFName(workbook, nameRecord); >+ } >+ } >+ > names.add(name); > } > } >@@ -235,6 +255,20 @@ > } > > /** >+ * >+ * @param sheetIndex >+ * @param reference >+ */ >+ public void setPrintArea(int sheetIndex, String reference) >+ { >+ HSSFName retrievedName = this.getBuiltInName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex); >+ if (retrievedName == null) >+ retrievedName = this.createBuiltinName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex); >+ >+ retrievedName.setReference(reference); >+ } >+ >+ /** > * used internally to set the workbook properties. > */ > >@@ -649,6 +683,7 @@ > * @return named range high level > */ > public HSSFName getNameAt(int index){ >+ if (index == -1) throw new IllegalArgumentException("Invalid Name Index"); > HSSFName result = (HSSFName) names.get(index); > > return result; >@@ -665,6 +700,61 @@ > } > > >+ >+ /** >+ * Method getBuiltInName. >+ * @param name >+ * @param sheetIndex Zero-based index >+ * @return HSSFName >+ */ >+ protected HSSFName getBuiltInName(byte name, int sheetIndex) >+ { >+ Iterator iterator = this.names.iterator(); >+ >+ while (iterator.hasNext()) >+ { >+ HSSFName retrievedName = (HSSFName)iterator.next(); >+ if (retrievedName.getBuiltInName() == name && retrievedName.getSheetIndex()==sheetIndex+1) >+ return retrievedName; >+ >+ } >+ >+ return null; >+ } >+ >+ /** Gets the PrintArea HSSFName object at the specified sheet index >+ * @param sheetIndex zero-based sheet index >+ * @return Null if no print area is defined >+ */ >+ public String getPrintArea(int sheetIndex) >+ { >+ HSSFName retrievedName = >+ this.getBuiltInName(NameRecord.BUILTIN_PRINT_AREA, sheetIndex); >+ >+ if (retrievedName == null) return null; >+ >+ return retrievedName.getReference(); >+ } >+ >+ >+ /** >+ * <p> >+ * Set the repeating rows or columns when printing >+ * @param sheetIndex zero-based sheet index >+ * @return Null if no print titles is defined for the sheet >+ */ >+ public HSSFPrintTitles getPrintTitles(int sheetIndex) >+ { >+ HSSFName name = this.getBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, sheetIndex); >+ >+ if (name != null && !(name instanceof HSSFPrintTitles)) >+ { >+ //for read support >+ } >+ >+ return (HSSFPrintTitles)name; >+ } >+ > /** creates a new named range and add it to the model > * @return named range high level > */ >@@ -677,6 +767,43 @@ > > return newName; > } >+ >+ /**Create a HSSFName object for the specified built-in name >+ * @param name the byte representation of the built-in name to generate >+ * @param index the zero based index for the sheet >+ * @return new Name object if the printArea does not already exist >+ */ >+ protected HSSFName createBuiltinName(byte name, int index) >+ { >+ NameRecord nameRecord = workbook.createBuiltInName(name, index); >+ >+ HSSFName newName = new HSSFName(workbook, nameRecord); >+ names.add(newName); >+ >+ return newName; >+ >+ } >+ >+ /**Create PrintTitles for the specified sheet. >+ * Global PrintTitles do not make sense so a sheet is required. >+ * @param index the zero based index for the sheet >+ * @return new Name object if the PrintTitle does not already exist >+ */ >+ public HSSFPrintTitles createPrintTitles(int index) >+ { >+ NameRecord titleRecord = workbook.getSpecificBuiltinRecord(NameRecord.BUILTIN_PRINT_TITLE, index); >+ >+ if (titleRecord == null) >+ titleRecord = workbook.createBuiltInName(NameRecord.BUILTIN_PRINT_TITLE, index); >+ >+ HSSFPrintTitles printTitles = new HSSFPrintTitles(workbook, titleRecord); >+ >+ names.add(printTitles); >+ >+ return printTitles; >+ >+ } >+ > > /** gets the named range index by his name > * @param name named range name >@@ -811,5 +938,5 @@ > UnknownRecord r = new UnknownRecord((short)0x00EB,(short)0x005a, data); > workbook.getRecords().add(loc, r); > } >- >+ > } >Index: src/java/org/apache/poi/hssf/util/AreaReference.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/util/AreaReference.java,v >retrieving revision 1.2 >diff -u -r1.2 AreaReference.java >--- src/java/org/apache/poi/hssf/util/AreaReference.java 5 May 2002 16:55:41 -0000 1.2 >+++ src/java/org/apache/poi/hssf/util/AreaReference.java 29 Jan 2003 17:00:53 -0000 >@@ -56,53 +56,226 @@ > > public class AreaReference { > >+ /** >+ * Internal Representation used to represent the Maximum Column when dealing >+ * with ranges defining only rows >+ */ >+ public static final String MAXIMUM_COLUMN = "IV"; >+ >+ >+ /** >+ * Internal Representation used to represent the Maximum Column when dealing >+ * with ranges defining only columns >+ */ >+ >+ public static final String MAXIMUM_CELL_REFERENCE_ROW = "65536"; > > private CellReference [] cells; > private int dim; > >- /** Create an area ref from a string representation >- */ >- public AreaReference(String reference) { >- String[] refs = seperateAreaRefs(reference); >- dim = refs.length; >- cells = new CellReference[dim]; >- for (int i=0;i<dim;i++) { >- cells[i]=new CellReference(refs[i]); >- } >- } >- //not sure if we need to be flexible here! >- /** return the dimensions of this area >- **/ >- public int getDim() { >- return dim; >- } >- /** return the cell references that define this area */ >- public CellReference[] getCells() { >- return cells; >- } >- >- public String toString() { >- StringBuffer retval = new StringBuffer(); >- for (int i=0;i<dim;i++){ >- retval.append(':'); >- retval.append(cells[i].toString()); >- } >- retval.deleteCharAt(0); >- return retval.toString(); >- } >- >- /** >- * seperates Area refs in two parts and returns them as seperate elements in a >- * String array >- */ >- private String[] seperateAreaRefs(String reference) { >- String retval[] = new String[2]; >- int length = reference.length(); >- >- int loc = reference.indexOf(':',0); >- >- retval[0] = reference.substring(0,loc); >- retval[1] = reference.substring(loc+1); >- return retval; >- } >+ >+ /** Create an area ref from a string representation >+ */ >+ public AreaReference(String reference) { >+ reference = processRowColOnlyRefs(reference); >+ String[] refs = seperateAreaRefs(reference); >+ dim = refs.length; >+ cells = new CellReference[dim]; >+ for (int i=0;i<dim;i++) { >+ cells[i]=new CellReference(refs[i]); >+ } >+ } >+ //not sure if we need to be flexible here! >+ /** return the dimensions of this area >+ **/ >+ public int getDim() { >+ return dim; >+ } >+ /** return the cell references that define this area */ >+ public CellReference[] getCells() { >+ return cells; >+ } >+ >+ public String toString() { >+ StringBuffer retval = new StringBuffer(); >+ for (int i=0;i<dim;i++){ >+ retval.append(':'); >+ retval.append(cells[i].toString()); >+ } >+ retval.deleteCharAt(0); >+ return retval.toString(); >+ } >+ >+ /** >+ * seperates Area refs in two parts and returns them as seperate elements in a >+ * String array >+ */ >+ private String[] seperateAreaRefs(String reference) { >+ String retval[] = new String[2]; >+ int length = reference.length(); >+ >+ int loc = reference.indexOf(':',0); >+ >+ retval[0] = reference.substring(0,loc); >+ retval[1] = reference.substring(loc+1); >+ return retval; >+ } >+ >+ /**Processes (absolute and relative) Row Only or Column Only references so the formula packages can understand them >+ * <p> >+ * eg. $1:$2 => $A$1:$IV$2 >+ * <p> >+ * eg. $C:$C => $C$1:$C$65535 >+ * <p> >+ * <b>Note : </b>One absolute reference converts the whole to an absolute reference >+ * @param reference the reference to check >+ * @param isRowCheck True indicates a row check, false indicates a column check >+ * @return Processed internal representation of the reference if it is a row-only >+ * reference, otherwise the same is returned >+ * >+ */ >+ protected String processRowColOnlyRefs(final String reference) >+ { >+ >+ boolean isRowCheck = false; >+ boolean isRowOnly = isRowOnlyReference(reference); >+ boolean isColOnly = isColOnlyReference(reference); >+ boolean isAbsolute = (reference.indexOf("$") > -1); >+ >+ //not a row only or col only reference >+ if (!isRowOnly && !isColOnly) return reference; >+ >+ isRowCheck = isRowOnly; >+ >+ String[] parsedRefs = new String[0]; >+ StringBuffer returnValue = new StringBuffer(); >+ String sheet = null; >+ int sheetIndex = reference.indexOf('!'); >+ >+ if (sheetIndex > 0) { >+ sheet = reference.substring(0, sheetIndex); >+ returnValue.append(sheet).append("!"); >+ } >+ >+ parsedRefs = seperateAreaRefs((sheetIndex > 0) ? reference.substring(sheetIndex+1) : reference); >+ >+ if (parsedRefs.length == 2){ >+ for (int i = 0; i < parsedRefs.length; i++) >+ { >+ String cellRef = removeAbsolutes(parsedRefs[i]); >+ boolean isFirst = (i == 0); >+ >+ if (!isFirst) returnValue.append(":"); >+ >+ if (isRowCheck) { >+ returnValue.append(processRowReference(cellRef, isFirst, isAbsolute)); >+ } else { >+ returnValue.append(processColReference(cellRef, isFirst, isAbsolute)); >+ } >+ } >+ } >+ >+ return returnValue.toString(); >+ } >+ >+ /**Determines if the cell reference points to a row only >+ * @return true if the reference (absolute or not) refers to a row only >+ */ >+ public static boolean isRowOnlyReference(final String reference) >+ { >+ int start = reference.indexOf("!") + 1; >+ char[] chars = reference.toCharArray(); >+ int loc = start; >+ if (chars[loc]=='$') loc++; >+ for (; loc < chars.length; loc++) { >+ if (Character.isDigit(chars[loc]) || chars[loc] == '$' || chars[loc] == ':') { >+ continue; >+ } else { >+ //not a number or absolute reference >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ /**Determines if the cell reference points to a Column only >+ * @return true if the reference (absolute or not) refers to a Column only >+ */ >+ public static boolean isColOnlyReference(final String reference) >+ { >+ int start = reference.indexOf("!") + 1; >+ char[] chars = reference.toCharArray(); >+ int loc = start; >+ if (chars[loc]=='$') loc++; >+ for (; loc < chars.length; loc++) { >+ if (Character.isLetter(chars[loc]) || chars[loc] == '$' || chars[loc] == ':') { >+ continue; >+ } else { >+ //not a number or absolute reference >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ >+ /** Removes the absolute references for processing >+ * @return reference with the "$" characters >+ */ >+ public static String removeAbsolutes(String reference) >+ { >+ StringBuffer sb = new StringBuffer(reference); >+ >+ int index = 0; >+ >+ while ( index < sb.length()) >+ { >+ char ch = sb.charAt(index); >+ if (ch == '$') { >+ sb.deleteCharAt(index); >+ } else { >+ index++; >+ } >+ } >+ >+ return sb.toString(); >+ } >+ >+ /**Converts the row reference to a proper internal form >+ * <p> >+ * For a row only reference, the first reference should be the first column >+ * and the second reference, the maximum column in the first row. >+ * <p> >+ * eg. $1:$2 => $A$1:$IV$2 >+ * @param rowReference number only row reference >+ * @param isFirst if the cell reference is the first in the range >+ * @param isAbsolute return an absolute reference >+ * @return reference >+ */ >+ protected String processRowReference(String rowReference, boolean isFirst, boolean isAbsolute) >+ { >+ String absolute = (isAbsolute) ? "$" : ""; >+ >+ if (isFirst) return absolute+"A"+absolute+rowReference; >+ else return absolute+AreaReference.MAXIMUM_COLUMN+absolute+rowReference; >+ } >+ >+ /**Converts the col reference to a proper internal form >+ * <p> >+ * For a col only reference, the first reference should be the column, first row >+ * and the second reference, the column, maximum row >+ * <p> >+ * eg. $A:$A => $A$1:$A$65535 >+ * @param rowReference number only row reference >+ * @param isFirst if the cell reference is the first in the range >+ * @param isAbsolute return an absolute reference >+ * @return an absolute reference >+ */ >+ protected String processColReference(String colReference, boolean isFirst, boolean isAbsolute) >+ { >+ String absolute = (isAbsolute) ? "$" : ""; >+ >+ if (isFirst) return absolute+colReference+absolute+"1"; >+ else return absolute+colReference+absolute+AreaReference.MAXIMUM_CELL_REFERENCE_ROW; >+ } > } >Index: src/java/org/apache/poi/hssf/util/RangeAddress.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/java/org/apache/poi/hssf/util/RangeAddress.java,v >retrieving revision 1.2 >diff -u -r1.2 RangeAddress.java >--- src/java/org/apache/poi/hssf/util/RangeAddress.java 29 Apr 2002 01:25:28 -0000 1.2 >+++ src/java/org/apache/poi/hssf/util/RangeAddress.java 29 Jan 2003 17:00:53 -0000 >@@ -1,394 +1,395 @@ >-package org.apache.poi.hssf.util; >- >-/* ==================================================================== >- * The Apache Software License, Version 1.1 >- * >- * Copyright (c) 2002 The Apache Software Foundation. All rights >- * reserved. >- * >- * Redistribution and use in source and binary forms, with or without >- * modification, are permitted provided that the following conditions >- * are met: >- * >- * 1. Redistributions of source code must retain the above copyright >- * notice, this list of conditions and the following disclaimer. >- * >- * 2. Redistributions in binary form must reproduce the above copyright >- * notice, this list of conditions and the following disclaimer in >- * the documentation and/or other materials provided with the >- * distribution. >- * >- * 3. The end-user documentation included with the redistribution, >- * if any, must include the following acknowledgment: >- * "This product includes software developed by the >- * Apache Software Foundation (http://www.apache.org/)." >- * Alternately, this acknowledgment may appear in the software itself, >- * if and wherever such third-party acknowledgments normally appear. >- * >- * 4. The names "Apache" and "Apache Software Foundation" and >- * "Apache POI" must not be used to endorse or promote products >- * derived from this software without prior written permission. For >- * written permission, please contact apache@apache.org. >- * >- * 5. Products derived from this software may not be called "Apache", >- * "Apache POI", nor may "Apache" appear in their name, without >- * prior written permission of the Apache Software Foundation. >- * >- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED >- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >- * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR >- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF >- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND >- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, >- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT >- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >- * SUCH DAMAGE. >- * ==================================================================== >- * >- * This software consists of voluntary contributions made by many >- * individuals on behalf of the Apache Software Foundation. For more >- * information on the Apache Software Foundation, please see >- * <http://www.apache.org/>. >- */ >- >- >-/** >- * Title: Range Address <P> >- * Description: provides connectivity utilities for ranges<P> >- * >- * >- * REFERENCE: <P> >- * @author IgOr KaTz && EuGeNe BuMaGiN (Tal Moshaiov) (VistaPortal LDT.) >- * @version 1.0 >- */ >- >-public class RangeAddress { >- final static int WRONG_POS = -1; >- final static int MAX_HEIGHT = 66666; >- final static char SO_FORMNAME_ENCLOSURE = '\''; >- String m_sheetName; >- String m_cellFrom; >- String m_cellTo; >- >- public RangeAddress (String _url) { >- init (_url); >- } >- >- public RangeAddress (int _startCol, int _startRow, int _endCol, int _endRow) { >- init (numTo26Sys (_startCol) + _startRow + ":" >- + numTo26Sys (_endCol) + _endRow); >- } >- >- public String getAddress (){ >- String result = ""; >- if(m_sheetName != null) >- result += m_sheetName; >- if(m_cellFrom != null){ >- result += m_cellFrom; >- if(m_cellTo != null) >- result += ":" + m_cellTo; >- } >- return result; >- } >- >- public String getSheetName (){ >- return m_sheetName; >- } >- >- public String getRange (){ >- String result = ""; >- if(m_cellFrom != null){ >- result += m_cellFrom; >- if(m_cellTo != null) >- result += ":" + m_cellTo; >- } >- return result; >- } >- >- public boolean isCellOk (String _cell){ >- if (_cell != null){ >- if ( (getYPosition (_cell) != WRONG_POS) && >- (getXPosition (_cell) != WRONG_POS) ) >- return true; >- else >- return false; >- } else >- return false; >- } >- >- public boolean isSheetNameOk (){ >- return isSheetNameOk (m_sheetName); >- } >- >- private static boolean intern_isSheetNameOk (String _sheetName, boolean _canBeWaitSpace){ >- for (int i = 0 ; i < _sheetName.length (); i++){ >- char ch = _sheetName.charAt (i); >- if (! (Character.isLetterOrDigit (ch) || (ch == '_')|| >- _canBeWaitSpace&&(ch == ' '))){ >- return false; >- } >- } >- return true; >- } >- >- public static boolean isSheetNameOk (String _sheetName){ >- boolean res = false; >- if ( ( _sheetName != null) && !_sheetName.equals ("")){ >- res = intern_isSheetNameOk (_sheetName,true); >- }else >- res = true; >- return res; >- } >- >- >- public String getFromCell (){ >- return m_cellFrom; >- } >- >- public String getToCell (){ >- return m_cellTo; >- } >- >- public int getWidth (){ >- if(m_cellFrom != null && m_cellTo != null){ >- int toX = getXPosition (m_cellTo); >- int fromX = getXPosition (m_cellFrom); >- if ((toX == WRONG_POS) || (fromX == WRONG_POS)){ >- return 0; >- }else >- return toX - fromX + 1; >- } >- return 0; >- } >- >- public int getHeight (){ >- if(m_cellFrom != null && m_cellTo != null){ >- int toY = getYPosition (m_cellTo); >- int fromY = getYPosition (m_cellFrom); >- if ((toY == WRONG_POS) || (fromY == WRONG_POS)){ >- return 0; >- }else >- return toY - fromY + 1; >- } >- return 0; >- } >- >- public void setSize (int _width, int _height){ >- if(m_cellFrom == null) >- m_cellFrom = "a1"; >- int tlX, tlY, rbX, rbY; >- tlX = getXPosition (m_cellFrom); >- tlY = getYPosition (m_cellFrom); >- m_cellTo = numTo26Sys (tlX + _width - 1); >- m_cellTo += String.valueOf (tlY + _height - 1); >- } >- >- public boolean hasSheetName (){ >- if(m_sheetName == null) >- return false; >- return true; >- } >- >- public boolean hasRange (){ >- if(m_cellFrom == null || m_cellTo == null) >- return false; >- return true; >- } >- >- public boolean hasCell (){ >- if(m_cellFrom == null) >- return false; >- return true; >- } >- >- private void init (String _url){ >- >- _url = removeString(_url, "$"); >- _url = removeString(_url, "'"); >- >- String[] urls = parseURL (_url); >- m_sheetName = urls[0]; >- m_cellFrom = urls[1]; >- m_cellTo = urls[2]; >- >- //What if range is one celled ? >- if (m_cellTo == null){ >- m_cellTo = m_cellFrom; >- } >- >- //Removing noneeds characters >- m_cellTo = removeString(m_cellTo,"."); >- >- >- } >- >- private String[] parseURL (String _url){ >- String[] result = new String[3]; >- int index = _url.indexOf(':'); >- if (index >= 0) { >- String fromStr = _url.substring(0, index); >- String toStr = _url.substring(index+1); >- index = fromStr.indexOf('.'); >- if (index >= 0) { >- result[0] = fromStr.substring(0, index); >- result[1] = fromStr.substring(index+1); >- } else { >- result[1] = fromStr; >- } >- index = toStr.indexOf('.'); >- if (index >= 0) { >- result[2] = toStr.substring(index+1); >- } else { >- result[2] = toStr; >- } >- } else { >- index = _url.indexOf('.'); >- if (index >= 0) { >- result[0] = _url.substring(0, index); >- result[1] = _url.substring(index+1); >- } else { >- result[1] = _url; >- } >- } >- return result; >- } >- >- public int getYPosition (String _subrange){ >- int result = WRONG_POS; >- _subrange = _subrange.trim (); >- if (_subrange.length () != 0){ >- String digitstr = getDigitPart (_subrange); >- try { >- result = Integer.parseInt (digitstr); >- if (result > MAX_HEIGHT){ >- result = WRONG_POS; >- } >- } >- catch (Exception ex) { >- >- result = WRONG_POS; >- } >- } >- return result; >- } >- >- private static boolean isLetter (String _str){ >- boolean res = true; >- if ( !_str.equals ("") ){ >- for (int i = 0 ; i < _str.length (); i++){ >- char ch = _str.charAt (i); >- if (! Character.isLetter (ch)){ >- res = false; >- break; >- } >- } >- }else >- res = false; >- return res; >- } >- >- public int getXPosition (String _subrange){ >- int result = WRONG_POS; >- String tmp = filter$ (_subrange); >- tmp = this.getCharPart (_subrange); >- // we will process only 2 letters ranges >- if (isLetter (tmp) && ((tmp.length () == 2)|| (tmp.length () == 1) )){ >- result = get26Sys (tmp); >- } >- return result; >- } >- >- public String getDigitPart (String _value){ >- String result = ""; >- int digitpos = getFirstDigitPosition (_value); >- if(digitpos >= 0){ >- result = _value.substring (digitpos); >- } >- return result; >- } >- >- public String getCharPart (String _value){ >- String result = ""; >- int digitpos = getFirstDigitPosition (_value); >- if(digitpos >= 0){ >- result = _value.substring (0, digitpos); >- } >- return result; >- } >- >- private String filter$ (String _range){ >- String res = ""; >- for (int i = 0 ; i < _range.length () ; i++){ >- char ch = _range.charAt (i); >- if ( ch != '$' ){ >- res = res + ch; >- } >- } >- return res; >- } >- >- private int getFirstDigitPosition (String _value){ >- int result = WRONG_POS; >- if(_value != null && _value.trim ().length () == 0){ >- return result; >- } >- _value = _value.trim (); >- int length = _value.length (); >- for(int i = 0; i < length; i++){ >- if(Character.isDigit (_value.charAt (i))){ >- result = i; >- break; >- } >- } >- return result; >- } >- >- public int get26Sys (String _s){ >- int sum = 0; >- int multiplier = 1; >- if (_s != "") { >- for (int i = _s.length ()-1 ; i >= 0 ; i--){ >- char ch = _s.charAt (i); >- int val = Character.getNumericValue (ch) - Character.getNumericValue ('A')+1; >- sum = sum + val * multiplier; >- multiplier = multiplier * 26; >- } >- return sum; >- } >- return WRONG_POS; >- } >- >- public String numTo26Sys (int _num){ >- int sum = 0; >- int reminder; >- String s =""; >- do{ >- _num --; >- reminder = _num % 26; >- int val = 65 + reminder; >- _num = _num / 26; >- s = (char)val + s; // reverce >- }while(_num > 0); >- return s; >- } >- >- public String replaceString(String _source , String _oldPattern, >- String _newPattern){ >- StringBuffer res = new StringBuffer(_source); >- int pos = -1; >- >- while ((pos = res.toString().indexOf(_oldPattern, pos)) > -1){ >- res.replace(pos, pos + _oldPattern.length(), _newPattern); >- } >- >- return res.toString(); >- } >- >- public String removeString(String _source, String _match){ >- return replaceString(_source, _match, ""); >- } >- >-} >+package org.apache.poi.hssf.util; >+ >+/* ==================================================================== >+ * The Apache Software License, Version 1.1 >+ * >+ * Copyright (c) 2002 The Apache Software Foundation. All rights >+ * reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in >+ * the documentation and/or other materials provided with the >+ * distribution. >+ * >+ * 3. The end-user documentation included with the redistribution, >+ * if any, must include the following acknowledgment: >+ * "This product includes software developed by the >+ * Apache Software Foundation (http://www.apache.org/)." >+ * Alternately, this acknowledgment may appear in the software itself, >+ * if and wherever such third-party acknowledgments normally appear. >+ * >+ * 4. The names "Apache" and "Apache Software Foundation" and >+ * "Apache POI" must not be used to endorse or promote products >+ * derived from this software without prior written permission. For >+ * written permission, please contact apache@apache.org. >+ * >+ * 5. Products derived from this software may not be called "Apache", >+ * "Apache POI", nor may "Apache" appear in their name, without >+ * prior written permission of the Apache Software Foundation. >+ * >+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED >+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR >+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF >+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND >+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, >+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT >+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ * SUCH DAMAGE. >+ * ==================================================================== >+ * >+ * This software consists of voluntary contributions made by many >+ * individuals on behalf of the Apache Software Foundation. For more >+ * information on the Apache Software Foundation, please see >+ * <http://www.apache.org/>. >+ */ >+ >+ >+/** >+ * Title: Range Address <P> >+ * Description: provides connectivity utilities for ranges<P> >+ * >+ * >+ * REFERENCE: <P> >+ * @author IgOr KaTz && EuGeNe BuMaGiN (Tal Moshaiov) (VistaPortal LDT.) >+ * @version 1.0 >+ */ >+ >+public class RangeAddress { >+ final static int WRONG_POS = -1; >+ final static int MAX_HEIGHT = 66666; >+ final static char SO_FORMNAME_ENCLOSURE = '\''; >+ String m_sheetName; >+ String m_cellFrom; >+ String m_cellTo; >+ >+ public RangeAddress (String _url) { >+ init (_url); >+ } >+ >+ public RangeAddress (int _startCol, int _startRow, int _endCol, int _endRow) { >+ init (numTo26Sys (_startCol) + _startRow + ":" >+ + numTo26Sys (_endCol) + _endRow); >+ } >+ >+ public String getAddress (){ >+ String result = ""; >+ if(m_sheetName != null) >+ result += m_sheetName; >+ if(m_cellFrom != null){ >+ result += m_cellFrom; >+ if(m_cellTo != null) >+ result += ":" + m_cellTo; >+ } >+ return result; >+ } >+ >+ public String getSheetName (){ >+ return m_sheetName; >+ } >+ >+ public String getRange (){ >+ String result = ""; >+ if(m_cellFrom != null){ >+ result += m_cellFrom; >+ if(m_cellTo != null) >+ result += ":" + m_cellTo; >+ } >+ return result; >+ } >+ >+ public boolean isCellOk (String _cell){ >+ if (_cell != null){ >+ if ( (getYPosition (_cell) != WRONG_POS) && >+ (getXPosition (_cell) != WRONG_POS) ) >+ return true; >+ else >+ return false; >+ } else >+ return false; >+ } >+ >+ public boolean isSheetNameOk (){ >+ return isSheetNameOk (m_sheetName); >+ } >+ >+ private static boolean intern_isSheetNameOk (String _sheetName, boolean _canBeWaitSpace){ >+ for (int i = 0 ; i < _sheetName.length (); i++){ >+ char ch = _sheetName.charAt (i); >+ if (! (Character.isLetterOrDigit (ch) || (ch == '_')|| >+ _canBeWaitSpace&&(ch == ' '))){ >+ return false; >+ } >+ } >+ return true; >+ } >+ >+ public static boolean isSheetNameOk (String _sheetName){ >+ boolean res = false; >+ if ( ( _sheetName != null) && !_sheetName.equals ("")){ >+ res = intern_isSheetNameOk (_sheetName,true); >+ }else >+ res = true; >+ return res; >+ } >+ >+ >+ public String getFromCell (){ >+ return m_cellFrom; >+ } >+ >+ public String getToCell (){ >+ return m_cellTo; >+ } >+ >+ public int getWidth (){ >+ if(m_cellFrom != null && m_cellTo != null){ >+ int toX = getXPosition (m_cellTo); >+ int fromX = getXPosition (m_cellFrom); >+ if ((toX == WRONG_POS) || (fromX == WRONG_POS)){ >+ return 0; >+ }else >+ return toX - fromX + 1; >+ } >+ return 0; >+ } >+ >+ public int getHeight (){ >+ if(m_cellFrom != null && m_cellTo != null){ >+ int toY = getYPosition (m_cellTo); >+ int fromY = getYPosition (m_cellFrom); >+ if ((toY == WRONG_POS) || (fromY == WRONG_POS)){ >+ return 0; >+ }else >+ return toY - fromY + 1; >+ } >+ return 0; >+ } >+ >+ public void setSize (int _width, int _height){ >+ if(m_cellFrom == null) >+ m_cellFrom = "a1"; >+ int tlX, tlY, rbX, rbY; >+ tlX = getXPosition (m_cellFrom); >+ tlY = getYPosition (m_cellFrom); >+ m_cellTo = numTo26Sys (tlX + _width - 1); >+ m_cellTo += String.valueOf (tlY + _height - 1); >+ } >+ >+ public boolean hasSheetName (){ >+ if(m_sheetName == null) >+ return false; >+ return true; >+ } >+ >+ public boolean hasRange (){ >+ if(m_cellFrom == null || m_cellTo == null) >+ return false; >+ return true; >+ } >+ >+ public boolean hasCell (){ >+ if(m_cellFrom == null) >+ return false; >+ return true; >+ } >+ >+ private void init (String _url){ >+ >+ _url = removeString(_url, "$"); >+ _url = removeString(_url, "'"); >+ >+ String[] urls = parseURL (_url); >+ m_sheetName = urls[0]; >+ m_cellFrom = urls[1]; >+ m_cellTo = urls[2]; >+ >+ //What if range is one celled ? >+ if (m_cellTo == null){ >+ m_cellTo = m_cellFrom; >+ } >+ >+ //Removing noneeds characters >+ m_cellTo = removeString(m_cellTo,"."); >+ >+ >+ } >+ >+ private String[] parseURL (String _url){ >+ String[] result = new String[3]; >+ int index = _url.indexOf(':'); >+ if (index >= 0) { >+ String fromStr = _url.substring(0, index); >+ String toStr = _url.substring(index+1); >+ index = fromStr.indexOf('!'); >+ if (index >= 0) { >+ result[0] = fromStr.substring(0, index); >+ result[1] = fromStr.substring(index+1); >+ } else { >+ result[1] = fromStr; >+ } >+ index = toStr.indexOf('!'); >+ if (index >= 0) { >+ result[2] = toStr.substring(index+1); >+ } else { >+ result[2] = toStr; >+ } >+ } else { >+ index = _url.indexOf('!'); >+ if (index >= 0) { >+ result[0] = _url.substring(0, index); >+ result[1] = _url.substring(index+1); >+ } else { >+ result[1] = _url; >+ } >+ } >+ return result; >+ } >+ >+ public int getYPosition (String _subrange){ >+ int result = WRONG_POS; >+ _subrange = _subrange.trim (); >+ if (_subrange.length () != 0){ >+ String digitstr = getDigitPart (_subrange); >+ try { >+ result = Integer.parseInt (digitstr); >+ if (result > MAX_HEIGHT){ >+ result = WRONG_POS; >+ } >+ } >+ catch (Exception ex) { >+ >+ result = WRONG_POS; >+ } >+ } >+ return result; >+ } >+ >+ private static boolean isLetter (String _str){ >+ boolean res = true; >+ if ( !_str.equals ("") ){ >+ for (int i = 0 ; i < _str.length (); i++){ >+ char ch = _str.charAt (i); >+ if (! Character.isLetter (ch)){ >+ res = false; >+ break; >+ } >+ } >+ }else >+ res = false; >+ return res; >+ } >+ >+ public int getXPosition (String _subrange){ >+ int result = WRONG_POS; >+ String tmp = filter$ (_subrange); >+ tmp = this.getCharPart (_subrange); >+ // we will process only 2 letters ranges >+ if (isLetter (tmp) && ((tmp.length () == 2)|| (tmp.length () == 1) )){ >+ result = get26Sys (tmp); >+ } >+ return result; >+ } >+ >+ public String getDigitPart (String _value){ >+ String result = ""; >+ int digitpos = getFirstDigitPosition (_value); >+ if(digitpos >= 0){ >+ result = _value.substring (digitpos); >+ } >+ return result; >+ } >+ >+ public String getCharPart (String _value){ >+ String result = ""; >+ int digitpos = getFirstDigitPosition (_value); >+ if(digitpos >= 0){ >+ result = _value.substring (0, digitpos); >+ } >+ return result; >+ } >+ >+ private String filter$ (String _range){ >+ String res = ""; >+ for (int i = 0 ; i < _range.length () ; i++){ >+ char ch = _range.charAt (i); >+ if ( ch != '$' ){ >+ res = res + ch; >+ } >+ } >+ return res; >+ } >+ >+ private int getFirstDigitPosition (String _value){ >+ int result = WRONG_POS; >+ if(_value != null && _value.trim ().length () == 0){ >+ return result; >+ } >+ _value = _value.trim (); >+ int length = _value.length (); >+ for(int i = 0; i < length; i++){ >+ if(Character.isDigit (_value.charAt (i))){ >+ result = i; >+ break; >+ } >+ } >+ return result; >+ } >+ >+ public int get26Sys (String _s){ >+ int sum = 0; >+ int multiplier = 1; >+ if (_s != "") { >+ for (int i = _s.length ()-1 ; i >= 0 ; i--){ >+ char ch = _s.charAt (i); >+ int val = Character.getNumericValue (ch) - Character.getNumericValue ('A')+1; >+ sum = sum + val * multiplier; >+ multiplier = multiplier * 26; >+ } >+ return sum; >+ } >+ return WRONG_POS; >+ } >+ >+ public String numTo26Sys (int _num){ >+ int sum = 0; >+ int reminder; >+ String s =""; >+ do{ >+ _num --; >+ reminder = _num % 26; >+ int val = 65 + reminder; >+ _num = _num / 26; >+ s = (char)val + s; // reverce >+ }while(_num > 0); >+ return s; >+ } >+ >+ public String replaceString(String _source , String _oldPattern, >+ String _newPattern){ >+ StringBuffer res = new StringBuffer(_source); >+ int pos = -1; >+ >+ while ((pos = res.toString().indexOf(_oldPattern, pos)) > -1){ >+ res.replace(pos, pos + _oldPattern.length(), _newPattern); >+ } >+ >+ return res.toString(); >+ } >+ >+ public String removeString(String _source, String _match){ >+ return replaceString(_source, _match, ""); >+ } >+ >+} >+ >Index: src/testcases/org/apache/poi/hssf/HSSFTests.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/HSSFTests.java,v >retrieving revision 1.3 >diff -u -r1.3 HSSFTests.java >--- src/testcases/org/apache/poi/hssf/HSSFTests.java 2 Jan 2003 11:17:57 -0000 1.3 >+++ src/testcases/org/apache/poi/hssf/HSSFTests.java 29 Jan 2003 17:00:54 -0000 >@@ -50,6 +50,7 @@ > import org.apache.poi.hssf.record.TestUnitsRecord; > import org.apache.poi.hssf.record.TestValueRangeRecord; > import org.apache.poi.hssf.record.aggregates.TestRowRecordsAggregate; >+import org.apache.poi.hssf.record.formula.TestArea3DPtg; > import org.apache.poi.hssf.usermodel.TestCellStyle; > import org.apache.poi.hssf.usermodel.TestFormulas; > import org.apache.poi.hssf.usermodel.TestHSSFCell; >@@ -146,6 +147,9 @@ > suite.addTest(new TestSuite(TestCellReference.class)); > suite.addTest(new TestSuite(TestRKUtil.class)); > suite.addTest(new TestSuite(TestSheetReferences.class)); >+ >+ //adds test of formula ptgs >+ suite.addTest(new TestSuite(TestArea3DPtg.class)); > > //$JUnit-END$ > return suite; >Index: src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java,v >retrieving revision 1.6 >diff -u -r1.6 TestHSSFCell.java >--- src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java 26 Jan 2003 20:34:39 -0000 1.6 >+++ src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java 29 Jan 2003 17:00:55 -0000 >@@ -232,7 +232,7 @@ > throws java.io.IOException { > String readFilename = System.getProperty("HSSF.testdata.path"); > >- File file = File.createTempFile("testBoolErr",".xls"); >+ File file = File.createTempFile("testFormulaStyle",".xls"); > FileOutputStream out = new FileOutputStream(file); > HSSFWorkbook wb = new HSSFWorkbook(); > HSSFSheet s = wb.createSheet("Sheet1"); >Index: src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java,v >retrieving revision 1.3 >diff -u -r1.3 TestNamedRange.java >--- src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java 9 Oct 2002 00:05:55 -0000 1.3 >+++ src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java 29 Jan 2003 17:00:55 -0000 >@@ -1,27 +1,75 @@ >-/* >- * RangeTestTest.java >- * NetBeans JUnit based test >+ >+/* ==================================================================== >+ * The Apache Software License, Version 1.1 >+ * >+ * Copyright (c) 2002 The Apache Software Foundation. All rights >+ * reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in >+ * the documentation and/or other materials provided with the >+ * distribution. >+ * >+ * 3. The end-user documentation included with the redistribution, >+ * if any, must include the following acknowledgment: >+ * "This product includes software developed by the >+ * Apache Software Foundation (http://www.apache.org/)." >+ * Alternately, this acknowledgment may appear in the software itself, >+ * if and wherever such third-party acknowledgments normally appear. > * >- * Created on April 21, 2002, 6:23 PM >+ * 4. The names "Apache" and "Apache Software Foundation" and >+ * "Apache POI" must not be used to endorse or promote products >+ * derived from this software without prior written permission. For >+ * written permission, please contact apache@apache.org. >+ * >+ * 5. Products derived from this software may not be called "Apache", >+ * "Apache POI", nor may "Apache" appear in their name, without >+ * prior written permission of the Apache Software Foundation. >+ * >+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED >+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES >+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE >+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR >+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, >+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT >+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF >+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND >+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, >+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT >+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF >+ * SUCH DAMAGE. >+ * ==================================================================== >+ * >+ * This software consists of voluntary contributions made by many >+ * individuals on behalf of the Apache Software Foundation. For more >+ * information on the Apache Software Foundation, please see >+ * <http://www.apache.org/>. > */ > > package org.apache.poi.hssf.usermodel; > >-import junit.framework.*; >- >-import org.apache.poi.poifs.filesystem.POIFSFileSystem; >- > import java.io.File; > import java.io.FileInputStream; >-import java.io.FileNotFoundException; > import java.io.FileOutputStream; > import java.io.IOException; > >+import junit.framework.TestCase; >+ >+import org.apache.poi.hssf.util.AreaReference; >+import org.apache.poi.poifs.filesystem.POIFSFileSystem; >+ > > /** >- * > * @author ROMANL > * @author Andrew C. Oliver (acoliver at apache dot org) >+ * @author Danny Mui (danny at muibros.com) > */ > public class TestNamedRange > extends TestCase { >@@ -54,6 +102,25 @@ > junit.textui.TestRunner.run(TestNamedRange.class); > } > >+ >+ /** >+ * There was bug where the named reference was not being set properly >+ * <p> >+ * i.e. Sheet1!$1$2 did not translate to Sheet1!$A$1:$UV$2 >+ */ >+ public void testNameRowReference() >+ { >+ HSSFWorkbook wb = new HSSFWorkbook(); >+ wb.createSheet("Sheet 1"); >+ HSSFName name = wb.createName(); >+ >+ name.setNameName("test"); >+ name.setReference("Sheet 1!$1:$2"); >+ >+ assertEquals("Row references should be converted: ", "Sheet 1!$A$1:$"+AreaReference.MAXIMUM_COLUMN+"$2", name.getReference()); >+ >+ } >+ > /** Test of TestCase method, of class test.RangeTest. */ > public void testNamedRange() > throws IOException >@@ -63,14 +130,65 @@ > HSSFWorkbook wb = null; > > String filename = System.getProperty("HSSF.testdata.path"); >- > filename = filename + "/Simple.xls"; > >+ fis = new FileInputStream(filename); >+ fs = new POIFSFileSystem(fis); >+ wb = new HSSFWorkbook(fs); > >- fis = new FileInputStream(filename); >- fs = new POIFSFileSystem(fis); >- wb = new HSSFWorkbook(fs); >+ //Creating new Named Range >+ HSSFName newNamedRange = wb.createName(); > >+ //Getting Sheet Name for the reference >+ String sheetName = wb.getSheetName(0); >+ >+ //Setting its name >+ newNamedRange.setNameName("RangeTest"); >+ //Setting its reference >+ newNamedRange.setReference(sheetName + "!$D$4:$E$8"); >+ >+ //Getting Named Range >+ HSSFName namedRange1 = wb.getNameAt(0); >+ //Getting it sheet name >+ sheetName = namedRange1.getSheetName(); >+ //Getting its reference >+ String referece = namedRange1.getReference(); >+ >+ File file = File.createTempFile("testNamedRange", >+ ".xls"); >+ >+ FileOutputStream fileOut = new FileOutputStream(file); >+ wb.write(fileOut); >+ fis.close(); >+ fileOut.close(); >+ >+ assertTrue("file exists",file.exists()); >+ >+ >+ FileInputStream in = new FileInputStream(file); >+ wb = new HSSFWorkbook(in); >+ HSSFName nm =wb.getNameAt(wb.getNameIndex("RangeTest")); >+ assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName())); >+ assertEquals("Reference Matches",wb.getSheetName(0)+"!$D$4:$E$8", nm.getReference()); >+ >+ >+ } >+ >+ /** Test that multiple named ranges can be added >+ */ >+ public void testMultipleNamedRange() >+ throws IOException >+ { >+ FileInputStream fis = null; >+ POIFSFileSystem fs = null; >+ HSSFWorkbook wb = null; >+ >+ String filename = System.getProperty("HSSF.testdata.path"); >+ filename = filename + "/Simple.xls"; >+ >+ fis = new FileInputStream(filename); >+ fs = new POIFSFileSystem(fis); >+ wb = new HSSFWorkbook(fs); > > //Creating new Named Range > HSSFName newNamedRange = wb.createName(); >@@ -81,8 +199,20 @@ > //Setting its name > newNamedRange.setNameName("RangeTest"); > //Setting its reference >- newNamedRange.setReference(sheetName + ".$D$4:$E$8"); >- >+ newNamedRange.setReference(sheetName + "!$D$4:$E$8"); >+ >+ //Creating another new Named Range >+ HSSFName newNamedRange2 = wb.createName(); >+ >+ //Getting Sheet Name for the reference >+ sheetName = wb.getSheetName(1); >+ >+ //Setting its name >+ newNamedRange2.setNameName("AnotherTest"); >+ //Setting its reference >+ newNamedRange2.setReference(sheetName + "!$F$1:$G$6"); >+ >+ > //Getting NAmed Range > HSSFName namedRange1 = wb.getNameAt(0); > //Getting it sheet name >@@ -90,7 +220,7 @@ > //Getting its reference > String referece = namedRange1.getReference(); > >- File file = File.createTempFile("testNamedRange", >+ File file = File.createTempFile("testMultiNamedRange", > ".xls"); > > FileOutputStream fileOut = new FileOutputStream(file); >@@ -100,14 +230,351 @@ > > assertTrue("file exists",file.exists()); > >+ > FileInputStream in = new FileInputStream(file); > wb = new HSSFWorkbook(in); > HSSFName nm =wb.getNameAt(wb.getNameIndex("RangeTest")); > assertTrue("Name is "+nm.getNameName(),"RangeTest".equals(nm.getNameName())); > assertTrue("Reference is "+nm.getReference(),(wb.getSheetName(0)+"!$D$4:$E$8").equals(nm.getReference())); > >+ nm = wb.getNameAt(wb.getNameIndex("AnotherTest")); >+ assertTrue("Name is "+nm.getNameName(),"AnotherTest".equals(nm.getNameName())); >+ assertTrue("Reference is "+nm.getReference(),newNamedRange2.getReference().equals(nm.getReference())); >+ >+ >+ } >+ >+ /** >+ * Addresses Bug #16411 >+ */ >+ public void testNamedRead() throws IOException >+ { >+ FileInputStream fis = null; >+ POIFSFileSystem fs = null; >+ HSSFWorkbook wb = null; >+ >+ String filename = System.getProperty("HSSF.testdata.path"); >+ filename = filename + "/SimpleNamed.xls"; >+ >+ fis = new FileInputStream(filename); >+ fs = new POIFSFileSystem(fis); >+ wb = new HSSFWorkbook(fs); >+ >+ HSSFName name = wb.getNameAt(0); >+ String sheetName = wb.getSheetName(0); >+ >+ assertEquals("Retrieved name", "Test", name.getNameName()); >+ assertEquals("Reference",sheetName+"!$C$8", name.getReference()); >+ >+ name.setReference(sheetName+"!$A$1:$C$36"); >+ assertEquals("Reference",sheetName+"!$A$1:$C$36", name.getReference()); >+ >+ fis.close(); >+ } >+ >+ /**Test to see if the print areas can be retrieved/created in memory >+ */ >+ public void testSinglePrintArea() >+ { >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ HSSFSheet sheet = workbook.createSheet("Test Print Area"); >+ String sheetName = workbook.getSheetName(0); >+ //HSSFName printArea = workbook.createPrintArea(0); >+ //assertNotNull("Print Area is Null", printArea); >+ >+ //printArea.setReference(); >+ String reference = sheetName+"!$A$1:$B$1"; >+ workbook.setPrintArea(0, reference); >+ >+ String retrievedPrintArea = workbook.getPrintArea(0); >+ >+ assertNotNull("Print Area not defined for first sheet", retrievedPrintArea); >+ assertEquals("References Match", reference, retrievedPrintArea); >+ >+ } >+ >+ /** >+ * Test to see if the print area made it to the file >+ */ >+ public void testPrintAreaFile() >+ throws IOException >+ { >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ HSSFSheet sheet = workbook.createSheet("Test Print Area"); >+ String sheetName = workbook.getSheetName(0); >+ //HSSFName printArea = workbook.createPrintArea(0); >+ //assertNotNull("Print Area is Null", printArea); >+ >+ //printArea.setReference(); >+ String reference = sheetName+"!$A$1:$B$1"; >+ workbook.setPrintArea(0, reference); >+ >+ File file = File.createTempFile("testPrintArea",".xls"); >+ >+ FileOutputStream fileOut = new FileOutputStream(file); >+ workbook.write(fileOut); >+ fileOut.close(); >+ >+ assertTrue("file exists",file.exists()); >+ >+ FileInputStream in = new FileInputStream(file); >+ workbook = new HSSFWorkbook(in); >+ >+ String retrievedPrintArea = workbook.getPrintArea(0); >+ assertNotNull("Print Area not defined for first sheet", retrievedPrintArea); >+ assertEquals("References Match", reference, retrievedPrintArea); > > } >+ >+ /**Test to see if the multiple print areas can be retrieved/created in memory >+ */ >+ public void testMultiplePrintArea() >+ { >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ HSSFSheet sheet = workbook.createSheet("Sheet 1"); >+ sheet = workbook.createSheet("Sheet 2"); >+ sheet = workbook.createSheet("Sheet 3"); > >+ String sheetName = workbook.getSheetName(0); >+ String reference = null; >+ >+ >+ reference = sheetName+"!$A$1:$B$1"; >+ workbook.setPrintArea(0, reference); >+ >+ sheetName = workbook.getSheetName(1); >+ String reference2 = sheetName+"!$B$2:$D$5"; >+ workbook.setPrintArea(1, reference2); >+ >+ sheetName = workbook.getSheetName(2); >+ String reference3 = sheetName+"!$D$2:$F$5"; >+ workbook.setPrintArea(2, reference3); >+ >+ String retrievedPrintArea = workbook.getPrintArea(0); >+ assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea); >+ assertEquals("References Do Not Match (Sheet 1)", reference, retrievedPrintArea); >+ >+ String retrievedPrintArea2 = workbook.getPrintArea(1); >+ assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea2); >+ assertEquals("References Do Not Match (Sheet 2)", reference2, retrievedPrintArea2); >+ >+ String retrievedPrintArea3 = workbook.getPrintArea(2); >+ assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea3); >+ assertEquals("References Do Not Match (Sheet 3)", reference3, retrievedPrintArea3); >+ >+ >+ >+ } >+ >+ /** >+ * Test to see if multiple print areas made it to the file >+ */ >+ public void testMultiplePrintAreaFile() >+ throws IOException >+ { >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ >+ HSSFSheet sheet = workbook.createSheet("Sheet 1"); >+ sheet = workbook.createSheet("Sheet 2"); >+ sheet = workbook.createSheet("Sheet 3"); >+ >+ String sheetName = workbook.getSheetName(0); >+ String reference = null; >+ >+ >+ reference = sheetName+"!$A$1:$B$1"; >+ workbook.setPrintArea(0, reference); >+ >+ sheetName = workbook.getSheetName(1); >+ String reference2 = sheetName+"!$B$2:$D$5"; >+ workbook.setPrintArea(1, reference2); >+ >+ sheetName = workbook.getSheetName(2); >+ String reference3 = sheetName+"!$D$2:$F$5"; >+ workbook.setPrintArea(2, reference3); >+ >+ File file = File.createTempFile("testMultiPrintArea",".xls"); >+ >+ FileOutputStream fileOut = new FileOutputStream(file); >+ workbook.write(fileOut); >+ fileOut.close(); >+ >+ assertTrue("file exists",file.exists()); >+ >+ FileInputStream in = new FileInputStream(file); >+ workbook = new HSSFWorkbook(in); >+ >+ String retrievedPrintArea = workbook.getPrintArea(0); >+ assertNotNull("Print Area Not Found (Sheet 1)", retrievedPrintArea); >+ assertEquals("References Do Not Match (Sheet 1)", reference, retrievedPrintArea); >+ >+ String retrievedPrintArea2 = workbook.getPrintArea(1); >+ assertNotNull("Print Area Not Found (Sheet 2)", retrievedPrintArea2); >+ assertEquals("References Do Not Match (Sheet 2)", reference2, retrievedPrintArea2); >+ >+ String retrievedPrintArea3 = workbook.getPrintArea(2); >+ assertNotNull("Print Area Not Found (Sheet 3)", retrievedPrintArea3); >+ assertEquals("References Do Not Match (Sheet 3)", reference3, retrievedPrintArea3); >+ >+ >+ } >+ >+ /**Test to see if the printTitles can be retrieved/created in memory >+ */ >+ public void testSinglePrintTitles() >+ { >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ HSSFSheet sheet = workbook.createSheet("Test Print Titles"); >+ String sheetName = workbook.getSheetName(0); >+ HSSFPrintTitles titles = workbook.createPrintTitles(0); >+ assertNotNull("Print Title is Null", titles); >+ >+ titles.setRowReference(sheetName+"!$1:$2"); >+ assertEquals("Sheetnames did not carry over.", titles.getSheetName(), sheetName); >+ assertEquals("PrintTitles properly set.", titles.getNameName(), "Print_Titles"); >+ >+ >+ HSSFName retrievedName = workbook.getPrintTitles(0); >+ assertEquals("PrintTitles properly set.", retrievedName.getNameName(), "Print_Titles"); >+ >+ assertEquals("References Match", titles.getReference(), retrievedName.getReference()); >+ >+ } >+ >+ /** >+ * Test to see if the print_titles made it to the file >+ */ >+ public void testPrintTitlesFile() >+ throws IOException >+ { >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ HSSFSheet sheet = workbook.createSheet("Test Print Titles"); >+ String sheetName = workbook.getSheetName(0); >+ HSSFPrintTitles titles = workbook.createPrintTitles(0); >+ assertNotNull("Print Title is Null", titles); >+ >+ titles.setRowReference(sheetName+"!$1:$2"); >+ assertEquals("Sheetnames did not carry over.", titles.getSheetName(), sheetName); >+ assertEquals("PrintTitles properly set.", titles.getNameName(), "Print_Titles"); >+ >+ File file = File.createTempFile("testPrintTitles",".xls"); >+ >+ FileOutputStream fileOut = new FileOutputStream(file); >+ workbook.write(fileOut); >+ fileOut.close(); >+ >+ assertTrue("file exists",file.exists()); >+ >+ FileInputStream in = new FileInputStream(file); >+ workbook = new HSSFWorkbook(in); >+ HSSFPrintTitles retrievedTitles = workbook.getPrintTitles(0); >+ assertNotNull("Print Area Not Found", retrievedTitles); >+ assertEquals("References Do Not Match", titles.getReference(), retrievedTitles.getReference()); >+ assertEquals("Row References Do Not Match", titles.getRowReference(), retrievedTitles.getRowReference()); >+ assertEquals("Column References Do Not Match", titles.getColReference(), retrievedTitles.getColReference()); >+ >+ } >+ >+ /**Test to see if the multiple print_titles can be retrieved/created in memory >+ */ >+ public void testMultiplePrintTitles() >+ { >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ HSSFSheet sheet = workbook.createSheet("Sheet 1"); >+ sheet = workbook.createSheet("Sheet 2"); >+ sheet = workbook.createSheet("Sheet 3"); >+ >+ String sheetName = workbook.getSheetName(0); >+ >+ HSSFPrintTitles titles = workbook.createPrintTitles(0); >+ assertNotNull("Print Titles (Sheet 1) is Null", titles); >+ >+ titles.setRowReference(sheetName+"!$1:$2"); >+ assertEquals("Sheetnames did not carry over.", titles.getSheetName(), sheetName); >+ >+ >+ sheetName = workbook.getSheetName(1); >+ HSSFPrintTitles titles2 = workbook.createPrintTitles(1); >+ assertNotNull("Print Titles (Sheet 2) is Null", titles2); >+ >+ titles2.setColReference(sheetName+"!$A:$A"); >+ assertNotNull("Print Titles (Sheet 2) is Null", titles2); >+ >+ sheetName = workbook.getSheetName(2); >+ HSSFPrintTitles titles3 = workbook.createPrintTitles(2); >+ assertNotNull("Print Titles (Sheet 3) is Null", titles3); >+ >+ titles3.setColReference(sheetName+"!$D:$E"); >+ assertNotNull("Print Titles (Sheet 3) is Null", titles3); >+ >+ >+ HSSFName retrievedTitles = workbook.getPrintTitles(0); >+ assertEquals("References Match", titles.getReference(), retrievedTitles.getReference()); >+ >+ HSSFName retrievedTitles2 = workbook.getPrintTitles(1); >+ assertEquals("References Match (Sheet 2)", titles2.getReference(), retrievedTitles2.getReference()); >+ >+ HSSFName retrievedTitles3 = workbook.getPrintTitles(2); >+ assertEquals("References Match (Sheet 3)", titles3.getReference(), retrievedTitles3.getReference()); >+ >+ } >+ >+ /** >+ * Test to see if multiple print titles made it to the file >+ */ >+ public void testMultiplePrintTitlesFile() >+ throws IOException >+ { >+ >+ HSSFWorkbook workbook = new HSSFWorkbook(); >+ HSSFSheet sheet = workbook.createSheet("Sheet 1"); >+ sheet = workbook.createSheet("Sheet 2"); >+ sheet = workbook.createSheet("Sheet 3"); >+ >+ String sheetName = workbook.getSheetName(0); >+ >+ HSSFPrintTitles titles = workbook.createPrintTitles(0); >+ assertNotNull("Print Titles (Sheet 1) is Null", titles); >+ >+ titles.setRowReference(sheetName+"!$1:$2"); >+ assertEquals("Sheetnames did not carry over.", titles.getSheetName(), sheetName); >+ >+ >+ sheetName = workbook.getSheetName(1); >+ HSSFPrintTitles titles2 = workbook.createPrintTitles(1); >+ assertNotNull("Print Titles (Sheet 2) is Null", titles2); >+ >+ titles2.setColReference(sheetName+"!$A:$A"); >+ assertNotNull("Print Titles (Sheet 2) is Null", titles2); >+ >+ sheetName = workbook.getSheetName(2); >+ HSSFPrintTitles titles3 = workbook.createPrintTitles(2); >+ assertNotNull("Print Titles (Sheet 3) is Null", titles3); >+ >+ titles3.setColReference(sheetName+"!$D:$E"); >+ assertNotNull("Print Titles (Sheet 3) is Null", titles3); >+ >+ File file = File.createTempFile("testMultiPrintTitles",".xls"); >+ FileOutputStream fileOut = new FileOutputStream(file); >+ workbook.write(fileOut); >+ fileOut.close(); >+ >+ assertTrue("file exists",file.exists()); >+ >+ FileInputStream in = new FileInputStream(file); >+ workbook = new HSSFWorkbook(in); >+ >+ >+ HSSFName retrievedTitles = workbook.getPrintTitles(0); >+ assertEquals("References Match", titles.getReference(), retrievedTitles.getReference()); >+ >+ HSSFName retrievedTitles2 = workbook.getPrintTitles(1); >+ assertEquals("References Match (Sheet 2)", titles2.getReference(), retrievedTitles2.getReference()); >+ >+ HSSFName retrievedTitles3 = workbook.getPrintTitles(2); >+ assertEquals("References Match (Sheet 3)", titles3.getReference(), retrievedTitles3.getReference()); >+ >+ } >+ > } > >Index: src/testcases/org/apache/poi/hssf/util/TestAreaReference.java >=================================================================== >RCS file: /home/cvspublic/jakarta-poi/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java,v >retrieving revision 1.1 >diff -u -r1.1 TestAreaReference.java >--- src/testcases/org/apache/poi/hssf/util/TestAreaReference.java 5 May 2002 16:55:41 -0000 1.1 >+++ src/testcases/org/apache/poi/hssf/util/TestAreaReference.java 29 Jan 2003 17:00:55 -0000 >@@ -60,6 +60,24 @@ > public TestAreaReference(String s) { > super(s); > } >+ >+ >+ public static void main(String [] ignored_args) >+ { >+ String filename = System.getProperty("HSSF.testdata.path"); >+ >+ System.out >+ .println("Testing org.apache.poi.hssf.util.TestAreaReference"); >+ junit.textui.TestRunner.run(TestAreaReference.class); >+ } >+ >+ public void testRemoveAbsolutes() >+ { >+ assertEquals("Absolutes Removed", "A1:B2", AreaReference.removeAbsolutes("$A$1:$B$2")); >+ assertEquals("Absolutes Removed", "sheet!A1:B2", AreaReference.removeAbsolutes("sheet!$A$1:$B$2")); >+ } >+ >+ > public void testAreaRef1() { > AreaReference ar = new AreaReference("$A$1:$B$2"); > assertTrue("Two cells expected",ar.getCells().length == 2); >@@ -77,4 +95,167 @@ > assertTrue("col is abs",cf.isColAbsolute()); > assertTrue("string is $B$2",cf.toString().equals("$B$2")); > } >+ >+ /**Tests the static function to see if it correctly interprets the formula >+ */ >+ public void testIsRowOnly(){ >+ assertTrue("$1:$2 is a row only formula", AreaReference.isRowOnlyReference("$1:$2")); >+ assertTrue("$A$1:$2 is not row only formula", !AreaReference.isRowOnlyReference("$A$1:$2")); >+ assertTrue("$A$1:$B$2 is not row only formula", !AreaReference.isRowOnlyReference("$A$1:$B$2")); >+ >+ assertTrue("1:2 is a row only formula", AreaReference.isRowOnlyReference("1:2")); >+ assertTrue("A1:2 is not row only formula", !AreaReference.isRowOnlyReference("A1:2")); >+ assertTrue("A1:B2 is not row only formula", !AreaReference.isRowOnlyReference("A1:$B2")); >+ >+ assertTrue("$A:$B is not a row only forumla", !AreaReference.isRowOnlyReference("$A:$B")); >+ } >+ >+ /**Tests the static function to see if it correctly interprets the formula >+ */ >+ public void testIsRowOnlyWithSheets(){ >+ assertTrue("Sheet1!$1:$2 is a row only formula", AreaReference.isRowOnlyReference("Sheet1!$1:$2")); >+ assertTrue("Sheet!$A$1:$2 is not row only formula", !AreaReference.isRowOnlyReference("Sheet1!$A$1:$2")); >+ assertTrue("Sheet1!$A$1:$B$2 is not row only formula", !AreaReference.isRowOnlyReference("Sheet1!$A$1:$B$2")); >+ >+ assertTrue("1:2 is a row only formula", AreaReference.isRowOnlyReference("Sheet1!1:2")); >+ assertTrue("A1:2 is not row only formula", !AreaReference.isRowOnlyReference("Sheet1!A1:2")); >+ assertTrue("A1:B2 is not row only formula", !AreaReference.isRowOnlyReference("Sheet1!A1:$B2")); >+ >+ >+ assertTrue("$A:$B is not a row only forumla", !AreaReference.isRowOnlyReference("Sheet1!$A:$B")); >+ } >+ >+ /**Tests the static function to see if it correctly interprets the formula >+ */ >+ public void testIsColOnly(){ >+ assertTrue("$A:$B is a col only formula", AreaReference.isColOnlyReference("$A:$A")); >+ >+ assertTrue("$A$1:$2 is not col only formula", !AreaReference.isColOnlyReference("$A$1:$2")); >+ assertTrue("$A$1:$B$2 is not col only formula", !AreaReference.isColOnlyReference("$A$1:$B$2")); >+ >+ assertTrue("A:B is a col only formula", AreaReference.isColOnlyReference("A:B")); >+ assertTrue("A1:2 is not col only formula", !AreaReference.isColOnlyReference("A1:2")); >+ assertTrue("A1:B2 is not col only formula", !AreaReference.isColOnlyReference("A1:$B2")); >+ >+ assertTrue("$1:$2 is not a col only forumla", !AreaReference.isColOnlyReference("$1:$2")); >+ } >+ >+ /**Tests the static function to see if it correctly interprets the formula >+ */ >+ public void testIsColOnlyWithSheets(){ >+ assertTrue("$A:$B is a col only formula", AreaReference.isColOnlyReference("Sheet 1!$A:$A")); >+ >+ assertTrue("$A$1:$2 is not col only formula", !AreaReference.isColOnlyReference("Sheet 1!$A$1:$2")); >+ assertTrue("$A$1:$B$2 is not col only formula", !AreaReference.isColOnlyReference("Sheet 1!$A$1:$B$2")); >+ >+ assertTrue("A:B is a col only formula", AreaReference.isColOnlyReference("Sheet 1!A:B")); >+ assertTrue("A1:2 is not col only formula", !AreaReference.isColOnlyReference("Sheet 1!A1:2")); >+ assertTrue("A1:B2 is not col only formula", !AreaReference.isColOnlyReference("Sheet 1!A1:$B2")); >+ >+ assertTrue("$1:$2 is not a col only forumla", !AreaReference.isColOnlyReference("Sheet 1!$1:$2")); >+ } >+ >+ >+ /**Generate the correct references for row only references >+ */ >+ >+ public void testRowReferences() >+ { >+ AreaReference ar = new AreaReference("$1:$1"); >+ >+ assertTrue("Two cells expected",ar.getCells().length == 2); >+ >+ CellReference cf = ar.getCells()[0]; >+ assertTrue("row is 0",cf.getRow()==0); >+ assertTrue("col is 0",cf.getCol()==0); >+ assertTrue("row is abs",cf.isRowAbsolute()); >+ assertTrue("col is abs",cf.isColAbsolute()); >+ assertTrue("string is $A$1",cf.toString().equals("$A$1")); >+ >+ cf = ar.getCells()[1]; >+ assertTrue("row is 1",cf.getRow()==0); >+ assertTrue("col is 255",cf.getCol()==255); >+ assertTrue("row is abs",cf.isRowAbsolute()); >+ assertTrue("col is abs",cf.isColAbsolute()); >+ assertTrue("string is $IV$1",cf.toString().equals("$IV$1")); >+ >+ >+ } >+ >+ /**Generate the correct references for row only references >+ */ >+ >+ public void testMultipleRowReferences() >+ { >+ AreaReference ar = new AreaReference("$1:$2"); >+ >+ assertTrue("Two cells expected",ar.getCells().length == 2); >+ >+ CellReference cf = ar.getCells()[0]; >+ assertTrue("row is 0",cf.getRow()==0); >+ assertTrue("col is 0",cf.getCol()==0); >+ assertTrue("row is abs",cf.isRowAbsolute()); >+ assertTrue("col is abs",cf.isColAbsolute()); >+ assertTrue("string is $A$1",cf.toString().equals("$A$1")); >+ >+ cf = ar.getCells()[1]; >+ assertTrue("row is 1",cf.getRow()==1); >+ assertTrue("col is 255",cf.getCol()==255); >+ assertTrue("row is abs",cf.isRowAbsolute()); >+ assertTrue("col is abs",cf.isColAbsolute()); >+ assertTrue("string is $IV$2",cf.toString().equals("$IV$2")); >+ >+ >+ } >+ >+ >+ /**Generate the correct references for column only references >+ */ >+ public void testColReferences() >+ { >+ AreaReference ar = new AreaReference("$A:$A"); >+ >+ assertTrue("Two cells expected",ar.getCells().length == 2); >+ >+ CellReference cf = ar.getCells()[0]; >+ assertTrue("row is 0",cf.getRow()==0); >+ assertTrue("col is 0",cf.getCol()==0); >+ assertTrue("row is abs",cf.isRowAbsolute()); >+ assertTrue("col is abs",cf.isColAbsolute()); >+ assertTrue("string is $A$1",cf.toString().equals("$A$1")); >+ >+ cf = ar.getCells()[1]; >+ //internal representation is 0 based >+ assertEquals("row number",65535,cf.getRow()); >+ assertEquals("last col", 0, cf.getCol()); >+ assertTrue("row is abs",cf.isRowAbsolute()); >+ assertTrue("col is abs",cf.isColAbsolute()); >+ assertEquals("String Reference","$A$"+AreaReference.MAXIMUM_CELL_REFERENCE_ROW,cf.toString()); >+ >+ } >+ >+ /**Generate the correct references for column only references >+ */ >+ public void testMultipleColReferences() >+ { >+ AreaReference ar = new AreaReference("$B:$D"); >+ >+ assertTrue("Two cells expected",ar.getCells().length == 2); >+ >+ CellReference cf = ar.getCells()[0]; >+ assertTrue("row is 0",cf.getRow()==0); >+ assertTrue("col is 0",cf.getCol()==1); >+ assertTrue("row is abs",cf.isRowAbsolute()); >+ assertTrue("col is abs",cf.isColAbsolute()); >+ assertTrue("String Reference",cf.toString().equals("$B$1")); >+ >+ cf = ar.getCells()[1]; >+ //internal representation is 0 based >+ assertEquals("last row number", 65535, cf.getRow()); >+ assertEquals("last col", 3, cf.getCol()); >+ assertTrue("row is abs",cf.isRowAbsolute()); >+ assertTrue("col is abs",cf.isColAbsolute()); >+ assertEquals("String Reference","$D$"+AreaReference.MAXIMUM_CELL_REFERENCE_ROW, cf.toString()); >+ >+ } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 16557
:
4630
| 4631