<!-- Don't forget to update status.xml too! -->
<release version="3.0.2-FINAL" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="add">42033 - Add support for named ranges with unicode names</action>
<action dev="POI-DEVELOPERS" type="add">34023 - When shifting rows, update formulas on that sheet to point to the new location of those rows</action>
<action dev="POI-DEVELOPERS" type="add">Support getting all the cells referenced by an AreaReference, not just the corner ones</action>
<action dev="POI-DEVELOPERS" type="add">43510 - Add support for named ranges in formulas, including non-contiguous named ranges</action>
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.0.2-FINAL" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="add">42033 - Add support for named ranges with unicode names</action>
<action dev="POI-DEVELOPERS" type="add">34023 - When shifting rows, update formulas on that sheet to point to the new location of those rows</action>
<action dev="POI-DEVELOPERS" type="add">Support getting all the cells referenced by an AreaReference, not just the corner ones</action>
<action dev="POI-DEVELOPERS" type="add">43510 - Add support for named ranges in formulas, including non-contiguous named ranges</action>
*/
public void setNameText(String name){
field_12_name_text = name;
+ setCompressedUnicodeFlag(
+ StringUtil.hasMultibyte(name) ? (byte)1 : (byte)0
+ );
}
// public void setNameDefintion(String definition){
return field_2_keyboard_shortcut ;
}
- /** gets the name length
+ /**
+ * gets the name length, in characters
* @return name length
*/
public byte getNameTextLength(){
return field_3_length_name_text;
}
+
+ /**
+ * gets the name length, in bytes
+ * @return raw name length
+ */
+ public byte getRawNameTextLength(){
+ if( (field_11_compressed_unicode_flag & 0x01) == 1 ) {
+ return (byte)(2 * field_3_length_name_text);
+ }
+ return field_3_length_name_text;
+ }
/** get the definition length
* @return definition length
data[17 + offset] = getStatusBarLength();
data[18 + offset] = getCompressedUnicodeFlag();
- /* temp: gjs
- if (isBuiltInName())
- {
- 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
- { */
-
int start_of_name_definition = 19 + field_3_length_name_text;
if (this.isBuiltInName()) {
//can send the builtin name directly in
data [19 + offset] = this.getBuiltInName();
+ } else if ((this.getCompressedUnicodeFlag() & 0x01) == 1) {
+ StringUtil.putUnicodeLE( getNameText(), data, 19 + offset );
+ start_of_name_definition = 19 + (2 * field_3_length_name_text);
} else {
StringUtil.putCompressedUnicode( getNameText(), data, 19 + offset );
-
}
/* } */
}
- /** gets the length of all texts
+ /**
+ * Gets the length of all texts, in bytes
* @return total length
*/
public int getTextsLength(){
int result;
- result = getNameTextLength() + getDescriptionTextLength() +
- getHelpTopicLength() + getStatusBarLength();
-
+ result = getRawNameTextLength() + getDescriptionTextLength() +
+ getHelpTopicLength() + getStatusBarLength();
return result;
}
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.TempFile;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
assertTrue("Name is "+nm2.getNameName(),"RangeTest2".equals(nm2.getNameName()));
assertTrue("Reference is "+nm2.getReference(),(wb.getSheetName(1)+"!$A$1:$O$21").equals(nm2.getReference()));
}
-
+
+ public void testUnicodeNamedRange() throws Exception {
+ HSSFWorkbook workBook = new HSSFWorkbook();
+ HSSFSheet sheet = workBook.createSheet("Test");
+ HSSFName name = workBook.createName();
+ name.setNameName("\u03B1");
+ name.setReference("Test!$D$3:$E$8");
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ workBook.write(out);
+
+ HSSFWorkbook workBook2 = new HSSFWorkbook(new ByteArrayInputStream(out.toByteArray()));
+ HSSFName name2 = workBook2.getNameAt(0);
+
+ assertEquals("\u03B1", name2.getNameName());
+ assertEquals("Test!$D$3:$E$8", name2.getReference());
+ }
/**
* Test to see if the print areas can be retrieved/created in memory