From 235eb62f532d9f877327b0483cae2352f7842a55 Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Thu, 18 Sep 2008 22:13:01 +0000 Subject: [PATCH] Merged revisions 696501 via svnmerge from https://svn.apache.org/repos/asf/poi/trunk ........ r696501 | josh | 2008-09-17 15:35:09 -0700 (Wed, 17 Sep 2008) | 1 line Small tweak to NamePtg and Ref3DPtg ........ git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@696831 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/model/FormulaParser.java | 4 +-- .../apache/poi/hssf/record/NameRecord.java | 4 +-- .../poi/hssf/record/formula/NamePtg.java | 34 ++++--------------- .../poi/hssf/record/formula/Ref3DPtg.java | 12 +++---- .../apache/poi/hssf/usermodel/HSSFName.java | 2 +- 5 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/FormulaParser.java b/src/java/org/apache/poi/hssf/model/FormulaParser.java index 32f38d40d1..a3fc9c1c49 100644 --- a/src/java/org/apache/poi/hssf/model/FormulaParser.java +++ b/src/java/org/apache/poi/hssf/model/FormulaParser.java @@ -319,7 +319,7 @@ public final class FormulaParser { for(int i = 0; i < book.getNumberOfNames(); i++) { // named range name matching is case insensitive if(book.getNameAt(i).getNameName().equalsIgnoreCase(name)) { - return new NamePtg(name, book); + return new NamePtg(i); } } throw new FormulaParseException("Specified named range '" @@ -388,7 +388,7 @@ public final class FormulaParser { // calls to user-defined functions within the workbook // get a Name token which points to a defined name record - nameToken = new NamePtg(name, this.book); + nameToken = new NamePtg(nameIndex); } else { if(book instanceof HSSFWorkbook) { nameToken = ((HSSFWorkbook)book).getNameXPtg(name); diff --git a/src/java/org/apache/poi/hssf/record/NameRecord.java b/src/java/org/apache/poi/hssf/record/NameRecord.java index 215c20feec..1a47e544dc 100644 --- a/src/java/org/apache/poi/hssf/record/NameRecord.java +++ b/src/java/org/apache/poi/hssf/record/NameRecord.java @@ -447,7 +447,7 @@ public final class NameRecord extends Record { /** gets the extern sheet number * @return extern sheet index */ - public short getExternSheetNumber(){ + public int getExternSheetNumber(){ if (field_13_name_definition.length < 1) { return 0; } @@ -513,7 +513,7 @@ public final class NameRecord extends Record { oldPtg = field_13_name_definition[0]; } List temp = new ArrayList(); - short externSheetIndex = 0; + int externSheetIndex = 0; if (oldPtg.getClass() == Area3DPtg.class){ externSheetIndex = ((Area3DPtg) oldPtg).getExternSheetIndex(); diff --git a/src/java/org/apache/poi/hssf/record/formula/NamePtg.java b/src/java/org/apache/poi/hssf/record/formula/NamePtg.java index a29ae5541d..1087ed9d23 100644 --- a/src/java/org/apache/poi/hssf/record/formula/NamePtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/NamePtg.java @@ -18,7 +18,6 @@ package org.apache.poi.hssf.record.formula; import org.apache.poi.hssf.record.RecordInputStream; -import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.util.LittleEndian; @@ -31,33 +30,14 @@ public final class NamePtg extends OperandPtg { public final static short sid = 0x23; private final static int SIZE = 5; /** one-based index to defined name record */ - private short field_1_label_index; + private int field_1_label_index; private short field_2_zero; // reserved must be 0 /** - * Creates new NamePtg and sets its name index to that of the corresponding defined name record - * in the workbook. The search for the name record is case insensitive. If it is not found, - * it gets created. + * @param nameIndex zero-based index to name within workbook */ - public NamePtg(String name, Workbook book) { - field_1_label_index = (short)(1+getOrCreateNameRecord(book, name)); // convert to 1-based - } - /** - * @return zero based index of the found or newly created defined name record. - */ - private static final int getOrCreateNameRecord(Workbook book, String name) { - // perhaps this logic belongs in Workbook? - int countNames = book.getNumberOfNames(); - for (int i = 0; i < countNames; i++) { - if(name.equalsIgnoreCase( book.getNameName(i) )) { - return i; - } - } - - Name nameObj = book.createName(); - nameObj.setNameName(name); - - return countNames; + public NamePtg(int nameIndex) { + field_1_label_index = 1+nameIndex; // convert to 1-based } /** Creates new NamePtg */ @@ -75,9 +55,9 @@ public final class NamePtg extends OperandPtg { } public void writeBytes(byte [] array, int offset) { - array[offset+0]= (byte) (sid + getPtgClass()); - LittleEndian.putShort(array,offset+1,field_1_label_index); - LittleEndian.putShort(array,offset+3, field_2_zero); + LittleEndian.putByte(array, offset + 0, sid + getPtgClass()); + LittleEndian.putUShort(array, offset + 1, field_1_label_index); + LittleEndian.putUShort(array, offset + 3, field_2_zero); } public int getSize() { diff --git a/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java index 308e9f0b53..a6ca3db2eb 100644 --- a/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java @@ -44,7 +44,7 @@ public final class Ref3DPtg extends RefPtgBase { readCoordinates(in); } - public Ref3DPtg(String cellref, short externIdx ) { + public Ref3DPtg(String cellref, int externIdx ) { CellReference c= new CellReference(cellref); setRow(c.getRow()); setColumn(c.getCol()); @@ -65,17 +65,17 @@ public final class Ref3DPtg extends RefPtgBase { } public void writeBytes(byte [] array, int offset) { - array[ 0 + offset ] = (byte) (sid + getPtgClass()); - LittleEndian.putShort(array, 1 + offset , getExternSheetIndex()); - writeCoordinates(array, offset+3); + LittleEndian.putByte(array, 0 + offset, sid + getPtgClass()); + LittleEndian.putUShort(array, 1 + offset, getExternSheetIndex()); + writeCoordinates(array, offset + 3); } public int getSize() { return SIZE; } - public short getExternSheetIndex(){ - return (short)field_1_index_extern_sheet; + public int getExternSheetIndex(){ + return field_1_index_extern_sheet; } public void setExternSheetIndex(int index){ diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFName.java b/src/java/org/apache/poi/hssf/usermodel/HSSFName.java index 6de2293794..bae2484d7c 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFName.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFName.java @@ -48,7 +48,7 @@ public class HSSFName implements Name { * @return sheet name, which this named range referred to */ public String getSheetName() { - short indexToExternSheet = _definedNameRec.getExternSheetNumber(); + int indexToExternSheet = _definedNameRec.getExternSheetNumber(); return _book.getWorkbook().findSheetNameFromExternSheet(indexToExternSheet); } -- 2.39.5