zhao
2021-07-07 2fdf959ac739edd6de84aa8053b8b9683dce8e8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) Under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for Additional information regarding copyright ownership.
   The ASF licenses this file to You Under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed Under the License is distributed on an "AS Is" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations Under the License.
==================================================================== */
 
namespace HH.WMS.Utils.NPOI.SS.Formula.PTG
{
    using System;
    using System.Text;
    using HH.WMS.Utils.NPOI.Util;
    using HH.WMS.Utils.NPOI.HSSF.Record;
    
    using HH.WMS.Utils.NPOI.SS.Util;
 
 
    /**
     * ReferencePtgBase - handles references (such as A1, A2, IA4)
     * @author  Andrew C. Oliver (acoliver@apache.org)
     * @author Jason Height (jheight at chariot dot net dot au)
     */
    [Serializable]
    public abstract class RefPtgBase : OperandPtg
    {
        private static int MAX_ROW_NUMBER = 65536;
 
        /** The row index - zero based Unsigned 16 bit value */
        private int field_1_row;
        /** Field 2
         * - lower 8 bits is the zero based Unsigned byte column index
         * - bit 16 - IsRowRelative
         * - bit 15 - IsColumnRelative
         */
        private int field_2_col;
        private static BitField rowRelative = BitFieldFactory.GetInstance(0x8000);
        private static BitField colRelative = BitFieldFactory.GetInstance(0x4000);
        private static BitField column = BitFieldFactory.GetInstance(0x3FFF);
 
        protected RefPtgBase()
        {
            //Required for Clone methods
        }
 
        /**
         * Takes in a String representation of a cell reference and Fills out the
         * numeric fields.
         */
        protected RefPtgBase(String cellref)
        {
            CellReference c = new CellReference(cellref);
            Row = c.Row;
            Column = c.Col;
            IsColRelative = !c.IsColAbsolute;
            IsRowRelative = !c.IsRowAbsolute;
        }
        protected RefPtgBase(CellReference c)
        {
            Row = (c.Row);
            Column = (c.Col);
            IsColRelative = (!c.IsColAbsolute);
            IsRowRelative = (!c.IsRowAbsolute);
        }
        protected RefPtgBase(int row, int column, bool isRowRelative, bool isColumnRelative)
        {
            this.Row = row;
            this.Column = column;
            this.IsRowRelative = isRowRelative;
            this.IsColRelative = isColumnRelative;
        }
 
        protected RefPtgBase(ILittleEndianInput in1)
        {
            field_1_row = in1.ReadUShort();
            field_2_col = in1.ReadUShort();
        }
        protected void ReadCoordinates(ILittleEndianInput in1)
        {
            field_1_row = in1.ReadUShort();
            field_2_col = in1.ReadUShort();
        }
        protected void WriteCoordinates(ILittleEndianOutput out1)
        {
            out1.WriteShort(field_1_row);
            out1.WriteShort(field_2_col);
        }
 
        protected void WriteCoordinates(byte[] array, int offset)
        {
            LittleEndian.PutUShort(array, offset + 0, field_1_row);
            LittleEndian.PutUShort(array, offset + 2, field_2_col);
        }
        /**
         * Returns the row number as a short, which will be
         *  wrapped (negative) for values between 32769 and 65535
         */
        public int Row
        {
            get { return field_1_row; }
            set
            {
                if (value < 0 || value >= MAX_ROW_NUMBER)
                {
                    throw new ArgumentException("The row number, when specified as an integer, must be between 0 and " + MAX_ROW_NUMBER);
                }
                field_1_row = value;
            }
        }
        /**
         * Returns the row number as an int, between 0 and 65535
         */
        public int RowAsInt
        {
            get { return field_1_row; }
        }
 
        public bool IsRowRelative
        {
            get { return rowRelative.IsSet(field_2_col); }
            set
            {
                field_2_col = rowRelative.SetBoolean(field_2_col, value);
            }
        }
 
        public bool IsColRelative
        {
            get { return colRelative.IsSet(field_2_col); }
            set
            {
                field_2_col = colRelative.SetBoolean(field_2_col, value);
            }
        }
 
        public int ColumnRawX
        {
            get { return field_2_col; }
            set { field_2_col = value; }
        }
 
        public int Column
        {
            get { return column.GetValue(field_2_col); }
            set
            {
                /*
                 if (value < 0 || value >= 0x100)
                {
                    throw new ArgumentException("Specified colIx (" + value + ") is out of range");
                }*/
                field_2_col = column.SetValue(field_2_col, value);
            }
        }
        public String FormatReferenceAsString()
        {
            // Only make cell references as needed. Memory is an issue
            CellReference cr = new CellReference(Row, Column, !IsRowRelative, !IsColRelative);
            return cr.FormatAsString();
        }
 
 
        public override byte DefaultOperandClass
        {
            get { return Ptg.CLASS_REF; }
        }
    }
}