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
 
/* ====================================================================
   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: Beginning Of File
     * Description: Somewhat of a misnomer, its used for the beginning of a Set of
     *              records that have a particular pupose or subject.
     *              Used in sheets and workbooks.
     * REFERENCE:  PG 289 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)
     * @author Andrew C. Oliver
     * @author Jason Height (jheight at chariot dot net dot au)
     * @version 2.0-pre
     */
 
    public class BOFRecord : StandardRecord
    {
 
        /**
         * for BIFF8 files the BOF is 0x809.  For earlier versions it was 0x09 or 0x(biffversion)09
         */
 
        public const short sid = 0x809;
        private int field_1_version;
        private int field_2_type;
        private int field_3_build;
        private int field_4_year;
        private int field_5_history;
        private int field_6_rversion;
 
        /**
         * suggested default (0x06 - BIFF8)
         */
 
        public static short VERSION = 0x06;
 
        /**
         * suggested default 0x10d3
         */
 
        public static short BUILD = 0x10d3;
 
        /**
         * suggested default  0x07CC (1996)
         */
 
        public static short BUILD_YEAR = 0x07CC;   // 1996
 
        /**
         * suggested default for a normal sheet (0x41)
         */
 
        public const short HISTORY_MASK = 0x41;
        public const short TYPE_WORKBOOK = 0x05;
        public const short TYPE_VB_MODULE = 0x06;
        public const short TYPE_WORKSHEET = 0x10;
        public const short TYPE_CHART = 0x20;
        public const short TYPE_EXCEL_4_MACRO = 0x40;
        public const short TYPE_WORKSPACE_FILE = 0x100;
 
        /**
         * Constructs an empty BOFRecord with no fields Set.
         */
 
        public BOFRecord()
        {
        }
        private BOFRecord(int type)
        {
            field_1_version = VERSION;
            field_2_type = type;
            field_3_build = BUILD;
            field_4_year = BUILD_YEAR;
            field_5_history = 0x01;
            field_6_rversion = VERSION;
        }
 
        public static BOFRecord CreateSheetBOF()
        {
            return new BOFRecord(TYPE_WORKSHEET);
        }
 
        /**
         * Constructs a BOFRecord and Sets its fields appropriately
         * @param in the RecordInputstream to Read the record from
         */
 
        public BOFRecord(RecordInputStream in1)
        {
            field_1_version = in1.ReadShort();
            field_2_type = in1.ReadShort();
 
            // Some external tools don't generate all of
            //  the remaining fields
            if (in1.Remaining >= 2)
            {
                field_3_build = in1.ReadShort();
            }
            if (in1.Remaining >= 2)
            {
                field_4_year = in1.ReadShort();
            }
            if (in1.Remaining >= 4)
            {
                field_5_history = in1.ReadInt();
            }
            if (in1.Remaining >= 4)
            {
                field_6_rversion = in1.ReadInt();
            }
        }
 
        /**
         * Version number - for BIFF8 should be 0x06
         * @see #VERSION
         * @param version version to be Set
         */
 
        public int Version
        {
            set { field_1_version = value; }
            get { return field_1_version; }
        }
        /**
         * Set the history bit mask (not very useful)
         * @see #HISTORY_MASK
         * @param bitmask bitmask to Set for the history
         */
 
        public int HistoryBitMask
        {
            set { field_5_history = value; }
            get { return field_5_history; }
        }
 
        /**
         * Set the minimum version required to Read this file
         *
         * @see #VERSION
         * @param version version to Set
         */
 
        public int RequiredVersion
        {
            set { field_6_rversion = value; }
            get { return field_6_rversion; }
        }
 
        /**
         * type of object this marks
         * @see #TYPE_WORKBOOK
         * @see #TYPE_VB_MODULE
         * @see #TYPE_WORKSHEET
         * @see #TYPE_CHART
         * @see #TYPE_EXCEL_4_MACRO
         * @see #TYPE_WORKSPACE_FILE
         * @return short type of object
         */
 
        public int Type
        {
            get { return field_2_type; }
            set { field_2_type = value; }
        }
        private String TypeName
        {
            get
            {
                switch (field_2_type)
                {
                    case TYPE_CHART: return "chart";
                    case TYPE_EXCEL_4_MACRO: return "excel 4 macro";
                    case TYPE_VB_MODULE: return "vb module";
                    case TYPE_WORKBOOK: return "workbook";
                    case TYPE_WORKSHEET: return "worksheet";
                    case TYPE_WORKSPACE_FILE: return "workspace file";
                }
                return "#error unknown type#";
            }
        }
 
        /**
         * Get the build that wrote this file
         * @see #BUILD
         * @return short build number of the generator of this file
         */
 
        public int Build
        {
            get { return field_3_build; }
            set { field_3_build = value; }
        }
 
        /**
         * Year of the build that wrote this file
         * @see #BUILD_YEAR
         * @return short build year of the generator of this file
         */
 
        public int BuildYear
        {
            get { return field_4_year; }
            set { field_4_year = value; }
        }
 
        public override String ToString()
        {
            StringBuilder buffer = new StringBuilder();
 
            buffer.Append("[BOF RECORD]\n");
            buffer.Append("    .version         = ")
                .Append(StringUtil.ToHexString(Version)).Append("\n");
            buffer.Append("    .type            = ")
                .Append(StringUtil.ToHexString(Type)).Append("\n");
            buffer.Append(" (").Append(TypeName).Append(")").Append("\n");
            buffer.Append("    .build           = ")
                .Append(StringUtil.ToHexString(Build)).Append("\n");
            buffer.Append("    .buildyear       = ").Append(BuildYear)
                .Append("\n");
            buffer.Append("    .history         = ")
                .Append(StringUtil.ToHexString(HistoryBitMask)).Append("\n");
            buffer.Append("    .requiredversion = ")
                .Append(StringUtil.ToHexString(RequiredVersion)).Append("\n");
            buffer.Append("[/BOF RECORD]\n");
            return buffer.ToString();
        }
 
        public override void Serialize(ILittleEndianOutput out1)
        {
            out1.WriteShort(Version);
            out1.WriteShort(Type);
            out1.WriteShort(Build);
            out1.WriteShort(BuildYear);
            out1.WriteInt(HistoryBitMask);
            out1.WriteInt(RequiredVersion);
        }
 
        protected override int DataSize
        {
            get { return 16; }
        }
 
        public override short Sid
        {
            get { return sid; }
        }
 
        public override object Clone()
        {
            BOFRecord rec = new BOFRecord();
            rec.field_1_version = field_1_version;
            rec.field_2_type = field_2_type;
            rec.field_3_build = field_3_build;
            rec.field_4_year = field_4_year;
            rec.field_5_history = field_5_history;
            rec.field_6_rversion = field_6_rversion;
            return rec;
        }
    }
}