zhao
2021-06-04 c7ec496f9e41c2227103b3ef776e4a3f91bce6b2
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/* ====================================================================
   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.HSSF.Record
{
 
    using System;
    using System.Text;
    using System.Collections;
    using HH.WMS.Utils.NPOI.Util;
 
    /**
     * Title:        Row Record
     * Description:  stores the row information for the sheet. 
     * REFERENCE:  PG 379 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
     * @author Andrew C. Oliver (acoliver at apache dot org)
     * @author Jason Height (jheight at chariot dot net dot au)
     * @version 2.0-pre
     */
    public class RowRecord : StandardRecord, IComparable
    {
        public const short sid = 0x208;
        public static int ENCODED_SIZE = 20;
 
        private const int OPTION_BITS_ALWAYS_SET = 0x0100;
        private const int DEFAULT_HEIGHT_BIT = 0x8000;
 
        /** The maximum row number that excel can handle (zero based) ie 65536 rows Is
         *  max number of rows.
         */
        [Obsolete]
        public const int MAX_ROW_NUMBER = 65535;
 
        private int field_1_row_number;
        private int field_2_first_col;
        private int field_3_last_col;   // plus 1
        private short field_4_height;
        private short field_5_optimize;   // hint field for gui, can/should be Set to zero
 
        // for generated sheets.
        private short field_6_reserved;
        /** 16 bit options flags */
        private int field_7_option_flags;
        private static BitField outlineLevel = BitFieldFactory.GetInstance(0x07);
 
        // bit 3 reserved
        private static BitField colapsed = BitFieldFactory.GetInstance(0x10);
        private static BitField zeroHeight = BitFieldFactory.GetInstance(0x20);
        private static BitField badFontHeight = BitFieldFactory.GetInstance(0x40);
        private static BitField formatted = BitFieldFactory.GetInstance(0x80);
        private short field_8_xf_index;   // only if IsFormatted
 
        public RowRecord(int rowNumber)
        {
            field_1_row_number = rowNumber;
            //field_2_first_col = -1;
            //field_3_last_col = -1;
            field_4_height = (short)0x00FF;
            field_5_optimize = (short)0;
            field_6_reserved = (short)0;
            field_7_option_flags = OPTION_BITS_ALWAYS_SET; // seems necessary for outlining
 
            field_8_xf_index = (short)0xf;
            SetEmpty();
        }
 
        /**
         * Constructs a Row record and Sets its fields appropriately.
         * @param in the RecordInputstream to Read the record from
         */
 
        public RowRecord(RecordInputStream in1)
        {
            field_1_row_number = in1.ReadUShort();
            field_2_first_col = in1.ReadShort();
            field_3_last_col = in1.ReadShort();
            field_4_height = in1.ReadShort();
            field_5_optimize = in1.ReadShort();
            field_6_reserved = in1.ReadShort();
            field_7_option_flags = in1.ReadShort();
            field_8_xf_index = in1.ReadShort();
        }
 
        public void SetEmpty()
        { 
            field_2_first_col = 0;
            field_3_last_col = 0;            
        }
        /**
         * Get the logical row number for this row (0 based index)
         * @return row - the row number
         */
        public bool IsEmpty
        {
            get
            {
                return (field_2_first_col | field_3_last_col) == 0;
            }
        }
        //public short RowNumber
        public int RowNumber
        {
            get
            {
                return field_1_row_number;
            }
            set { field_1_row_number = value; }
        }
 
        /**
         * Get the logical col number for the first cell this row (0 based index)
         * @return col - the col number
         */
 
        public int FirstCol
        {
            get{return field_2_first_col;}
            set { field_2_first_col = value; }
        }
 
        /**
         * Get the logical col number for the last cell this row plus one (0 based index)
         * @return col - the last col number + 1
         */
 
        public int LastCol
        {
            get { return field_3_last_col; }
            set { field_3_last_col = value; }
        }
 
        /**
         * Get the height of the row
         * @return height of the row
         */
 
        public short Height
        {
            get{return field_4_height;}
            set { field_4_height = value; }
        }
 
        /**
         * Get whether to optimize or not (Set to 0)
         * @return optimize (Set to 0)
         */
 
        public short Optimize
        {
            get
            {
                return field_5_optimize;
            }
            set { field_5_optimize = value; }
        }
 
        /**
         * Gets the option bitmask.  (use the individual bit Setters that refer to this
         * method)
         * @return options - the bitmask
         */
 
        public short OptionFlags
        {
            get
            {
                return (short)field_7_option_flags;
            }
            set { field_7_option_flags = value | (short)OPTION_BITS_ALWAYS_SET; }
        }
 
        // option bitfields
 
        /**
         * Get the outline level of this row
         * @return ol - the outline level
         * @see #GetOptionFlags()
         */
 
        public short OutlineLevel
        {
            get { return (short)outlineLevel.GetValue(field_7_option_flags); }
            set { field_7_option_flags = outlineLevel.SetValue(field_7_option_flags, value); }
        }
 
        /**
         * Get whether or not to colapse this row
         * @return c - colapse or not
         * @see #GetOptionFlags()
         */
 
        public bool Colapsed
        {
            get
            {
                return (colapsed.IsSet(field_7_option_flags));
            }
            set 
            { 
                field_7_option_flags = colapsed.SetBoolean(field_7_option_flags, value); 
            }
        }
 
        /**
         * Get whether or not to Display this row with 0 height
         * @return - z height is zero or not.
         * @see #GetOptionFlags()
         */
 
        public bool ZeroHeight
        {
            get
            {
                return zeroHeight.IsSet(field_7_option_flags);
            }
            set 
            { 
                field_7_option_flags = zeroHeight.SetBoolean(field_7_option_flags, value); 
            }
        }
 
        /**
         * Get whether the font and row height are not compatible
         * @return - f -true if they aren't compatible (damn not logic)
         * @see #GetOptionFlags()
         */
 
        public bool BadFontHeight
        {
            get
            {
                return badFontHeight.IsSet(field_7_option_flags);
            }
            set 
            { 
                field_7_option_flags = badFontHeight.SetBoolean(field_7_option_flags, value); 
            }
        }
 
        /**
         * Get whether the row has been formatted (even if its got all blank cells)
         * @return formatted or not
         * @see #GetOptionFlags()
         */
 
        public bool Formatted
        {
            get
            {
                return formatted.IsSet(field_7_option_flags);
            }
            set { field_7_option_flags = formatted.SetBoolean(field_7_option_flags, value); }
        }
 
        // end bitfields
 
        /**
         * if the row is formatted then this is the index to the extended format record
         * @see org.apache.poi.hssf.record.ExtendedFormatRecord
         * @return index to the XF record or bogus value (undefined) if Isn't formatted
         */
 
        public short XFIndex
        {
            get { return field_8_xf_index; }
            set { field_8_xf_index = value; }
        }
 
        public override String ToString()
        {
            StringBuilder buffer = new StringBuilder();
 
            buffer.Append("[ROW]\n");
            buffer.Append("    .rownumber      = ")
                .Append(StringUtil.ToHexString(RowNumber)).Append("\n");
            buffer.Append("    .firstcol       = ")
                .Append(StringUtil.ToHexString(FirstCol)).Append("\n");
            buffer.Append("    .lastcol        = ")
                .Append(StringUtil.ToHexString(LastCol)).Append("\n");
            buffer.Append("    .height         = ")
                .Append(StringUtil.ToHexString(Height)).Append("\n");
            buffer.Append("    .optimize       = ")
                .Append(StringUtil.ToHexString(Optimize)).Append("\n");
            buffer.Append("    .reserved       = ")
                .Append(StringUtil.ToHexString(field_6_reserved)).Append("\n");
            buffer.Append("    .optionflags    = ")
                .Append(StringUtil.ToHexString(OptionFlags)).Append("\n");
            buffer.Append("        .outlinelvl = ")
                .Append(StringUtil.ToHexString(OutlineLevel)).Append("\n");
            buffer.Append("        .colapsed   = ").Append(Colapsed)
                .Append("\n");
            buffer.Append("        .zeroheight = ").Append(ZeroHeight)
                .Append("\n");
            buffer.Append("        .badfontheig= ").Append(BadFontHeight)
                .Append("\n");
            buffer.Append("        .formatted  = ").Append(Formatted)
                .Append("\n");
            buffer.Append("    .xFindex        = ")
                .Append(StringUtil.ToHexString(XFIndex)).Append("\n");
            buffer.Append("[/ROW]\n");
            return buffer.ToString();
        }
 
 
        public override void Serialize(ILittleEndianOutput out1)
        {
            out1.WriteShort(RowNumber);
            out1.WriteShort(FirstCol == -1 ? (short)0 : FirstCol);
            out1.WriteShort(LastCol == -1 ? (short)0 : LastCol);
            out1.WriteShort(Height);
            out1.WriteShort(Optimize);
            out1.WriteShort(field_6_reserved);
            out1.WriteShort(OptionFlags);
            out1.WriteShort(XFIndex);
        }
        protected override int DataSize
        {
            get
            {
                return ENCODED_SIZE - 4;
            }
        }
        public override int RecordSize
        {
            get { return 20; }
        }
 
        public override short Sid
        {
            get { return sid; }
        }
 
        public int CompareTo(Object obj)
        {
            RowRecord loc = (RowRecord)obj;
 
            if (this.RowNumber == loc.RowNumber)
            {
                return 0;
            }
            if (this.RowNumber < loc.RowNumber)
            {
                return -1;
            }
            if (this.RowNumber > loc.RowNumber)
            {
                return 1;
            }
            return -1;
        }
 
        public override bool Equals(Object obj)
        {
            if (!(obj is RowRecord))
            {
                return false;
            }
            RowRecord loc = (RowRecord)obj;
 
            if (this.RowNumber == loc.RowNumber)
            {
                return true;
            }
            return false;
        }
 
        public override int GetHashCode ()
        {
            return RowNumber;
        }
 
        public override Object Clone()
        {
            RowRecord rec = new RowRecord(field_1_row_number);
            rec.field_2_first_col = field_2_first_col;
            rec.field_3_last_col = field_3_last_col;
            rec.field_4_height = field_4_height;
            rec.field_5_optimize = field_5_optimize;
            rec.field_6_reserved = field_6_reserved;
            rec.field_7_option_flags = field_7_option_flags;
            rec.field_8_xf_index = field_8_xf_index;
            return rec;
        }
    }
}