1    
2    
3    /* ====================================================================
4     * The Apache Software License, Version 1.1
5     *
6     * Copyright (c) 2002 The Apache Software Foundation.  All rights
7     * reserved.
8     *
9     * Redistribution and use in source and binary forms, with or without
10    * modification, are permitted provided that the following conditions
11    * are met:
12    *
13    * 1. Redistributions of source code must retain the above copyright
14    *    notice, this list of conditions and the following disclaimer.
15    *
16    * 2. Redistributions in binary form must reproduce the above copyright
17    *    notice, this list of conditions and the following disclaimer in
18    *    the documentation and/or other materials provided with the
19    *    distribution.
20    *
21    * 3. The end-user documentation included with the redistribution,
22    *    if any, must include the following acknowledgment:
23    *       "This product includes software developed by the
24    *        Apache Software Foundation (http://www.apache.org/)."
25    *    Alternately, this acknowledgment may appear in the software itself,
26    *    if and wherever such third-party acknowledgments normally appear.
27    *
28    * 4. The names "Apache" and "Apache Software Foundation" and
29    *    "Apache POI" must not be used to endorse or promote products
30    *    derived from this software without prior written permission. For
31    *    written permission, please contact apache@apache.org.
32    *
33    * 5. Products derived from this software may not be called "Apache",
34    *    "Apache POI", nor may "Apache" appear in their name, without
35    *    prior written permission of the Apache Software Foundation.
36    *
37    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40    * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41    * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44    * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45    * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47    * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48    * SUCH DAMAGE.
49    * ====================================================================
50    *
51    * This software consists of voluntary contributions made by many
52    * individuals on behalf of the Apache Software Foundation.  For more
53    * information on the Apache Software Foundation, please see
54    * <http://www.apache.org/>.
55    */
56   
57   package org.apache.poi.hssf.record.formula;
58   
59   import org.apache.poi.util.LittleEndian;
60   import org.apache.poi.hssf.util.RangeAddress;
61   
62   /**
63    * Title:        Reference 3D Ptg <P>
64    * Description:  Defined a cell in extern sheet. <P>
65    * REFERENCE:  <P>
66    * @author Libin Roman (Vista Portal LDT. Developer)
67    * @version 1.0-pre
68    */
69   
70   public class Ref3DPtg extends Ptg {
71       public final static byte sid  = 0x3a;
72       private final static int  SIZE = 7; // 6 + 1 for Ptg
73       private short             field_1_index_extern_sheet;
74       private short             field_2_row;
75       private short             field_3_column;
76   
77       /** Creates new AreaPtg */
78   
79       public Ref3DPtg() {
80       }
81   
82       public Ref3DPtg(byte[] data, int offset) {
83           offset++;
84           field_1_index_extern_sheet = LittleEndian.getShort(data, 0 + offset);
85           field_2_row          = LittleEndian.getShort(data, 2 + offset);
86           field_3_column        = LittleEndian.getShort(data, 4 + offset);
87       }
88   
89       public String toString() {
90           StringBuffer buffer = new StringBuffer();
91   
92           buffer.append("Ref3dPrg\n");
93           buffer.append("Index to Extern Sheet = " + getExternSheetIndex()).append("\n");
94           buffer.append("Row = " + getRow()).append("\n");
95           buffer.append("Col  = " + getColumn()).append("\n");
96           buffer.append("ColRowRel= "
97           + isColRowRelative()).append("\n");
98           buffer.append("ColRel   = " + isColRelative()).append("\n");
99           return buffer.toString();
100      }
101  
102      public void writeBytes(byte [] array, int offset) {
103          array[ 0 + offset ] = sid;
104          LittleEndian.putShort(array, 1 + offset , getExternSheetIndex());
105          LittleEndian.putShort(array, 3 + offset , getRow());
106          LittleEndian.putShort(array, 5 + offset , getColumnRaw());
107      }
108  
109      public int getSize() {
110          return SIZE;
111      }
112  
113      public short getExternSheetIndex(){
114          return field_1_index_extern_sheet;
115      }
116  
117      public void setExternSheetIndex(short index){
118          field_1_index_extern_sheet = index;
119      }
120  
121      public short getRow() {
122          return field_2_row;
123      }
124  
125      public void setRow(short row) {
126          field_2_row = row;
127      }
128  
129      public short getColumn() {
130          return ( short ) (field_3_column & 0xFF);
131      }
132  
133      public short getColumnRaw() {
134          return field_3_column;
135      }
136  
137      public boolean isColRowRelative() {
138          return (((getColumnRaw()) & 0x8000) == 0x8000);
139      }
140  
141      public boolean isColRelative() {
142          return (((getColumnRaw()) & 0x4000) == 0x4000);
143      }
144  
145      public void setColumn(short column) {
146          field_3_column &= 0xFF00;
147          field_3_column |= column & 0xFF;
148      }
149  
150      public void setColumnRaw(short column) {
151          field_3_column = column;
152      }
153  
154      public String getArea(){
155          RangeAddress ra = new RangeAddress("");
156  
157          String result = (ra.numTo26Sys(getColumn()) + (getRow() + 1));
158  
159          return result;
160      }
161  
162      public void setArea(String ref){
163          RangeAddress ra = new RangeAddress(ref);
164  
165          String from = ra.getFromCell();
166  
167          setColumn((short) (ra.getXPosition(from) -1));
168          setRow((short) (ra.getYPosition(from) -1));
169  
170      }
171  
172      public String toFormulaString() {
173          String result = getArea();
174  
175          return result;
176      }
177  
178     public byte getDefaultOperandClass() {return Ptg.CLASS_VALUE;}
179  
180  }
181