diff --git a/src/java/org/apache/poi/hssf/model/Workbook.java b/src/java/org/apache/poi/hssf/model/Workbook.java index 8ec742baf..6711e9692 100644 --- a/src/java/org/apache/poi/hssf/model/Workbook.java +++ b/src/java/org/apache/poi/hssf/model/Workbook.java @@ -1996,7 +1996,6 @@ public class Workbook implements Model maxformatid = maxformatid >= (short) 0xa4 ? (short) ( maxformatid + 1 ) : (short) 0xa4; //Starting value from M$ empiracle study. rec.setIndexCode( maxformatid ); rec.setFormatStringLength( (byte) format.length() ); - rec.setUnicodeFlag(StringUtil.isUnicodeFormat(format)); rec.setFormatString( format ); int pos = 0; diff --git a/src/java/org/apache/poi/hssf/record/FormatRecord.java b/src/java/org/apache/poi/hssf/record/FormatRecord.java index 9437c1fa3..30448bb42 100644 --- a/src/java/org/apache/poi/hssf/record/FormatRecord.java +++ b/src/java/org/apache/poi/hssf/record/FormatRecord.java @@ -36,7 +36,7 @@ public class FormatRecord { public final static short sid = 0x41e; private short field_1_index_code; - private short field_2_formatstring_len; + private short field_3_unicode_len; // unicode string length private boolean field_3_unicode_flag; // it is not undocumented - it is unicode flag private String field_4_formatstring; @@ -85,7 +85,7 @@ public class FormatRecord field_1_index_code = LittleEndian.getShort(data, 0 + offset); // field_2_formatstring_len = data[ 2 + offset ]; field_3_unicode_len = LittleEndian.getShort( data, 2 + offset ); - field_2_formatstring_len = field_3_unicode_len; + field_3_unicode_flag = ( data[ 4 + offset ] & (byte)0x01 ) != 0; @@ -120,7 +120,7 @@ public class FormatRecord public void setFormatStringLength(byte len) { - field_2_formatstring_len = len; + field_3_unicode_len = len; } @@ -144,6 +144,7 @@ public class FormatRecord public void setFormatString(String fs) { field_4_formatstring = fs; + setUnicodeFlag(StringUtil.isUnicodeString(fs)); } /** @@ -165,10 +166,10 @@ public class FormatRecord * @see #getFormatString() */ - public short getFormatStringLength() + /* public short getFormatStringLength() { return field_3_unicode_flag ? field_3_unicode_len : field_2_formatstring_len; - } + }*/ /** * get whether the string is unicode diff --git a/src/java/org/apache/poi/util/StringUtil.java b/src/java/org/apache/poi/util/StringUtil.java index 6de79210a..361463312 100644 --- a/src/java/org/apache/poi/util/StringUtil.java +++ b/src/java/org/apache/poi/util/StringUtil.java @@ -322,11 +322,11 @@ public class StringUtil { /** * @param format - * @return true if format is Unicode. + * @return true if string needs Unicode to be represented. */ - public static boolean isUnicodeFormat(final String format) { + public static boolean isUnicodeString(final String value) { try { - return !format.equals(new String(format.getBytes("ISO-8859-1"), "ISO-8859-1")); + return !value.equals(new String(value.getBytes("ISO-8859-1"), "ISO-8859-1")); } catch (UnsupportedEncodingException e) { return true; }