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:        Reference 3D Ptg <P>
124  
125   * Description:  Defined a cell 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 Ref3DPtg extends Ptg {
138  
139      public final static short sid  = 0x3a;
140  
141      private final static int  SIZE = 7; // 6 + 1 for Ptg
142  
143      private short             field_1_index_extern_sheet;
144  
145      private short             field_2_row;
146  
147      private short             field_3_column;
148  
149      
150  
151      /** Creates new AreaPtg */
152  
153      
154  
155      public Ref3DPtg() {
156  
157      }
158  
159      
160  
161      public Ref3DPtg(byte[] data, int offset) {
162  
163          offset++;
164  
165          field_1_index_extern_sheet = LittleEndian.getShort(data, 0 + offset);
166  
167          field_2_row          = LittleEndian.getShort(data, 2 + offset);
168  
169          field_3_column        = LittleEndian.getShort(data, 4 + offset);
170  
171      }
172  
173      
174  
175      public String toString() {
176  
177          StringBuffer buffer = new StringBuffer();
178  
179          
180  
181          buffer.append("Ref3dPrg\n");
182  
183          buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n");
184  
185          buffer.append("Row = " + getRow()).append("\n");
186  
187          buffer.append("Col  = " + getColumn()).append("\n");
188  
189          buffer.append("ColRowRel= "
190  
191          + isColRowRelative()).append("\n");
192  
193          buffer.append("ColRel   = " + isColRelative()).append("\n");
194  
195          return buffer.toString();
196  
197      }
198  
199      
200  
201      public void writeBytes(byte [] array, int offset) {
202  
203          array[ 0 + offset ] = sid;
204  
205          LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
206  
207          LittleEndian.putShort(array, 3 + offset , getRow());
208  
209          LittleEndian.putShort(array, 5 + offset , getColumnRaw());               
210  
211      }
212  
213      
214  
215      public int getSize() {
216  
217          return SIZE;
218  
219      }
220  
221      
222  
223      public short getExternSheetIndex(){
224  
225          return field_1_index_extern_sheet;
226  
227      }
228  
229      
230  
231      public void setExternSheetIndex(short index){
232  
233          field_1_index_extern_sheet = index;
234  
235      }
236  
237      
238  
239      public short getRow() {
240  
241          return field_2_row;
242  
243      }
244  
245      
246  
247      public void setRow(short row) {
248  
249          field_2_row = row;
250  
251      }
252  
253      
254  
255      public short getColumn() {
256  
257          return ( short ) (field_3_column & 0xFF);
258  
259      }
260  
261      
262  
263      public short getColumnRaw() {
264  
265          return field_3_column;
266  
267      }
268  
269      
270  
271      public boolean isColRowRelative() {
272  
273          return (((getColumnRaw()) & 0x8000) == 0x8000);
274  
275      }
276  
277      
278  
279      public boolean isColRelative() {
280  
281          return (((getColumnRaw()) & 0x4000) == 0x4000);
282  
283      }
284  
285      
286  
287      public void setColumn(short column) {
288  
289          field_3_column &= 0xFF00;
290  
291          field_3_column |= column & 0xFF;
292  
293      }
294  
295      
296  
297      public void setColumnRaw(short column) {
298  
299          field_3_column = column;
300  
301      }
302  
303      
304  
305      public String getArea(){
306  
307          RangeAddress ra = new RangeAddress("");
308  
309          
310  
311          String result = (ra.numTo26Sys(getColumn()) + (getRow() + 1));
312  
313          
314  
315          return result;
316  
317      }
318  
319  
320  
321      public void setArea(String ref){
322  
323          RangeAddress ra = new RangeAddress(ref);
324  
325          
326  
327          String from = ra.getFromCell();
328  
329          
330  
331          setColumn((short) (ra.getXPosition(from) -1));
332  
333          setRow((short) (ra.getYPosition(from) -1));
334  
335                          
336  
337      }
338  
339  
340  
341      public String toFormulaString() {
342  
343          String result = getArea();
344  
345          
346  
347          return result;
348  
349      }
350  
351      
352  
353  }
354  
355  ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????Ref3DPtg???????????????????????????????Ptg???????????????????????????????sid???????????????????????????????SIZE????????????????????????????????????????????????????????????????????????????????????????field_1_index_extern_sheet???????????????????????????????field_2_row???????????????????????????????field_3_column???????????????????????????????????????????Ref3DPtg????????????Ref3DPtg?????????offset?????????field_1_index_extern_sheet??????????????????????????????????????LittleEndian???????????????????????????????????????????????????getShort????????????????????????????????????????????????????????????data??????????????????????????????????????????????????????????????????????offset?????????field_2_row????????????????????????????????LittleEndian?????????????????????????????????????????????getShort??????????????????????????????????????????????????????data????????????????????????????????????????????????????????????????offset?????????field_3_column?????????????????????????????????LittleEndian??????????????????????????????????????????????getShort???????????????????????????????????????????????????????data?????????????????????????????????????????????????????????????????offset???????????????????toString?????????buffer?????????buffer????????????????????????????????????????????????????getExternSheetIndex?????????buffer??????????????????????????????????getRow?????????buffer???????????????????????????????????getColumn?????????buffer???????????isColRowRelative?????????buffer???????????????????????????????????????isColRelative????????????????buffer?????????????????writeBytes?????????array????????????????????offset???????????????????????????????sid?????????LittleEndian??????????????????????putShort???????????????????????????????array??????????????????????????????????????????offset???????????????????????????????????????????????????getExternSheetIndex?????????LittleEndian??????????????????????putShort???????????????????????????????array??????????????????????????????????????????offset???????????????????????????????????????????????????getRow?????????LittleEndian??????????????????????putShort???????????????????????????????array??????????????????????????????????????????offset???????????????????????????????????????????????????getColumnRaw????????????????getSize????????????????SIZE??????????????????getExternSheetIndex????????????????field_1_index_extern_sheet?????????????????setExternSheetIndex?????????field_1_index_extern_sheet??????????????????????????????????????index??????????????????getRow????????????????field_2_row?????????????????setRow?????????field_2_row???????????????????????row??????????????????getColumn???????????????????????????field_3_column??????????????????getColumnRaw????????????????field_3_column????????????????????isColRowRelative???????????????????getColumnRaw????????????????????isColRelative???????????????????getColumnRaw?????????????????setColumn?????????field_3_column?????????field_3_column???????????????????????????column?????????????????setColumnRaw?????????field_3_column??????????????????????????column???????????????????getArea?????????RangeAddress???????????????????????????????RangeAddress??????????????????????????ra?????????????????????????????numTo26Sys????????????????????????????????????????getColumn????????????????????????????????????????????????????????getRow????????????????result?????????????????setArea?????????RangeAddress???????????????????????????????RangeAddress????????????????????????????????????????????ref???????????????????????ra??????????????????????????getFromCell?????????setColumn????????????????????????????ra???????????????????????????????getXPosition????????????????????????????????????????????from?????????setRow?????????????????????????ra????????????????????????????getYPosition?????????????????????????????????????????from???????????????????toFormulaString?????????????????????????getArea????????????????result