Diffstat (limited to 'noncore/apps/opie-sheet/Excel.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-sheet/Excel.h | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/noncore/apps/opie-sheet/Excel.h b/noncore/apps/opie-sheet/Excel.h new file mode 100644 index 0000000..0a581cf --- a/dev/null +++ b/noncore/apps/opie-sheet/Excel.h | |||
@@ -0,0 +1,205 @@ | |||
1 | |||
2 | #include <stdio.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <math.h> | ||
5 | #include <time.h> | ||
6 | #include <sys/types.h> | ||
7 | #include <strings.h> | ||
8 | #include <qstring.h> | ||
9 | #include <qarray.h> | ||
10 | #include <qlist.h> | ||
11 | |||
12 | #define DATEFORMAT 0x1 | ||
13 | #define NUMBERFORMAT 0x2 | ||
14 | |||
15 | #define BIFF8 0x600 | ||
16 | #define BIFF7 0x500 | ||
17 | #define WBKGLOBAL 0x5 | ||
18 | #define WRKSHEET 0x10 | ||
19 | |||
20 | #define XL_ARRAY 0x221 | ||
21 | #define XL_BOUNDSHEET 0x85 | ||
22 | #define XL_BOF 0x809 | ||
23 | #define XL_BOOLERR 0x205 | ||
24 | #define XL_CONTINUE 0x3c | ||
25 | #define XL_DIMENSION 0x200 | ||
26 | #define XL_EOF 0x0a | ||
27 | #define XL_EXTSST 0xff | ||
28 | #define XL_FORMULA 0x406 | ||
29 | #define XL_FORMULA2 0x6 | ||
30 | #define XL_FORMAT 0x41e | ||
31 | #define XL_INDEX 0x20b | ||
32 | #define XL_LABEL 0x204 | ||
33 | #define XL_LABELSST 0xfd | ||
34 | #define XL_MULRK 0xbd | ||
35 | #define XL_NAME 0x18 | ||
36 | #define XL_NOTE 0x1c | ||
37 | #define XL_NUMBER 0x203 | ||
38 | #define XL_RK 0x7e | ||
39 | #define XL_RK2 0x27e | ||
40 | #define XL_ROW 0x208 | ||
41 | #define XL_SST 0xfc | ||
42 | #define XL_STRING 0x207 | ||
43 | #define XL_TXO 0x1b6 | ||
44 | #define XL_XF 0xe0 | ||
45 | #define XL_UNKNOWN 0xffff | ||
46 | |||
47 | #define CELL_LABEL 0x2 | ||
48 | #define CELL_NUMBER 0x3 | ||
49 | #define CELL_DATE 0x4 | ||
50 | #define CELL_BOOLEAN 0x5 | ||
51 | #define CELL_ERROR 0x6 | ||
52 | |||
53 | |||
54 | |||
55 | class ExcelFormat | ||
56 | { | ||
57 | public: | ||
58 | int code; | ||
59 | int type; | ||
60 | QString format; | ||
61 | ExcelFormat(); | ||
62 | ExcelFormat(int c,int t, QString s); | ||
63 | }; | ||
64 | |||
65 | struct xfrecord | ||
66 | { | ||
67 | int code; | ||
68 | int type; | ||
69 | QString format; | ||
70 | }; | ||
71 | |||
72 | class ExcelCell | ||
73 | { | ||
74 | public: | ||
75 | int type; | ||
76 | int row,col; | ||
77 | int xfindex; //xf format index of cell | ||
78 | int valuei; | ||
79 | double valued; | ||
80 | QString valuec; | ||
81 | |||
82 | }; | ||
83 | |||
84 | class ExcelBREC | ||
85 | { | ||
86 | public: | ||
87 | int code; | ||
88 | int length; | ||
89 | int position; | ||
90 | char* data; | ||
91 | }; | ||
92 | |||
93 | class SSTList | ||
94 | { | ||
95 | public: | ||
96 | QArray <ExcelBREC*> rec; | ||
97 | }; | ||
98 | |||
99 | class ExcelSheet | ||
100 | { | ||
101 | public: | ||
102 | QString name; | ||
103 | ExcelBREC BOFRecord; | ||
104 | int position; | ||
105 | int type; | ||
106 | int rows; | ||
107 | int cols; | ||
108 | |||
109 | int cellsize,rowalloc,cellalloc; | ||
110 | QArray <ExcelCell*> Cells; | ||
111 | bool InitCells(void); // true if ok | ||
112 | ExcelCell* Get(int row, int col); | ||
113 | void Set(int row, int col, ExcelCell* cell); | ||
114 | |||
115 | }; | ||
116 | |||
117 | struct mulrk { | ||
118 | int row; | ||
119 | int first; | ||
120 | int last; | ||
121 | int numrks; | ||
122 | QArray<int> rknumbers; | ||
123 | QArray<double> rkdbls; | ||
124 | QArray<int> xfindices; | ||
125 | }; | ||
126 | |||
127 | |||
128 | |||
129 | |||
130 | class ExcelBook | ||
131 | { | ||
132 | public: | ||
133 | FILE *File; | ||
134 | int Position; | ||
135 | //int stringcount; | ||
136 | QArray <QString*> SharedStrings; | ||
137 | //int xfcount; | ||
138 | QArray <ExcelFormat*> XFRecords; | ||
139 | //int Sheetcount; | ||
140 | QArray <ExcelSheet*> Sheets; | ||
141 | //int name count; | ||
142 | QArray <QString*> Names; | ||
143 | |||
144 | QString dateformat; | ||
145 | int Version; | ||
146 | int endian; | ||
147 | int Integer2Byte(int b1, int b2 ); | ||
148 | int Integer4Byte(int b1, int b2, int b3, int b4 ); | ||
149 | int Integer2ByteFile(FILE *f); | ||
150 | float Float4Byte(int b1, int b2, int b3, int b4); | ||
151 | double Double4Byte(int b1, int b2, int b3, int b4); | ||
152 | double Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8); | ||
153 | void DetectEndian(void); | ||
154 | |||
155 | bool OpenFile(char *Filename); // true if ok | ||
156 | bool CloseFile(void); // true if ok | ||
157 | void SeekPosition(int pos); // go to Pos | ||
158 | void SeekSkip(int pos); // skips pos bytes. | ||
159 | int FileEOF(void); //returns -1 if EOF else 0 | ||
160 | int Get2Bytes(void); //gets an int from the file | ||
161 | char* Read(int pos, int length); | ||
162 | QString ReadUnicodeChar(int pos, int length); | ||
163 | QString* GetString(int num); //gets the num string from SharedStrings; | ||
164 | int SeekBOF(void); | ||
165 | ExcelBREC* GetBREC(void); | ||
166 | ExcelBREC* PeekBREC(void); | ||
167 | char* GetDataOfBREC(ExcelBREC* record); | ||
168 | void ConvertCharToArray(ExcelBREC* record, char* chars, int length); | ||
169 | int SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record); | ||
170 | int ReadSheet(ExcelSheet* sheet); //read the sheet sheet* | ||
171 | ExcelSheet* GetSheet(void); | ||
172 | void ParseSheets(void); | ||
173 | void GetSheets(void); | ||
174 | |||
175 | bool ParseBook(char *file); // THIS IS THE MAIN PARSE FUNCTION of file | ||
176 | QString GetASCII(char* inbytes, int pos, int chars); | ||
177 | QString GetUnicode(char * inbytes, int pos, int chars); | ||
178 | void HandleBoundSheet( ExcelBREC* rec); | ||
179 | void HandleName(ExcelSheet* sheet, ExcelBREC* rec); | ||
180 | ExcelFormat* GetFormatting(int xf); | ||
181 | void HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes); | ||
182 | char* MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont); | ||
183 | void HandleSST(ExcelBREC* rec); | ||
184 | void HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec); | ||
185 | ExcelCell* CellLabel(int row, int col, QString str); | ||
186 | ExcelCell* CellNumber(int row, int col, int index, double d); | ||
187 | QString* CellDataString(ExcelSheet* sh, int row, int col); | ||
188 | int CellGetPrecision(double d); | ||
189 | void CellSetDateFormat(char *d); | ||
190 | void HandleMulrk(ExcelSheet* sheet, ExcelBREC* record); | ||
191 | void MulrkRead(struct mulrk *mulrk, char* data); | ||
192 | void HandleNumber(ExcelSheet* sheet, ExcelBREC* record); | ||
193 | void HandleFormat(ExcelBREC* rec); | ||
194 | void HandleXF(ExcelBREC* rec); | ||
195 | void HandleRK(ExcelSheet* sheet, ExcelBREC* record); | ||
196 | void HandleFormula(ExcelSheet* sheet, ExcelBREC* record); | ||
197 | QString GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz); | ||
198 | QString FindCellName(int row, int col); | ||
199 | |||
200 | |||
201 | |||
202 | |||
203 | |||
204 | }; | ||
205 | |||