1    
2    
3    /* ====================================================================
4    
5     * The Apache Software License, Version 1.1
6    
7     *
8    
9     * Copyright (c) 2002 The Apache Software Foundation.  All rights
10   
11    * reserved.
12   
13    *
14   
15    * Redistribution and use in source and binary forms, with or without
16   
17    * modification, are permitted provided that the following conditions
18   
19    * are met:
20   
21    *
22   
23    * 1. Redistributions of source code must retain the above copyright
24   
25    *    notice, this list of conditions and the following disclaimer.
26   
27    *
28   
29    * 2. Redistributions in binary form must reproduce the above copyright
30   
31    *    notice, this list of conditions and the following disclaimer in
32   
33    *    the documentation and/or other materials provided with the
34   
35    *    distribution.
36   
37    *
38   
39    * 3. The end-user documentation included with the redistribution,
40   
41    *    if any, must include the following acknowledgment:
42   
43    *       "This product includes software developed by the
44   
45    *        Apache Software Foundation (http://www.apache.org/)."
46   
47    *    Alternately, this acknowledgment may appear in the software itself,
48   
49    *    if and wherever such third-party acknowledgments normally appear.
50   
51    *
52   
53    * 4. The names "Apache" and "Apache Software Foundation" and
54   
55    *    "Apache POI" must not be used to endorse or promote products
56   
57    *    derived from this software without prior written permission. For
58   
59    *    written permission, please contact apache@apache.org.
60   
61    *
62   
63    * 5. Products derived from this software may not be called "Apache",
64   
65    *    "Apache POI", nor may "Apache" appear in their name, without
66   
67    *    prior written permission of the Apache Software Foundation.
68   
69    *
70   
71    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
72   
73    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
74   
75    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
76   
77    * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
78   
79    * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
80   
81    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
82   
83    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
84   
85    * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
86   
87    * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
88   
89    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
90   
91    * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92   
93    * SUCH DAMAGE.
94   
95    * ====================================================================
96   
97    *
98   
99    * This software consists of voluntary contributions made by many
100  
101   * individuals on behalf of the Apache Software Foundation.  For more
102  
103   * information on the Apache Software Foundation, please see
104  
105   * <http://www.apache.org/>.
106  
107   */
108  
109  
110  
111  package org.apache.poi.hssf.record;
112  
113  
114  
115  import org.apache.poi.util.LittleEndian;
116  
117  import org.apache.poi.util.StringUtil;
118  
119  import java.util.Stack;
120  
121  import org.apache.poi.hssf.record.formula.Ptg;
122  
123  import org.apache.poi.hssf.record.formula.Area3DPtg;
124  
125  import org.apache.poi.hssf.record.formula.Ref3DPtg;
126  
127  import java.util.List;
128  
129  import org.apache.poi.hssf.util.RangeAddress;
130  
131  
132  
133  /**
134  
135   * Title:        Name Record (aka Named Range) <P>
136  
137   * Description:  Defines a named range within a workbook. <P>
138  
139   * REFERENCE:  <P>
140  
141   * @author Libin Roman (Vista Portal LDT. Developer)
142  
143   * @version 1.0-pre
144  
145   */
146  
147  
148  
149  public class NameRecord extends Record {
150  
151      /**
152  
153       */
154  
155      public final static short sid = 0x18; //Docs says that it is 0x218
156  
157      private short             field_1_option_flag;
158  
159      private byte              field_2_keyboard_shortcut;
160  
161      private byte              field_3_length_name_text;
162  
163      private short             field_4_length_name_definition;
164  
165      private short             field_5_index_to_sheet;
166  
167      private short             field_6_equals_to_index_to_sheet;
168  
169      private byte              field_7_length_custom_menu;
170  
171      private byte              field_8_length_description_text;
172  
173      private byte              field_9_length_help_topic_text;
174  
175      private byte              field_10_length_status_bar_text;
176  
177      private byte              field_11_compressed_unicode_flag;   // not documented
178  
179      private String            field_12_name_text;
180  
181      private Stack             field_13_name_definition;
182  
183      private String            field_14_custom_menu_text;
184  
185      private String            field_15_description_text;
186  
187      private String            field_16_help_topic_text;
188  
189      private String            field_17_status_bar_text;
190  
191      
192  
193      /** Creates new NameRecord */
194  
195      public NameRecord() {
196  
197          field_13_name_definition = new Stack();
198  
199          
200  
201          field_12_name_text = new String();
202  
203          field_14_custom_menu_text = new String();
204  
205          field_15_description_text = new String();
206  
207          field_16_help_topic_text = new String();
208  
209          field_17_status_bar_text = new String();
210  
211      }
212  
213      
214  
215      /**
216  
217       * Constructs a Name record and sets its fields appropriately.
218  
219       *
220  
221       * @param id     id must be 0x18 or an exception will be throw upon validation
222  
223       * @param size  the size of the data area of the record
224  
225       * @param data  data of the record (should not contain sid/len)
226  
227       */
228  
229      public NameRecord(short id, short size, byte [] data) {
230  
231          super(id, size, data);
232  
233      }
234  
235      
236  
237      /**
238  
239       * Constructs a Name record and sets its fields appropriately.
240  
241       *
242  
243       * @param id     id must be 0x18 or an exception will be throw upon validation
244  
245       * @param size  the size of the data area of the record
246  
247       * @param data  data of the record (should not contain sid/len)
248  
249       * @param offset of the record's data
250  
251       */
252  
253      public NameRecord(short id, short size, byte [] data, int offset) {
254  
255          super(id, size, data, offset);
256  
257      }
258  
259      
260  
261      /** sets the option flag for the named range
262  
263       * @param flag option flag
264  
265       */
266  
267      public void setOptionFlag(short flag){
268  
269          field_1_option_flag = flag;
270  
271      }
272  
273      
274  
275      /** sets the keyboard shortcut
276  
277       * @param shortcut keyboard shortcut
278  
279       */
280  
281      public void setKeyboardShortcut(byte shortcut){
282  
283          field_2_keyboard_shortcut = shortcut;
284  
285      }
286  
287      
288  
289      /** sets the name of the named range length
290  
291       * @param length name length
292  
293       */
294  
295      public void setNameTextLength(byte length){
296  
297          field_3_length_name_text = length;
298  
299      }
300  
301      
302  
303      /** sets the definition (reference - formula) length
304  
305       * @param length defenition length
306  
307       */
308  
309      public void setDefinitionTextLength(short length){
310  
311          field_4_length_name_definition = length;
312  
313      }
314  
315      
316  
317      /** sets the index number to the extern sheet (thats is what writen in ducomentetion
318  
319       *  but as i saw , its work direrent)
320  
321       * @param index extern sheet index
322  
323       */
324  
325      public void setIndexToSheet(short index){
326  
327          field_5_index_to_sheet = index;
328  
329          
330  
331          // field_6_equals_to_index_to_sheet is equal to field_5_index_to_sheet
332  
333          field_6_equals_to_index_to_sheet = index;
334  
335      }
336  
337      
338  
339      /** sets the custom menu length
340  
341       * @param length custom menu length
342  
343       */
344  
345      public void setCustomMenuLength(byte length){
346  
347          field_7_length_custom_menu = length;
348  
349      }
350  
351      
352  
353      /** sets the length of named range description
354  
355       * @param length description length
356  
357       */
358  
359      public void setDescriptionTextLength(byte length){
360  
361          field_8_length_description_text = length;
362  
363      }
364  
365      
366  
367      /** sets the help topic length
368  
369       * @param length help topic length
370  
371       */
372  
373      public void setHelpTopicLength(byte length){
374  
375          field_9_length_help_topic_text = length;
376  
377      }
378  
379      
380  
381      /** sets the length of the status bar text
382  
383       * @param length status bar text length
384  
385       */
386  
387      public void setStatusBarLength(byte length){
388  
389          field_10_length_status_bar_text = length;
390  
391      }
392  
393      
394  
395      /** sets the compressed unicode flag
396  
397       * @param flag unicode flag
398  
399       */
400  
401      public void setCompressedUnicodeFlag(byte flag) {
402  
403          field_11_compressed_unicode_flag = flag;
404  
405      }
406  
407      
408  
409      /** sets the name of the named range
410  
411       * @param name named range name
412  
413       */
414  
415      public void setNameText(String name){
416  
417          field_12_name_text = name;
418  
419      }
420  
421      
422  
423      //    public void setNameDefintion(String definition){
424  
425      //        test = definition;
426  
427      //    }
428  
429      
430  
431      /** sets the custom menu text
432  
433       * @param text custom menu text
434  
435       */
436  
437      public void setCustomMenuText(String text){
438  
439          field_14_custom_menu_text = text;
440  
441      }
442  
443      
444  
445      /** sets the description text
446  
447       * @param text the description text
448  
449       */
450  
451      public void setDescriptionText(String text){
452  
453          field_15_description_text = text;
454  
455      }
456  
457      
458  
459      /** sets the help topic text
460  
461       * @param text help topix text
462  
463       */
464  
465      public void setHelpTopicText(String text){
466  
467          field_16_help_topic_text = text;
468  
469      }
470  
471      
472  
473      /** sets the status bar text
474  
475       * @param text status bar text
476  
477       */
478  
479      public void setStatusBarText(String text){
480  
481          field_17_status_bar_text = text;
482  
483      }
484  
485      
486  
487      /** gets the option flag
488  
489       * @return option flag
490  
491       */
492  
493      public short getOptionFlag(){
494  
495          return field_1_option_flag;
496  
497      }
498  
499      
500  
501      /** returns the keyboard shortcut
502  
503       * @return keyboard shortcut
504  
505       */
506  
507      public byte getKeyboardShortcut(){
508  
509          return field_2_keyboard_shortcut ;
510  
511      }
512  
513      
514  
515      /** gets the name length
516  
517       * @return name length
518  
519       */
520  
521      public byte getNameTextLength(){
522  
523          return field_3_length_name_text;
524  
525      }
526  
527      
528  
529      /** get the definition length
530  
531       * @return definition length
532  
533       */
534  
535      public short getDefinitionTextLength(){
536  
537          return field_4_length_name_definition;
538  
539      }
540  
541      
542  
543      /** gets the index to extern sheet
544  
545       * @return index to extern sheet
546  
547       */
548  
549      public short getIndexToSheet(){
550  
551          return field_5_index_to_sheet;
552  
553      }
554  
555      
556  
557      /** gets the custom menu length
558  
559       * @return custom menu length
560  
561       */
562  
563      public byte getCustomMenuLength(){
564  
565          return field_7_length_custom_menu;
566  
567      }
568  
569      
570  
571      /** gets the description text length
572  
573       * @return description text length
574  
575       */
576  
577      public byte getDescriptionTextLength(){
578  
579          return field_8_length_description_text;
580  
581      }
582  
583      
584  
585      /** gets the help topic length
586  
587       * @return help topic length
588  
589       */
590  
591      public byte getHelpTopicLength(){
592  
593          return field_9_length_help_topic_text;
594  
595      }
596  
597      
598  
599      /** get the status bar text length
600  
601       * @return satus bar length
602  
603       */
604  
605      public byte getStatusBarLength(){
606  
607          return field_10_length_status_bar_text;
608  
609      }
610  
611      
612  
613      /** gets the name compressed Unicode flag
614  
615       * @return compressed unicode flag
616  
617       */
618  
619      public byte getCompressedUnicodeFlag() {
620  
621          return field_11_compressed_unicode_flag;
622  
623      }
624  
625      
626  
627      /** gets the name
628  
629       * @return name
630  
631       */
632  
633      public String getNameText(){
634  
635          return field_12_name_text;
636  
637      }
638  
639      
640  
641      /** gets the definition, reference (Formula)
642  
643       * @return definition
644  
645       */
646  
647      public List getNameDefinition() {
648  
649          return ( List ) field_13_name_definition;
650  
651      }
652  
653      
654  
655      /** get the custom menu text
656  
657       * @return custom menu text
658  
659       */
660  
661      public String getCustomMenuText(){
662  
663          return field_14_custom_menu_text;
664  
665      }
666  
667      
668  
669      /** gets the description text
670  
671       * @return description text
672  
673       */
674  
675      public String getDescriptionText(){
676  
677          return field_15_description_text;
678  
679      }
680  
681      
682  
683      /** get the help topic text
684  
685       * @return gelp topic text
686  
687       */
688  
689      public String getHelpTopicText(){
690  
691          return field_16_help_topic_text;
692  
693      }
694  
695      
696  
697      /** gets the status bar text
698  
699       * @return status bar text
700  
701       */
702  
703      public String getStatusBarText(){
704  
705          return field_17_status_bar_text;
706  
707      }
708  
709      
710  
711      /**
712  
713       * called by constructor, should throw runtime exception in the event of a
714  
715       * record passed with a differing ID.
716  
717       *
718  
719       * @param id alleged id for this record
720  
721       */
722  
723      protected void validateSid(short id) {
724  
725          if (id != sid) {
726  
727              throw new RecordFormatException("NOT A valid Name RECORD");
728  
729          }
730  
731      }
732  
733      
734  
735      /**
736  
737       * called by the class that is responsible for writing this sucker.
738  
739       * Subclasses should implement this so that their data is passed back in a
740  
741       * byte array.
742  
743       *
744  
745       * @param offset to begin writing at
746  
747       * @param data byte array containing instance data
748  
749       * @return number of bytes written
750  
751       */
752  
753      public int serialize(int offset, byte[] data) {
754  
755          LittleEndian.putShort(data, 0 + offset, sid);
756  
757          LittleEndian.putShort(data, 2 + offset, (short)( 15 + getTextsLength()));
758  
759          LittleEndian.putShort(data, 4 + offset, getOptionFlag());
760  
761          data[6 + offset] = getKeyboardShortcut();
762  
763          data[7 + offset] = getNameTextLength();
764  
765          LittleEndian.putShort(data, 8 + offset, getDefinitionTextLength());
766  
767          LittleEndian.putShort(data, 10 + offset, getIndexToSheet());
768  
769          LittleEndian.putShort(data, 12 + offset, getIndexToSheet());
770  
771          data [14 + offset] =  getCustomMenuLength();
772  
773          data [15 + offset] =  getDescriptionTextLength();
774  
775          data [16 + offset] =  getHelpTopicLength();
776  
777          data [17 + offset] =  getStatusBarLength();
778  
779          data [18 + offset] =  getCompressedUnicodeFlag();
780  
781          
782  
783          StringUtil.putCompressedUnicode(getNameText(), data , 19 + offset);
784  
785          
786  
787          int start_of_name_definition    = 19  + field_3_length_name_text;
788  
789          serializePtgs(data, start_of_name_definition + offset);        
790  
791          
792  
793          int start_of_custom_menu_text   = start_of_name_definition + field_4_length_name_definition;
794  
795          StringUtil.putCompressedUnicode(getCustomMenuText(), data , start_of_custom_menu_text + offset);
796  
797          
798  
799          int start_of_description_text   = start_of_custom_menu_text + field_8_length_description_text;
800  
801          StringUtil.putCompressedUnicode(getDescriptionText(), data , start_of_description_text + offset);
802  
803          
804  
805          int start_of_help_topic_text    = start_of_description_text + field_9_length_help_topic_text;
806  
807          StringUtil.putCompressedUnicode(getHelpTopicText(), data , start_of_help_topic_text + offset);
808  
809          
810  
811          int start_of_status_bar_text       = start_of_help_topic_text + field_10_length_status_bar_text;
812  
813          StringUtil.putCompressedUnicode(getStatusBarText(), data , start_of_status_bar_text + offset);
814  
815          
816  
817          
818  
819          return getRecordSize();
820  
821      }
822  
823      
824  
825      private void serializePtgs(byte [] data, int offset) {
826  
827          int pos = offset;
828  
829          
830  
831          for (int k = 0; k < field_13_name_definition.size(); k++) {
832  
833              Ptg ptg = ( Ptg ) field_13_name_definition.get(k);
834  
835              
836  
837              ptg.writeBytes(data, pos);
838  
839              pos += ptg.getSize();
840  
841          }
842  
843      }
844  
845      
846  
847      
848  
849      /** gets the length of all texts
850  
851       * @return total length
852  
853       */
854  
855      public int getTextsLength(){
856  
857          int result;
858  
859          
860  
861          result = getNameTextLength() + getDefinitionTextLength() + getDescriptionTextLength() +
862  
863          getHelpTopicLength() + getStatusBarLength();
864  
865          
866  
867          
868  
869          return result;
870  
871      }
872  
873      
874  
875      /** returns the record size
876  
877       */
878  
879      public int getRecordSize(){
880  
881          int result;
882  
883          
884  
885          result = 19 + getTextsLength();
886  
887          
888  
889          return result;
890  
891      }
892  
893      
894  
895      /** gets the extern sheet number
896  
897       * @return extern sheet index
898  
899       */
900  
901      public short getExternSheetNumber(){
902  
903          Ptg ptg = (Ptg) field_13_name_definition.peek();
904  
905          short result = 0;
906  
907          
908  
909          if (ptg.getClass() == Area3DPtg.class){
910  
911              result = ((Area3DPtg) ptg).getExternSheetIndex();
912  
913              
914  
915          } else if (ptg.getClass() == Ref3DPtg.class){
916  
917              result = ((Ref3DPtg) ptg).getExternSheetIndex();
918  
919          }
920  
921          
922  
923          return result;
924  
925      }
926  
927      
928  
929      /** sets the extern sheet number
930  
931       * @param externSheetNumber extern sheet number
932  
933       */
934  
935      public void setExternSheetNumber(short externSheetNumber){
936  
937          Ptg ptg;
938  
939          
940  
941          if (field_13_name_definition.isEmpty()){
942  
943              ptg = createNewPtg();
944  
945          } else {
946  
947              ptg = (Ptg) field_13_name_definition.peek();
948  
949          }
950  
951          
952  
953          if (ptg.getClass() == Area3DPtg.class){
954  
955              ((Area3DPtg) ptg).setExternSheetIndex(externSheetNumber);
956  
957              
958  
959          } else if (ptg.getClass() == Ref3DPtg.class){
960  
961              ((Ref3DPtg) ptg).setExternSheetIndex(externSheetNumber);
962  
963          }
964  
965          
966  
967      }
968  
969      
970  
971      private Ptg createNewPtg(){
972  
973          Ptg ptg = new Area3DPtg();
974  
975          field_13_name_definition.push(ptg);
976  
977          
978  
979          return ptg;
980  
981      }
982  
983      
984  
985      /** gets the reference , the area only (range)
986  
987       * @return area reference
988  
989       */
990  
991      public String getAreaReference(){
992  
993          Ptg ptg = (Ptg) field_13_name_definition.peek();
994  
995          String result = "";
996  
997          
998  
999          if (ptg.getClass() == Area3DPtg.class){
1000 
1001             result = ((Area3DPtg) ptg).getArea();
1002 
1003             
1004 
1005         } else if (ptg.getClass() == Ref3DPtg.class){
1006 
1007             result = ((Ref3DPtg) ptg).getArea();
1008 
1009         }
1010 
1011         
1012 
1013         return result;
1014 
1015     }
1016 
1017     
1018 
1019     /** sets the reference , the area only (range)
1020 
1021      * @param ref area reference
1022 
1023      */
1024 
1025     public void setAreaReference(String ref){
1026 
1027         //Trying to find if what ptg do we need
1028 
1029         RangeAddress ra = new RangeAddress(ref);
1030 
1031         Ptg oldPtg;
1032 
1033         Ptg ptg;
1034 
1035         
1036 
1037         if (field_13_name_definition.isEmpty()){
1038 
1039             oldPtg = createNewPtg();
1040 
1041         } else {
1042 
1043             //Trying to find extern sheet index
1044 
1045             oldPtg = (Ptg) field_13_name_definition.pop();
1046 
1047         }
1048 
1049         
1050 
1051         short externSheetIndex = 0;
1052 
1053         
1054 
1055         if (oldPtg.getClass() == Area3DPtg.class){
1056 
1057             externSheetIndex =  ((Area3DPtg) oldPtg).getExternSheetIndex();
1058 
1059             
1060 
1061         } else if (oldPtg.getClass() == Ref3DPtg.class){
1062 
1063             externSheetIndex =  ((Ref3DPtg) oldPtg).getExternSheetIndex();
1064 
1065         }
1066 
1067         
1068 
1069         if (ra.hasRange()) {
1070 
1071             ptg = new Area3DPtg();
1072 
1073             ((Area3DPtg) ptg).setExternSheetIndex(externSheetIndex);
1074 
1075             ((Area3DPtg) ptg).setArea(ref);
1076 
1077             this.setDefinitionTextLength((short)((Area3DPtg) ptg).getSize());
1078 
1079         } else {
1080 
1081             ptg = new Ref3DPtg();
1082 
1083             ((Ref3DPtg) ptg).setExternSheetIndex(externSheetIndex);
1084 
1085             ((Ref3DPtg) ptg).setArea(ref);
1086 
1087             this.setDefinitionTextLength((short)((Ref3DPtg) ptg).getSize());
1088 
1089         }
1090 
1091         
1092 
1093         field_13_name_definition.push(ptg);
1094 
1095         
1096 
1097     }
1098 
1099     
1100 
1101     /**
1102 
1103      * called by the constructor, should set class level fields.  Should throw
1104 
1105      * runtime exception for bad/icomplete data.
1106 
1107      *
1108 
1109      * @param data raw data
1110 
1111      * @param size size of data
1112 
1113      * @param offset of the record's data (provided a big array of the file)
1114 
1115      */
1116 
1117     protected void fillFields(byte[] data, short size, int offset) {
1118 
1119         field_1_option_flag             = LittleEndian.getShort(data, 0 + offset);
1120 
1121         field_2_keyboard_shortcut       = data [2 + offset];
1122 
1123         field_3_length_name_text        = data [3 + offset];
1124 
1125         field_4_length_name_definition  = LittleEndian.getShort(data, 4 + offset);
1126 
1127         field_5_index_to_sheet          = LittleEndian.getShort(data, 6 + offset);
1128 
1129         field_6_equals_to_index_to_sheet= LittleEndian.getShort(data, 8 + offset);
1130 
1131         field_7_length_custom_menu      = data [10 + offset];
1132 
1133         field_8_length_description_text = data [11 + offset];
1134 
1135         field_9_length_help_topic_text  = data [12 + offset];
1136 
1137         field_10_length_status_bar_text = data [13 + offset];
1138 
1139         
1140 
1141         field_11_compressed_unicode_flag= data [14 + offset];
1142 
1143         field_12_name_text = new String(data, 15 + offset,
1144 
1145         LittleEndian.ubyteToInt(field_3_length_name_text));
1146 
1147         
1148 
1149         int start_of_name_definition    = 15 + field_3_length_name_text;
1150 
1151         field_13_name_definition = getParsedExpressionTokens(data, field_4_length_name_definition,
1152 
1153         offset, start_of_name_definition);
1154 
1155         
1156 
1157         int start_of_custom_menu_text   = start_of_name_definition + field_4_length_name_definition;
1158 
1159         field_14_custom_menu_text       = new String(data, start_of_custom_menu_text + offset,
1160 
1161         LittleEndian.ubyteToInt(field_7_length_custom_menu));
1162 
1163         
1164 
1165         int start_of_description_text   = start_of_custom_menu_text + field_8_length_description_text;
1166 
1167         field_15_description_text       = new String(data, start_of_description_text + offset,
1168 
1169         LittleEndian.ubyteToInt(field_8_length_description_text));
1170 
1171         
1172 
1173         int start_of_help_topic_text    = start_of_description_text + field_9_length_help_topic_text;
1174 
1175         field_16_help_topic_text        = new String(data, start_of_help_topic_text + offset,
1176 
1177         LittleEndian.ubyteToInt(field_9_length_help_topic_text));
1178 
1179         
1180 
1181         int start_of_status_bar_text       = start_of_help_topic_text + field_10_length_status_bar_text;
1182 
1183         field_17_status_bar_text        = new String(data, start_of_status_bar_text +  offset,
1184 
1185         LittleEndian.ubyteToInt(field_10_length_status_bar_text));
1186 
1187         
1188 
1189     }
1190 
1191     
1192 
1193     private Stack getParsedExpressionTokens(byte [] data, short size,
1194 
1195     int offset, int start_of_expression) {
1196 
1197         Stack stack = new Stack();
1198 
1199         int   pos           = start_of_expression + offset;
1200 
1201         int   sizeCounter   = 0;
1202 
1203         
1204 
1205         while (sizeCounter < size) {
1206 
1207             Ptg ptg = Ptg.createPtg(data, pos);
1208 
1209             
1210 
1211             pos += ptg.getSize();
1212 
1213             sizeCounter += ptg.getSize();
1214 
1215             stack.push(ptg);
1216 
1217         }
1218 
1219         return stack;
1220 
1221     }
1222 
1223     
1224 
1225     
1226 
1227     /**
1228 
1229      * return the non static version of the id for this record.
1230 
1231      */
1232 
1233     public short getSid() {
1234 
1235         return this.sid;
1236 
1237     }
1238 
1239     
1240 
1241 }
1242 
1243 ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????NameRecord?????????????????????????????????Record????????????????????????????????????????????????sid??????????????????????????????????????????????????????????????????????????????????????????????????????field_1_option_flag???????????????????????????????field_2_keyboard_shortcut???????????????????????????????field_3_length_name_text???????????????????????????????field_4_length_name_definition???????????????????????????????field_5_index_to_sheet???????????????????????????????field_6_equals_to_index_to_sheet???????????????????????????????field_7_length_custom_menu???????????????????????????????field_8_length_description_text???????????????????????????????field_9_length_help_topic_text???????????????????????????????field_10_length_status_bar_text???????????????????????????????field_11_compressed_unicode_flag???????????????????????????????????????????????????????????????????????????????????????????????????????????????????field_12_name_text???????????????????????????????field_13_name_definition???????????????????????????????field_14_custom_menu_text???????????????????????????????field_15_description_text???????????????????????????????field_16_help_topic_text???????????????????????????????field_17_status_bar_text??????????????????????????????????????????????NameRecord???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????NameRecord???????????????id???????????????????size?????????????????????????data??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????NameRecord???????????????id???????????????????size?????????????????????????data???????????????????????????????offset???????????????????????????????????????????????????????????????????????????????????????????????????????????setOptionFlag?????????field_1_option_flag???????????????????????????????flag???????????????????????????????????????????????????????????????????????????????????????????????????????setKeyboardShortcut?????????field_2_keyboard_shortcut?????????????????????????????????????shortcut????????????????????????????????????????????????????????????????????????????????????????????????????????????setNameTextLength????????????????????????????????????length???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????setDefinitionTextLength?????????field_4_length_name_definition??????????????????????????????????????????length??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????setIndexToSheet?????????field_5_index_to_sheet??????????????????????????????????index????????????????????????????????????????????????????????????????????????????????????????field_6_equals_to_index_to_sheet????????????????????????????????????????????index???????????????????????????????????????????????????????????????????????????????????????????????????????setCustomMenuLength?????????field_7_length_custom_menu??????????????????????????????????????length??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????setDescriptionTextLength?????????field_8_length_description_text???????????????????????????????????????????length?????????????????????????????????????????????????????????????????????????????????????????????????????setHelpTopicLength?????????field_9_length_help_topic_text??????????????????????????????????????????length??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????setStatusBarLength?????????field_10_length_status_bar_text???????????????????????????????????????????length????????????????????????????????????????????????????????????????????????????????????????????????????setCompressedUnicodeFlag?????????field_11_compressed_unicode_flag????????????????????????????????????????????flag????????????????????????????????????????????????????????????????????????????????????????????????????????setNameText??????????????????????????????name?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????setCustomMenuText?????????field_14_custom_menu_text?????????????????????????????????????text?????????????????????????????????????????????????????????????????????????????????????????????????????setDescriptionText?????????field_15_description_text?????????????????????????????????????text???????????????????????????????????????????????????????????????????????????????????????????????setHelpTopicText?????????field_16_help_topic_text????????????????????????????????????text???????????????????????????????????????????????????????????????????????????????????????????????setStatusBarText?????????field_17_status_bar_text????????????????????????????????????text????????????????????????????????????????????????????????????????????????????????????getOptionFlag????????????????field_1_option_flag??????????????????????????????????????????????????????????????????????????????????????????????????getKeyboardShortcut????????????????field_2_keyboard_shortcut???????????????????????????????????????????????????????????????????????????????????getNameTextLength????????????????field_3_length_name_text???????????????????????????????????????????????????????????????????????????????????????????????getDefinitionTextLength????????????????field_4_length_name_definition????????????????????????????????????????????????????????????????????????????????????????????????????????getIndexToSheet????????????????field_5_index_to_sheet?????????????????????????????????????????????????????????????????????????????????????????????????getCustomMenuLength????????????????field_7_length_custom_menu???????????????????????????????????????????????????????????????????????????????????????????????????????????getDescriptionTextLength????????????????field_8_length_description_text???????????????????????????????????????????????????????????????????????????????????????????????getHelpTopicLength????????????????field_9_length_help_topic_text??????????????????????????????????????????????????????????????????????????????????????????????????getStatusBarLength????????????????field_10_length_status_bar_text????????????????????????????????????????????????????????????????????????????????????????????????????????????????getCompressedUnicodeFlag????????????????field_11_compressed_unicode_flag???????????????????????????????????????????????????????????????????????getNameText??????????????????????????????????????????????????????????????????????????????????????????????????????getNameDefinition?????????????????????????field_13_name_definition??????????????????????????????????????????????????????????????????????????????????????????????getCustomMenuText????????????????field_14_custom_menu_text???????????????????????????????????????????????????????????????????????????????????????????????getDescriptionText????????????????field_15_description_text????????????????????????????????????????????????????????????????????????????????????????????getHelpTopicText????????????????field_16_help_topic_text?????????????????????????????????????????????????????????????????????????????????????????????getStatusBarText????????????????field_17_status_bar_text?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????validateSid?????????????id???????????????????sid????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????serialize?????????LittleEndian??????????????????????putShort???????????????????????????????data?????????????????????????????????????????offset?????????????????????????????????????????????????sid?????????LittleEndian??????????????????????putShort???????????????????????????????data?????????????????????????????????????????offset???????????????????????????????????????????????????????????????getTextsLength?????????LittleEndian??????????????????????putShort???????????????????????????????data?????????????????????????????????????????offset?????????????????????????????????????????????????getOptionFlag?????????data??????????????????offset????????????????????????????getKeyboardShortcut?????????data??????????????????offset????????????????????????????getNameTextLength?????????LittleEndian??????????????????????putShort???????????????????????????????data?????????????????????????????????????????offset?????????????????????????????????????????????????getDefinitionTextLength?????????LittleEndian??????????????????????putShort???????????????????????????????data??????????????????????????????????????????offset??????????????????????????????????????????????????getIndexToSheet?????????LittleEndian??????????????????????putShort???????????????????????????????data??????????????????????????????????????????offset??????????????????????????????????????????????????getIndexToSheet?????????data????????????????????offset???????????????????????????????getCustomMenuLength?????????data????????????????????offset???????????????????????????????getDescriptionTextLength?????????data????????????????????offset???????????????????????????????getHelpTopicLength?????????data????????????????????offset???????????????????????????????getStatusBarLength?????????data????????????????????offset???????????????????????????????getCompressedUnicodeFlag?????????StringUtil????????????????????putCompressedUnicode?????????????????????????????????????????getNameText????????????????????????????????????????????????????????data????????????????????????????????????????????????????????????????????offset?????????????????????????????????????????????????field_3_length_name_text?????????serializePtgs???????????????????????data?????????????????????????????start_of_name_definition????????????????????????????????????????????????????????offset???????????????????????????????????????????start_of_name_definition??????????????????????????????????????????????????????????????????????field_4_length_name_definition?????????StringUtil????????????????????putCompressedUnicode?????????????????????????????????????????getCustomMenuText??????????????????????????????????????????????????????????????data?????????????????????????????????????????????????????????????????????start_of_custom_menu_text?????????????????????????????????????????????????????????????????????????????????????????????????offset???????????????????????????????????????????start_of_custom_menu_text???????????????????????????????????????????????????????????????????????field_8_length_description_text?????????StringUtil????????????????????putCompressedUnicode?????????????????????????????????????????getDescriptionText???????????????????????????????????????????????????????????????data??????????????????????????????????????????????????????????????????????start_of_description_text??????????????????????????????????????????????????????????????????????????????????????????????????offset???????????????????????????????????????????start_of_description_text???????????????????????????????????????????????????????????????????????field_9_length_help_topic_text?????????StringUtil????????????????????putCompressedUnicode?????????????????????????????????????????getHelpTopicText?????????????????????????????????????????????????????????????data????????????????????????????????????????????????????????????????????start_of_help_topic_text???????????????????????????????????????????????????????????????????????????????????????????????offset??????????????????????????????????????????????start_of_help_topic_text?????????????????????????????????????????????????????????????????????????field_10_length_status_bar_text?????????StringUtil????????????????????putCompressedUnicode?????????????????????????????????????????getStatusBarText?????????????????????????????????????????????????????????????data????????????????????????????????????????????????????????????????????start_of_status_bar_text???????????????????????????????????????????????????????????????????????????????????????????????offset????????????????getRecordSize??????????????????serializePtgs???????????????????offset?????????????????????????k?????????????????????????????field_13_name_definition??????????????????????????????????????????????????????????????k?????????????Ptg?????????????????????????Ptg???????????????????????????????field_13_name_definition????????????????????????????????????????????????????????????k?????????????ptg?????????????????writeBytes????????????????????????????data??????????????????????????????????pos?????????????pos????????????????????ptg????????????????????????getSize???????????????????????????????????????????????????????????????????????????????????????????getTextsLength?????????result??????????????????getNameTextLength????????????????????????????????????????getDefinitionTextLength????????????????????????????????????????????????????????????????????getDescriptionTextLength?????????getHelpTopicLength????????????????????????????????getStatusBarLength????????????????result?????????????????????????????????????????????????????????getRecordSize?????????result???????????????????????getTextsLength????????????????result???????????????????????????????????????????????????????????????????????????????????????????????????getExternSheetNumber?????????Ptg?????????????ptg?????????????result???????????????????????????????????ptg????????????????????ptg?????????????result??????????????????????????????????ptg????????????????result????????????????????????????????????????????????????????????????????????????????????????????????????????????????????setExternSheetNumber?????????Ptg?????????????ptg?????????????ptg?????????????ptg??????????????????????????ptg???????????????????????????????????????????????????externSheetNumber????????????????????ptg?????????????????????????ptg??????????????????????????????????????????????????externSheetNumber?????????????Ptg?????????????????createNewPtg?????????Ptg???????????????????????Area3DPtg?????????field_13_name_definition???????????????????????????????????????ptg????????????????ptg??????????????????????????????????????????????????????????????????????????????????????????????????????????????getAreaReference?????????Ptg?????????????ptg?????????????result???????????????????????????????????ptg????????????????????ptg?????????????result??????????????????????????????????ptg????????????????result???????????????????????????????????????????????????????????????????????????????????????????????????????????????setAreaReference?????????????????????????????????????????????????????????RangeAddress???????????????????????????????RangeAddress????????????????????????????????????????????ref?????????Ptg?????????Ptg?????????????oldPtg?????????????????????????????????????????????????????????????oldPtg?????????????oldPtg?????????????externSheetIndex??????????????????????????????????????????????oldPtg????????????????????oldPtg?????????????externSheetIndex?????????????????????????????????????????????oldPtg?????????????ra????????????????hasRange?????????????ptg??????????????????????????ptg???????????????????????????????????????????????????externSheetIndex??????????????????????????ptg???????????????????????????????????????ref??????????????????????????????????????????????????????????????ptg?????????????ptg?????????????????????????ptg??????????????????????????????????????????????????externSheetIndex?????????????????????????ptg??????????????????????????????????????ref?????????????????????????????????????????????????????????????ptg???????????????????????????????????????ptg???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????fillFields?????????field_1_option_flag???????????????????????????????????????????LittleEndian????????????????????????????????????????????????????????getShort?????????????????????????????????????????????????????????????????data???????????????????????????????????????????????????????????????????????????offset?????????field_2_keyboard_shortcut???????????????????????????????????????????data?????????????????????????????????????????????????????offset?????????field_3_length_name_text???????????????????????????????????????????data?????????????????????????????????????????????????????offset?????????field_4_length_name_definition???????????????????????????????????????????LittleEndian????????????????????????????????????????????????????????getShort?????????????????????????????????????????????????????????????????data???????????????????????????????????????????????????????????????????????????offset?????????field_5_index_to_sheet???????????????????????????????????????????LittleEndian????????????????????????????????????????????????????????getShort?????????????????????????????????????????????????????????????????data???????????????????????????????????????????????????????????????????????????offset?????????field_6_equals_to_index_to_sheet???????????????????????????????????????????LittleEndian????????????????????????????????????????????????????????getShort?????????????????????????????????????????????????????????????????data???????????????????????????????????????????????????????????????????????????offset?????????field_7_length_custom_menu???????????????????????????????????????????data??????????????????????????????????????????????????????offset?????????field_8_length_description_text???????????????????????????????????????????data??????????????????????????????????????????????????????offset?????????field_9_length_help_topic_text???????????????????????????????????????????data??????????????????????????????????????????????????????offset?????????field_10_length_status_bar_text???????????????????????????????????????????data??????????????????????????????????????????????????????offset?????????field_11_compressed_unicode_flag???????????????????????????????????????????data??????????????????????????????????????????????????????offset?????????field_12_name_text?????????????????????????????????????????data????????????????????????????????????????????????????offset?????????LittleEndian??????????????????????ubyteToInt?????????????????????????????????field_3_length_name_text????????????????????????????????????????????????field_3_length_name_text?????????field_13_name_definition????????????????????????????????????getParsedExpressionTokens??????????????????????????????????????????????????????????????data????????????????????????????????????????????????????????????????????field_4_length_name_definition?????????offset?????????????????start_of_name_definition???????????????????????????????????????????start_of_name_definition??????????????????????????????????????????????????????????????????????field_4_length_name_definition?????????field_14_custom_menu_text??????????????????????????????????????????????????????data????????????????????????????????????????????????????????????start_of_custom_menu_text????????????????????????????????????????????????????????????????????????????????????????offset?????????LittleEndian??????????????????????ubyteToInt?????????????????????????????????field_7_length_custom_menu???????????????????????????????????????????start_of_custom_menu_text???????????????????????????????????????????????????????????????????????field_8_length_description_text?????????field_15_description_text??????????????????????????????????????????????????????data????????????????????????????????????????????????????????????start_of_description_text????????????????????????????????????????????????????????????????????????????????????????offset?????????LittleEndian??????????????????????ubyteToInt?????????????????????????????????field_8_length_description_text???????????????????????????????????????????start_of_description_text???????????????????????????????????????????????????????????????????????field_9_length_help_topic_text?????????field_16_help_topic_text??????????????????????????????????????????????????????data????????????????????????????????????????????????????????????start_of_help_topic_text???????????????????????????????????????????????????????????????????????????????????????offset?????????LittleEndian??????????????????????ubyteToInt?????????????????????????????????field_9_length_help_topic_text??????????????????????????????????????????????start_of_help_topic_text?????????????????????????????????????????????????????????????????????????field_10_length_status_bar_text?????????field_17_status_bar_text??????????????????????????????????????????????????????data????????????????????????????????????????????????????????????start_of_status_bar_text????????????????????????????????????????????????????????????????????????????????????????offset?????????LittleEndian??????????????????????ubyteToInt?????????????????????????????????field_10_length_status_bar_text???????????????????getParsedExpressionTokens???????????????????????????????start_of_expression?????????????????????????????????????????????????????offset????????????????sizeCounter??????????????????????????????size?????????????Ptg???????????????????????Ptg???????????????????????????createPtg?????????????????????????????????????data???????????????????????????????????????????pos?????????????pos????????????????????ptg????????????????????????getSize?????????????sizeCounter????????????????????????????ptg????????????????????????????????getSize?????????????stack????????????????????????ptg????????????????stack????????????????????????????????????????????????????????????????????????????????????????????????????getSid