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.formula;
112  
113  
114  
115  import org.apache.poi.util.LittleEndian;
116  
117  import org.apache.poi.hssf.util.RangeAddress;
118  
119  
120  
121  /**
122  
123   * Title:        Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
124  
125   * Description:  Defined a area in Extern Sheet. <P>
126  
127   * REFERENCE:  <P>
128  
129   * @author Libin Roman (Vista Portal LDT. Developer)
130  
131   * @version 1.0-pre
132  
133   */
134  
135  
136  
137  public class Area3DPtg extends Ptg
138  
139  {
140  
141      public final static short sid  = 0x3b;
142  
143      private final static int  SIZE = 11; // 10 + 1 for Ptg
144  
145      private short             field_1_index_extern_sheet;  
146  
147      private short             field_2_first_row;
148  
149      private short             field_3_last_row;
150  
151      private short             field_4_first_column;
152  
153      private short             field_5_last_column;
154  
155  
156  
157      /** Creates new AreaPtg */
158  
159  
160  
161      public Area3DPtg()
162  
163      {
164  
165      }
166  
167  
168  
169      public Area3DPtg(byte[] data, int offset)
170  
171      {
172  
173          offset++;
174  
175          field_1_index_extern_sheet = LittleEndian.getShort(data, 0 + offset);
176  
177          field_2_first_row          = LittleEndian.getShort(data, 2 + offset);
178  
179          field_3_last_row           = LittleEndian.getShort(data, 4 + offset);
180  
181          field_4_first_column       = LittleEndian.getShort(data, 6 + offset);
182  
183          field_5_last_column        = LittleEndian.getShort(data, 8 + offset);
184  
185      }
186  
187  
188  
189      public String toString()
190  
191      {
192  
193          StringBuffer buffer = new StringBuffer();
194  
195  
196  
197          buffer.append("AreaPtg\n");
198  
199          buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n");
200  
201          buffer.append("firstRow = " + getFirstRow()).append("\n");
202  
203          buffer.append("lastRow  = " + getLastRow()).append("\n");
204  
205          buffer.append("firstCol = " + getFirstColumn()).append("\n");
206  
207          buffer.append("lastCol  = " + getLastColumn()).append("\n");
208  
209          buffer.append("firstColRowRel= "
210  
211                        + isFirstColRowRelative()).append("\n");
212  
213          buffer.append("lastColRowRel = "
214  
215                        + isLastColRowRelative()).append("\n");
216  
217          buffer.append("firstColRel   = " + isFirstColRelative()).append("\n");
218  
219          buffer.append("lastColRel    = " + isLastColRelative()).append("\n");
220  
221          return buffer.toString();
222  
223      }
224  
225  
226  
227      public void writeBytes(byte [] array, int offset)
228  
229      {
230  
231          array[ 0 + offset ] = sid;
232  
233          LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
234  
235          LittleEndian.putShort(array, 3 + offset , getFirstRow());
236  
237          LittleEndian.putShort(array, 5 + offset , getLastRow());               
238  
239          LittleEndian.putShort(array, 7 + offset , getFirstColumnRaw());               
240  
241          LittleEndian.putShort(array, 9 + offset , getLastColumnRaw());               
242  
243      }
244  
245  
246  
247      public int getSize()
248  
249      {
250  
251          return SIZE;
252  
253      }
254  
255      
256  
257      public short getExternSheetIndex(){
258  
259          return field_1_index_extern_sheet;
260  
261      }
262  
263      
264  
265      public void setExternSheetIndex(short index){
266  
267          field_1_index_extern_sheet = index;
268  
269      }
270  
271  
272  
273      public short getFirstRow()
274  
275      {
276  
277          return field_2_first_row;
278  
279      }
280  
281  
282  
283      public void setFirstRow(short row)
284  
285      {
286  
287          field_2_first_row = row;
288  
289      }
290  
291  
292  
293      public short getLastRow()
294  
295      {
296  
297          return field_3_last_row;
298  
299      }
300  
301  
302  
303      public void setLastRow(short row)
304  
305      {
306  
307          field_3_last_row = row;
308  
309      }
310  
311  
312  
313      public short getFirstColumn()
314  
315      {
316  
317          return ( short ) (field_4_first_column & 0xFF);
318  
319      }
320  
321  
322  
323      public short getFirstColumnRaw()
324  
325      {
326  
327          return field_4_first_column;
328  
329      }
330  
331  
332  
333      public boolean isFirstColRowRelative()
334  
335      {
336  
337          return (((getFirstColumnRaw()) & 0x8000) == 0x8000);
338  
339      }
340  
341  
342  
343      public boolean isFirstColRelative()
344  
345      {
346  
347          return (((getFirstColumnRaw()) & 0x4000) == 0x4000);
348  
349      }
350  
351  
352  
353      public void setFirstColumn(short column)
354  
355      {
356  
357          field_4_first_column &= 0xFF00;
358  
359          field_4_first_column |= column & 0xFF; 
360  
361      }
362  
363  
364  
365      public void setFirstColumnRaw(short column)
366  
367      {
368  
369          field_4_first_column = column;   
370  
371      }
372  
373  
374  
375      public short getLastColumn()
376  
377      {
378  
379          return ( short ) (field_5_last_column & 0xFF);   
380  
381      }
382  
383  
384  
385      public short getLastColumnRaw()
386  
387      {
388  
389          return field_5_last_column;
390  
391      }
392  
393  
394  
395      public boolean isLastColRowRelative()
396  
397      {
398  
399          return (((getLastColumnRaw()) & 0x8000) == 1);
400  
401      }
402  
403  
404  
405      public boolean isLastColRelative()
406  
407      {
408  
409          return (((getFirstColumnRaw()) & 0x4000) == 1);
410  
411      }
412  
413  
414  
415      public void setLastColumn(short column)
416  
417      {
418  
419          field_5_last_column &= 0xFF00;
420  
421          field_5_last_column |= column & 0xFF; 
422  
423      }
424  
425  
426  
427      public void setLastColumnRaw(short column)
428  
429      {
430  
431          field_5_last_column = column;
432  
433      }
434  
435      
436  
437      public String getArea(){
438  
439          RangeAddress ra = new RangeAddress( getFirstColumn(),getFirstRow() + 1, getLastColumn(), getLastRow() + 1);   
440  
441          String result = ra.getAddress();
442  
443          
444  
445          return result;
446  
447      }
448  
449      
450  
451      public void setArea(String ref){
452  
453          RangeAddress ra = new RangeAddress(ref);
454  
455          
456  
457          String from = ra.getFromCell();
458  
459          String to   = ra.getToCell();
460  
461          
462  
463          setFirstColumn((short) (ra.getXPosition(from) -1));
464  
465          setFirstRow((short) (ra.getYPosition(from) -1));
466  
467          setLastColumn((short) (ra.getXPosition(to) -1));
468  
469          setLastRow((short) (ra.getYPosition(to) -1));
470  
471                          
472  
473      }
474  
475  
476  
477      public String toFormulaString()
478  
479      {
480  
481          String result = getArea();
482  
483  
484  
485          return result;
486  
487      }
488  
489  
490  
491      
492  
493  }
494  
495  ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Area3DPtg????????????????????????????????Ptg???????????????????????????????sid???????????????????????????????SIZE??????????????????????????????????????????????????????????????????????????????????????????field_1_index_extern_sheet???????????????????????????????field_2_first_row???????????????????????????????field_3_last_row???????????????????????????????field_4_first_column???????????????????????????????field_5_last_column???????????????????????????????????????????Area3DPtg????????????Area3DPtg?????????offset?????????field_1_index_extern_sheet??????????????????????????????????????LittleEndian???????????????????????????????????????????????????getShort????????????????????????????????????????????????????????????data??????????????????????????????????????????????????????????????????????offset?????????field_2_first_row??????????????????????????????????????LittleEndian???????????????????????????????????????????????????getShort????????????????????????????????????????????????????????????data??????????????????????????????????????????????????????????????????????offset?????????field_3_last_row??????????????????????????????????????LittleEndian???????????????????????????????????????????????????getShort????????????????????????????????????????????????????????????data??????????????????????????????????????????????????????????????????????offset?????????field_4_first_column??????????????????????????????????????LittleEndian???????????????????????????????????????????????????getShort????????????????????????????????????????????????????????????data??????????????????????????????????????????????????????????????????????offset?????????field_5_last_column??????????????????????????????????????LittleEndian???????????????????????????????????????????????????getShort????????????????????????????????????????????????????????????data??????????????????????????????????????????????????????????????????????offset???????????????????toString?????????buffer?????????buffer????????????????????????????????????????????????????getExternSheetIndex?????????buffer???????????????????????????????????????getFirstRow?????????buffer???????????????????????????????????????getLastRow?????????buffer???????????????????????????????????????getFirstColumn?????????buffer???????????????????????????????????????getLastColumn?????????buffer?????????????????????????isFirstColRowRelative?????????buffer?????????????????????????isLastColRowRelative?????????buffer????????????????????????????????????????????isFirstColRelative?????????buffer????????????????????????????????????????????isLastColRelative????????????????buffer?????????????????writeBytes?????????array????????????????????offset???????????????????????????????sid?????????LittleEndian??????????????????????putShort???????????????????????????????array??????????????????????????????????????????offset???????????????????????????????????????????????????getExternSheetIndex?????????LittleEndian??????????????????????putShort???????????????????????????????array??????????????????????????????????????????offset???????????????????????????????????????????????????getFirstRow?????????LittleEndian??????????????????????putShort???????????????????????????????array??????????????????????????????????????????offset???????????????????????????????????????????????????getLastRow?????????LittleEndian??????????????????????putShort???????????????????????????????array??????????????????????????????????????????offset???????????????????????????????????????????????????getFirstColumnRaw?????????LittleEndian??????????????????????putShort???????????????????????????????array??????????????????????????????????????????offset???????????????????????????????????????????????????getLastColumnRaw????????????????getSize????????????????SIZE??????????????????getExternSheetIndex????????????????field_1_index_extern_sheet?????????????????setExternSheetIndex?????????field_1_index_extern_sheet??????????????????????????????????????index??????????????????getFirstRow????????????????field_2_first_row?????????????????setFirstRow?????????field_2_first_row?????????????????????????????row??????????????????getLastRow????????????????field_3_last_row?????????????????setLastRow?????????field_3_last_row????????????????????????????row??????????????????getFirstColumn???????????????????????????field_4_first_column??????????????????getFirstColumnRaw????????????????field_4_first_column????????????????????isFirstColRowRelative???????????????????getFirstColumnRaw????????????????????isFirstColRelative???????????????????getFirstColumnRaw?????????????????setFirstColumn?????????field_4_first_column?????????field_4_first_column?????????????????????????????????column?????????????????setFirstColumnRaw?????????field_4_first_column????????????????????????????????column??????????????????getLastColumn???????????????????????????field_5_last_column??????????????????getLastColumnRaw????????????????field_5_last_column????????????????????isLastColRowRelative???????????????????getLastColumnRaw????????????????????isLastColRelative???????????????????getFirstColumnRaw?????????????????setLastColumn?????????field_5_last_column?????????field_5_last_column????????????????????????????????column?????????????????setLastColumnRaw?????????field_5_last_column???????????????????????????????column???????????????????getArea?????????RangeAddress???????????????????????????????RangeAddress?????????????????????????????????????????????getFirstColumn??????????????????????????????????????????????????????????????getFirstRow?????????????????????????????????????????????????????????????????????????????????getLastColumn??????????????????????????????????????????????????????????????????????????????????????????????????getLastRow?????????????????????????ra????????????????????????????getAddress????????????????result?????????????????setArea?????????RangeAddress???????????????????????????????RangeAddress????????????????????????????????????????????ref???????????????????????ra??????????????????????????getFromCell???????????????????????ra??????????????????????????getToCell?????????setFirstColumn?????????????????????????????????ra????????????????????????????????????getXPosition?????????????????????????????????????????????????from?????????setFirstRow??????????????????????????????ra?????????????????????????????????getYPosition??????????????????????????????????????????????from?????????setLastColumn????????????????????????????????ra???????????????????????????????????getXPosition????????????????????????????????????????????????to?????????setLastRow?????????????????????????????ra????????????????????????????????getYPosition?????????????????????????????????????????????to???????????????????toFormulaString?????????????????????????getArea????????????????result