Diffstat (limited to 'noncore/apps/opie-sheet/Excel.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-sheet/Excel.h | 255 |
1 files changed, 139 insertions, 116 deletions
diff --git a/noncore/apps/opie-sheet/Excel.h b/noncore/apps/opie-sheet/Excel.h index 0a581cf..51ccf5c 100644 --- a/noncore/apps/opie-sheet/Excel.h +++ b/noncore/apps/opie-sheet/Excel.h | |||
@@ -1,13 +1,43 @@ | |||
1 | /* | ||
2 | =. This file is part of the Opie Project | ||
3 | .=l. Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org> | ||
4 | .>+-= | ||
5 | _;:, .> :=|. This program is free software; you can | ||
6 | .> <`_, > . <= redistribute it and/or modify it under | ||
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
8 | .="- .-=="i, .._ License as published by the Free Software | ||
9 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
10 | ._= =} : or (at your option) any later version. | ||
11 | .%`+i> _;_. | ||
12 | .i_,=:_. -<s. This program is distributed in the hope that | ||
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
14 | : .. .:, . . . without even the implied warranty of | ||
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
17 | ..}^=.= = ; Library General Public License for more | ||
18 | ++= -. .` .: details. | ||
19 | : = ...= . :.=- | ||
20 | -. .:....=;==+<; You should have received a copy of the GNU | ||
21 | -_. . . )=. = Library General Public License along with | ||
22 | -- :-=` this library; see the file COPYING.LIB. | ||
23 | If not, write to the Free Software Foundation, | ||
24 | Inc., 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | |||
29 | /* QT */ | ||
30 | #include <qstring.h> | ||
31 | #include <qarray.h> | ||
32 | #include <qlist.h> | ||
1 | 33 | ||
34 | /* STD */ | ||
2 | #include <stdio.h> | 35 | #include <stdio.h> |
3 | #include <stdlib.h> | 36 | #include <stdlib.h> |
4 | #include <math.h> | 37 | #include <math.h> |
5 | #include <time.h> | 38 | #include <time.h> |
6 | #include <sys/types.h> | 39 | #include <sys/types.h> |
7 | #include <strings.h> | 40 | #include <strings.h> |
8 | #include <qstring.h> | ||
9 | #include <qarray.h> | ||
10 | #include <qlist.h> | ||
11 | 41 | ||
12 | #define DATEFORMAT 0x1 | 42 | #define DATEFORMAT 0x1 |
13 | #define NUMBERFORMAT 0x2 | 43 | #define NUMBERFORMAT 0x2 |
@@ -55,151 +85,144 @@ | |||
55 | class ExcelFormat | 85 | class ExcelFormat |
56 | { | 86 | { |
57 | public: | 87 | public: |
58 | int code; | 88 | int code; |
59 | int type; | 89 | int type; |
60 | QString format; | 90 | QString format; |
61 | ExcelFormat(); | 91 | ExcelFormat(); |
62 | ExcelFormat(int c,int t, QString s); | 92 | ExcelFormat(int c,int t, QString s); |
63 | }; | 93 | }; |
64 | 94 | ||
65 | struct xfrecord | 95 | struct xfrecord |
66 | { | 96 | { |
67 | int code; | 97 | int code; |
68 | int type; | 98 | int type; |
69 | QString format; | 99 | QString format; |
70 | }; | 100 | }; |
71 | 101 | ||
72 | class ExcelCell | 102 | class ExcelCell |
73 | { | 103 | { |
74 | public: | 104 | public: |
75 | int type; | 105 | int type; |
76 | int row,col; | 106 | int row,col; |
77 | int xfindex; //xf format index of cell | 107 | int xfindex; //xf format index of cell |
78 | int valuei; | 108 | int valuei; |
79 | double valued; | 109 | double valued; |
80 | QString valuec; | 110 | QString valuec; |
81 | 111 | ||
82 | }; | 112 | }; |
83 | 113 | ||
84 | class ExcelBREC | 114 | class ExcelBREC |
85 | { | 115 | { |
86 | public: | 116 | public: |
87 | int code; | 117 | int code; |
88 | int length; | 118 | int length; |
89 | int position; | 119 | int position; |
90 | char* data; | 120 | char* data; |
91 | }; | 121 | }; |
92 | 122 | ||
93 | class SSTList | 123 | class SSTList |
94 | { | 124 | { |
95 | public: | 125 | public: |
96 | QArray <ExcelBREC*> rec; | 126 | QArray <ExcelBREC*> rec; |
97 | }; | 127 | }; |
98 | 128 | ||
99 | class ExcelSheet | 129 | class ExcelSheet |
100 | { | 130 | { |
101 | public: | 131 | public: |
102 | QString name; | 132 | QString name; |
103 | ExcelBREC BOFRecord; | 133 | ExcelBREC BOFRecord; |
104 | int position; | 134 | int position; |
105 | int type; | 135 | int type; |
106 | int rows; | 136 | int rows; |
107 | int cols; | 137 | int cols; |
108 | 138 | ||
109 | int cellsize,rowalloc,cellalloc; | 139 | int cellsize,rowalloc,cellalloc; |
110 | QArray <ExcelCell*> Cells; | 140 | QArray <ExcelCell*> Cells; |
111 | bool InitCells(void); // true if ok | 141 | bool InitCells(void); // true if ok |
112 | ExcelCell* Get(int row, int col); | 142 | ExcelCell* Get(int row, int col); |
113 | void Set(int row, int col, ExcelCell* cell); | 143 | void Set(int row, int col, ExcelCell* cell); |
114 | 144 | ||
115 | }; | 145 | }; |
116 | 146 | ||
117 | struct mulrk { | 147 | struct mulrk |
118 | int row; | 148 | { |
119 | int first; | 149 | int row; |
120 | int last; | 150 | int first; |
121 | int numrks; | 151 | int last; |
122 | QArray<int> rknumbers; | 152 | int numrks; |
123 | QArray<double> rkdbls; | 153 | QArray<int> rknumbers; |
124 | QArray<int> xfindices; | 154 | QArray<double> rkdbls; |
155 | QArray<int> xfindices; | ||
125 | }; | 156 | }; |
126 | 157 | ||
127 | |||
128 | |||
129 | |||
130 | class ExcelBook | 158 | class ExcelBook |
131 | { | 159 | { |
132 | public: | 160 | public: |
133 | FILE *File; | 161 | FILE *File; |
134 | int Position; | 162 | int Position; |
135 | //int stringcount; | 163 | //int stringcount; |
136 | QArray <QString*> SharedStrings; | 164 | QArray <QString*> SharedStrings; |
137 | //int xfcount; | 165 | //int xfcount; |
138 | QArray <ExcelFormat*> XFRecords; | 166 | QArray <ExcelFormat*> XFRecords; |
139 | //int Sheetcount; | 167 | //int Sheetcount; |
140 | QArray <ExcelSheet*> Sheets; | 168 | QArray <ExcelSheet*> Sheets; |
141 | //int name count; | 169 | //int name count; |
142 | QArray <QString*> Names; | 170 | QArray <QString*> Names; |
143 | 171 | ||
144 | QString dateformat; | 172 | QString dateformat; |
145 | int Version; | 173 | int Version; |
146 | int endian; | 174 | int endian; |
147 | int Integer2Byte(int b1, int b2 ); | 175 | int Integer2Byte(int b1, int b2 ); |
148 | int Integer4Byte(int b1, int b2, int b3, int b4 ); | 176 | int Integer4Byte(int b1, int b2, int b3, int b4 ); |
149 | int Integer2ByteFile(FILE *f); | 177 | int Integer2ByteFile(FILE *f); |
150 | float Float4Byte(int b1, int b2, int b3, int b4); | 178 | float Float4Byte(int b1, int b2, int b3, int b4); |
151 | double Double4Byte(int b1, int b2, int b3, int b4); | 179 | 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); | 180 | double Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8); |
153 | void DetectEndian(void); | 181 | void DetectEndian(void); |
154 | 182 | ||
155 | bool OpenFile(char *Filename); // true if ok | 183 | bool OpenFile(char *Filename); // true if ok |
156 | bool CloseFile(void); // true if ok | 184 | bool CloseFile(void); // true if ok |
157 | void SeekPosition(int pos); // go to Pos | 185 | void SeekPosition(int pos); // go to Pos |
158 | void SeekSkip(int pos); // skips pos bytes. | 186 | void SeekSkip(int pos); // skips pos bytes. |
159 | int FileEOF(void); //returns -1 if EOF else 0 | 187 | int FileEOF(void); //returns -1 if EOF else 0 |
160 | int Get2Bytes(void); //gets an int from the file | 188 | int Get2Bytes(void); //gets an int from the file |
161 | char* Read(int pos, int length); | 189 | char* Read(int pos, int length); |
162 | QString ReadUnicodeChar(int pos, int length); | 190 | QString ReadUnicodeChar(int pos, int length); |
163 | QString* GetString(int num); //gets the num string from SharedStrings; | 191 | QString* GetString(int num); //gets the num string from SharedStrings; |
164 | int SeekBOF(void); | 192 | int SeekBOF(void); |
165 | ExcelBREC* GetBREC(void); | 193 | ExcelBREC* GetBREC(void); |
166 | ExcelBREC* PeekBREC(void); | 194 | ExcelBREC* PeekBREC(void); |
167 | char* GetDataOfBREC(ExcelBREC* record); | 195 | char* GetDataOfBREC(ExcelBREC* record); |
168 | void ConvertCharToArray(ExcelBREC* record, char* chars, int length); | 196 | void ConvertCharToArray(ExcelBREC* record, char* chars, int length); |
169 | int SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record); | 197 | int SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record); |
170 | int ReadSheet(ExcelSheet* sheet); //read the sheet sheet* | 198 | int ReadSheet(ExcelSheet* sheet); //read the sheet sheet* |
171 | ExcelSheet* GetSheet(void); | 199 | ExcelSheet* GetSheet(void); |
172 | void ParseSheets(void); | 200 | void ParseSheets(void); |
173 | void GetSheets(void); | 201 | void GetSheets(void); |
174 | 202 | ||
175 | bool ParseBook(char *file); // THIS IS THE MAIN PARSE FUNCTION of file | 203 | bool ParseBook(char *file); // THIS IS THE MAIN PARSE FUNCTION of file |
176 | QString GetASCII(char* inbytes, int pos, int chars); | 204 | QString GetASCII(char* inbytes, int pos, int chars); |
177 | QString GetUnicode(char * inbytes, int pos, int chars); | 205 | QString GetUnicode(char * inbytes, int pos, int chars); |
178 | void HandleBoundSheet( ExcelBREC* rec); | 206 | void HandleBoundSheet( ExcelBREC* rec); |
179 | void HandleName(ExcelSheet* sheet, ExcelBREC* rec); | 207 | void HandleName(ExcelSheet* sheet, ExcelBREC* rec); |
180 | ExcelFormat* GetFormatting(int xf); | 208 | ExcelFormat* GetFormatting(int xf); |
181 | void HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes); | 209 | void HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes); |
182 | char* MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont); | 210 | char* MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont); |
183 | void HandleSST(ExcelBREC* rec); | 211 | void HandleSST(ExcelBREC* rec); |
184 | void HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec); | 212 | void HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec); |
185 | ExcelCell* CellLabel(int row, int col, QString str); | 213 | ExcelCell* CellLabel(int row, int col, QString str); |
186 | ExcelCell* CellNumber(int row, int col, int index, double d); | 214 | ExcelCell* CellNumber(int row, int col, int index, double d); |
187 | QString* CellDataString(ExcelSheet* sh, int row, int col); | 215 | QString* CellDataString(ExcelSheet* sh, int row, int col); |
188 | int CellGetPrecision(double d); | 216 | int CellGetPrecision(double d); |
189 | void CellSetDateFormat(char *d); | 217 | void CellSetDateFormat(char *d); |
190 | void HandleMulrk(ExcelSheet* sheet, ExcelBREC* record); | 218 | void HandleMulrk(ExcelSheet* sheet, ExcelBREC* record); |
191 | void MulrkRead(struct mulrk *mulrk, char* data); | 219 | void MulrkRead(struct mulrk *mulrk, char* data); |
192 | void HandleNumber(ExcelSheet* sheet, ExcelBREC* record); | 220 | void HandleNumber(ExcelSheet* sheet, ExcelBREC* record); |
193 | void HandleFormat(ExcelBREC* rec); | 221 | void HandleFormat(ExcelBREC* rec); |
194 | void HandleXF(ExcelBREC* rec); | 222 | void HandleXF(ExcelBREC* rec); |
195 | void HandleRK(ExcelSheet* sheet, ExcelBREC* record); | 223 | void HandleRK(ExcelSheet* sheet, ExcelBREC* record); |
196 | void HandleFormula(ExcelSheet* sheet, ExcelBREC* record); | 224 | void HandleFormula(ExcelSheet* sheet, ExcelBREC* record); |
197 | QString GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz); | 225 | QString GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz); |
198 | QString FindCellName(int row, int col); | 226 | QString FindCellName(int row, int col); |
199 | |||
200 | |||
201 | |||
202 | |||
203 | |||
204 | }; | 227 | }; |
205 | 228 | ||