]> source.dussan.org Git - poi.git/commitdiff
Support for unicode named named ranges (patch and test from bug #42033)
authorNick Burch <nick@apache.org>
Tue, 8 Jan 2008 17:49:08 +0000 (17:49 +0000)
committerNick Burch <nick@apache.org>
Tue, 8 Jan 2008 17:49:08 +0000 (17:49 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@610082 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/NameRecord.java
src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java

index ff7a3972901bac29faf8da9fa8883e089512d941..59bd2eab7a3bc6b632a103c6a1230d04e38aed90 100644 (file)
@@ -36,6 +36,7 @@
 
                <!-- 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>
index 575bb6ba33adf4403d5e0754593e203ec9388a81..584482100837ff181e7b5e98b760e42f1f3a0a73 100644 (file)
@@ -33,6 +33,7 @@
        <!-- 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>
index 0d0d7f1cda9eec9c43ead19e97b609dd929d6dfd..3b1c413d58052c702ea05e33d697d7c94c3868cb 100644 (file)
@@ -270,6 +270,9 @@ public class NameRecord extends Record {
      */
     public void setNameText(String name){
         field_12_name_text = name;
+        setCompressedUnicodeFlag(
+               StringUtil.hasMultibyte(name) ? (byte)1 : (byte)0
+        );
     }
 
     //    public void setNameDefintion(String definition){
@@ -318,12 +321,24 @@ public class NameRecord extends Record {
         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
@@ -511,27 +526,16 @@ public class NameRecord extends Record {
         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 );
-                               
                        }
 
 
@@ -554,15 +558,15 @@ public class NameRecord extends Record {
         /* } */
     }
 
-    /** 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;
     }
index 8af9b2f3cf799d79c37148493c04a9216d45fdaa..f804822d24bc419684ecee442c46889e0416be52 100644 (file)
@@ -26,6 +26,8 @@ import org.apache.poi.hssf.util.CellReference;
 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;
@@ -316,7 +318,23 @@ public class TestNamedRange
                 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