Hi All. (I can't write english so well, sorry.) I wrote a patch for NameRecord.java to support unicode in NamedRange. I tried to read and write Cell, that had been defined by Named Range(Unicode name defined), but did not go well. This patch is like to BoundSheetRecord.java, readUnicodeLEString used to read, putUnicodeLE used to write. regards. Index: src/java/org/apache/poi/hssf/record/NameRecord.java =================================================================== --- src/java/org/apache/poi/hssf/record/NameRecord.java (revision 525136) +++ src/java/org/apache/poi/hssf/record/NameRecord.java (working copy) @@ -274,6 +274,7 @@ */ public void setNameText(String name){ field_12_name_text = name; + setCompressedUnicodeFlag(StringUtil.hasMultibyte(name) ? (byte)1 : (byte)0); } // public void setNameDefintion(String definition){ @@ -328,6 +329,15 @@ public byte getNameTextLength(){ return field_3_length_name_text; } + + /** gets the name length that depends on the unicode flag + * @return raw name length + */ + public byte getRawNameTextLength(){ + return (byte) ( ( ( field_11_compressed_unicode_flag & 0x01 ) == 1 ) + ? 2 * field_3_length_name_text + : field_3_length_name_text ); + } /** get the definition length * @return definition length @@ -532,13 +542,15 @@ 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 { - StringUtil.putCompressedUnicode( getNameText(), data, 19 + offset ); - - } + 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 ); + } Ptg.serializePtgStack(field_13_name_definition, data, start_of_name_definition + offset ); @@ -566,7 +578,7 @@ public int getTextsLength(){ int result; - result = getNameTextLength() + getDescriptionTextLength() + + result = getRawNameTextLength() + getDescriptionTextLength() + getHelpTopicLength() + getStatusBarLength(); @@ -724,19 +736,19 @@ field_8_length_description_text = in.readByte(); field_9_length_help_topic_text = in.readByte(); field_10_length_status_bar_text = in.readByte(); - - //store the name in byte form if it's a builtin name - field_11_compressed_unicode_flag= in.readByte(); - if (this.isBuiltInName()) { - field_12_builtIn_name = in.readByte(); - } else { - if (field_11_compressed_unicode_flag == 1) { - field_12_name_text = in.readCompressedUnicode(field_3_length_name_text); - } else { - field_12_name_text = in.readCompressedUnicode(field_3_length_name_text); - } - } - + + //store the name in byte form if it's a builtin name + field_11_compressed_unicode_flag= in.readByte(); + if (this.isBuiltInName()) { + field_12_builtIn_name = in.readByte(); + } else { + if (field_11_compressed_unicode_flag == 1) { + field_12_name_text = in.readUnicodeLEString(field_3_length_name_text); + } else { + field_12_name_text = in.readCompressedUnicode(field_3_length_name_text); + } + } + field_13_name_definition = Ptg.createParsedExpressionTokens(field_4_length_name_definition, in); //Who says that this can only ever be compressed unicode???
Created attachment 19898 [details] patch
Created attachment 19899 [details] TestCase
Created attachment 19900 [details] TestCase
Thanks for this, applied