admin
2022-09-30 1a16b19acb23a4f28bafd01f3ed80fb225a96c3e
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * This file is part of libxls -- A multiplatform, C/C++ library
 * for parsing Excel(TM) files.
 *
 * Redistribution and use in source and binary forms, with or without modification, are
 * permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice, this list of
 *       conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright notice, this list
 *       of conditions and the following disclaimer in the documentation and/or other materials
 *       provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY David Hoerl ''AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David Hoerl OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Copyright 2004 Komarov Valery
 * Copyright 2006 Christophe Leitienne
 * Copyright 2013 Bob Colbert
 * Copyright 2008-2013 David Hoerl
 *
 */
 
#ifndef XLS_STRUCT_INC
#define XLS_STRUCT_INC
 
#include "libxls/ole.h"
 
#ifdef AIX
#pragma pack(1)
#else
#pragma pack(push, 1)
#endif
 
typedef struct BOF
{
    WORD id;
    WORD size;
}
BOF;
 
typedef struct BIFF
{
    WORD ver;
    WORD type;
    WORD id_make;
    WORD year;
    DWORD flags;
    DWORD min_ver;
    BYTE buf[100];
}
BIFF;
 
typedef struct WIND1
{
    WORD xWn;
    WORD yWn;
    WORD dxWn;
    WORD dyWn;
    WORD grbit;
    WORD itabCur;
    WORD itabFirst;
    WORD ctabSel;
    WORD wTabRatio;
}
WIND1;
 
typedef struct BOUNDSHEET
{
    DWORD    filepos;
    BYTE    type;
    BYTE    visible;
    BYTE    name[];
}
BOUNDSHEET;
 
typedef struct ROW
{
    WORD    index;
    WORD    fcell;
    WORD    lcell;
    WORD    height;
    WORD    notused;
    WORD    notused2; //used only for BIFF3-4
    WORD    flags;
    WORD    xf;
}
ROW;
 
typedef struct COL
{
    WORD    row;
    WORD    col;
    WORD    xf;
}
COL;
 
 
typedef struct FORMULA // BIFF8
{
    WORD    row;
    WORD    col;
    WORD    xf;
    // next 8 bytes either a IEEE double, or encoded on a byte basis
    BYTE    resid;
    BYTE    resdata[5];
    WORD    res;
    WORD    flags;
    BYTE    chn[4]; // BIFF8
    WORD    len;
    BYTE    value[1]; //var
}
FORMULA;
 
typedef struct FARRAY // BIFF8
{
    WORD    row1;
    WORD    row2;
    BYTE    col1;
    BYTE    col2;
    WORD    flags;
    BYTE    chn[4]; // BIFF8
    WORD    len;
    BYTE    value[1]; //var
}
FARRAY;
 
typedef struct RK
{
    WORD    row;
    WORD    col;
    WORD    xf;
    DWORD_UA value;
}
RK;
 
typedef struct MULRK
{
    WORD    row;
    WORD    col;
    struct {
        WORD    xf;
        DWORD_UA value;
    }        rk[];
    //WORD    last_col;
}
MULRK;
 
typedef struct MULBLANK
{
    WORD    row;
    WORD    col;
    WORD    xf[];
    //WORD    last_col;
}
MULBLANK;
 
typedef struct BLANK
{
    WORD    row;
    WORD    col;
    WORD    xf;
}
BLANK;
 
typedef struct LABEL
{
    WORD    row;
    WORD    col;
    WORD    xf;
    BYTE    value[1]; // var
}
LABEL;
typedef LABEL LABELSST;
 
typedef struct SST
{
    DWORD    num;
    DWORD    numofstr;
    BYTE    strings;
}
SST;
 
typedef struct XF5
{
    WORD    font;
    WORD    format;
    WORD    type;
    WORD    align;
    WORD    color;
    WORD    fill;
    WORD    border;
    WORD    linestyle;
}
XF5;
 
typedef struct XF8
{
    WORD    font;
    WORD    format;
    WORD    type;
    BYTE    align;
    BYTE    rotation;
    BYTE    ident;
    BYTE    usedattr;
    DWORD    linestyle;
    DWORD    linecolor;
    WORD    groundcolor;
}
XF8;
 
typedef struct BR_NUMBER
{
    WORD    row;
    WORD    col;
    WORD    xf;
    double value;
}
BR_NUMBER;
 
typedef struct COLINFO
{
    WORD    first;
    WORD    last;
    WORD    width;
    WORD    xf;
    WORD    flags;
    WORD    notused;
}
COLINFO;
 
typedef struct MERGEDCELLS
{
    WORD    rowf;
    WORD    rowl;
    WORD    colf;
    WORD    coll;
}
MERGEDCELLS;
 
typedef struct FONT
{
    WORD    height;
    WORD    flag;
    WORD    color;
    WORD    bold;
    WORD    escapement;
    BYTE    underline;
    BYTE    family;
    BYTE    charset;
    BYTE    notused;
    BYTE    name;
}
FONT;
 
typedef struct FORMAT
{
    WORD    index;
    BYTE    value[0];
}
FORMAT;
 
#pragma pack(pop)
 
//---------------------------------------------------------
 
typedef    struct st_sheet
{
    DWORD count;        // Count of sheets
    struct st_sheet_data
    {
        DWORD filepos;
        BYTE visibility;
        BYTE type;
        BYTE* name;
    }
    * sheet;
}
st_sheet;
 
typedef    struct st_font
{
    DWORD count;        // Count of FONT's
    struct st_font_data
    {
        WORD    height;
        WORD    flag;
        WORD    color;
        WORD    bold;
        WORD    escapement;
        BYTE    underline;
        BYTE    family;
        BYTE    charset;
        BYTE*    name;
    }
    * font;
}
st_font;
 
typedef struct st_format
{
    DWORD count;        // Count of FORMAT's
    struct st_format_data
    {
         WORD index;
         BYTE *value;
    }
    * format;
}
st_format;
 
typedef    struct st_xf
{
    DWORD count;    // Count of XF
    //    XF** xf;
    struct st_xf_data
    {
        WORD    font;
        WORD    format;
        WORD    type;
        BYTE    align;
        BYTE    rotation;
        BYTE    ident;
        BYTE    usedattr;
        DWORD    linestyle;
        DWORD    linecolor;
        WORD    groundcolor;
    }
    * xf;
}
st_xf;
 
 
typedef    struct st_sst
{
    DWORD count;
    DWORD lastid;
    DWORD continued;
    DWORD lastln;
    DWORD lastrt;
    DWORD lastsz;
    struct str_sst_string
    {
        BYTE* str;
    }
    * string;
}
st_sst;
 
 
typedef    struct st_cell
{
    DWORD count;
    struct st_cell_data
    {
        WORD    id;
        WORD    row;
        WORD    col;
        WORD    xf;
        BYTE*    str;        // String value;
        double    d;
        int32_t    l;
        WORD    width;        // Width of col
        WORD    colspan;
        WORD    rowspan;
        BYTE    isHidden;    // Is cell hidden
    }
    * cell;
}
st_cell;
 
 
typedef    struct st_row
{
    //    DWORD count;
    WORD lastcol;    // numCols - 1
    WORD lastrow;    // numRows - 1
    struct st_row_data
    {
        WORD index;
        WORD fcell;
        WORD lcell;
        WORD height;
        WORD flags;
        WORD xf;
        BYTE xfflags;
        st_cell cells;
    }
    * row;
}
st_row;
 
 
typedef    struct st_colinfo
{
    DWORD count;                //Count of COLINFO
    struct st_colinfo_data
    {
        WORD    first;
        WORD    last;
        WORD    width;
        WORD    xf;
        WORD    flags;
    }
    * col;
}
st_colinfo;
 
typedef struct xlsWorkBook
{
    //FILE*        file;
    OLE2Stream*    olestr;
    int32_t        filepos;        // position in file
 
    //From Header (BIFF)
    BYTE        is5ver;
    BYTE        is1904;
    WORD        type;
 
    //Other data
    WORD        codepage;        //Charset codepage
    char*        charset;
    st_sheet    sheets;
    st_sst        sst;            //SST table
    st_xf        xfs;            //XF table
    st_font        fonts;
    st_format    formats;        //FORMAT table
 
    char        *summary;        // ole file
    char        *docSummary;    // ole file
}
xlsWorkBook;
 
typedef struct xlsWorkSheet
{
    DWORD        filepos;
    WORD        defcolwidth;
    st_row        rows;
    xlsWorkBook *workbook;
    st_colinfo    colinfo;
}
xlsWorkSheet;
 
#ifdef __cplusplus
typedef struct st_cell::st_cell_data xlsCell;
typedef    struct st_row::st_row_data xlsRow;
#else
typedef struct st_cell_data xlsCell;
typedef    struct st_row_data xlsRow;
#endif
 
typedef struct xls_summaryInfo
{
    BYTE        *title;
    BYTE        *subject;
    BYTE        *author;
    BYTE        *keywords;
    BYTE        *comment;
    BYTE        *lastAuthor;
    BYTE        *appName;
    BYTE        *category;
    BYTE        *manager;
    BYTE        *company;
}
xlsSummaryInfo;
 
typedef void (*xls_formula_handler)(WORD bof, WORD len, BYTE *formula);
 
#endif