summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/Excel.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-sheet/Excel.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/Excel.cpp2867
1 files changed, 1457 insertions, 1410 deletions
diff --git a/noncore/apps/opie-sheet/Excel.cpp b/noncore/apps/opie-sheet/Excel.cpp
index fc49d56..57aef20 100644
--- a/noncore/apps/opie-sheet/Excel.cpp
+++ b/noncore/apps/opie-sheet/Excel.cpp
@@ -1,1655 +1,1702 @@
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*/
1 28
29#include "Excel.h"
2 30
31/* STD */
3#include <stdio.h> 32#include <stdio.h>
4#include <stdlib.h> 33#include <stdlib.h>
5#include <math.h> 34#include <math.h>
6#include <time.h> 35#include <time.h>
7#include <sys/types.h> 36#include <sys/types.h>
8#include <strings.h> 37#include <strings.h>
9#include "Excel.h"
10 38
11static xfrecord formatter[] = { 39static xfrecord formatter[] = {
12{ 0xe , DATEFORMAT, "%m/%d/%y"}, 40 { 0xe , DATEFORMAT, "%m/%d/%y"},
13{ 0xf , DATEFORMAT, "%d-%b-%y"}, 41 { 0xf , DATEFORMAT, "%d-%b-%y"},
14{ 0x10, DATEFORMAT, "%d-%b"}, 42 { 0x10, DATEFORMAT, "%d-%b"},
15{ 0x11, DATEFORMAT, "%b-%y"}, 43 { 0x11, DATEFORMAT, "%b-%y"},
16{ 0x12, DATEFORMAT, "%I:%M %p"}, 44 { 0x12, DATEFORMAT, "%I:%M %p"},
17{ 0x13, DATEFORMAT, "%I:%M:%S %p"}, 45 { 0x13, DATEFORMAT, "%I:%M:%S %p"},
18{ 0x14, DATEFORMAT, "%H:%M"}, 46 { 0x14, DATEFORMAT, "%H:%M"},
19{ 0x15, DATEFORMAT, "%H:%M:%S"}, 47 { 0x15, DATEFORMAT, "%H:%M:%S"},
20{ 0x16, DATEFORMAT, "%m/%d/%y %H:%M"}, 48 { 0x16, DATEFORMAT, "%m/%d/%y %H:%M"},
21{ 0x2d, DATEFORMAT, "%M:%S"}, 49 { 0x2d, DATEFORMAT, "%M:%S"},
22{ 0x2e, DATEFORMAT, "%H:%M:%S"}, 50 { 0x2e, DATEFORMAT, "%H:%M:%S"},
23{ 0x2f, DATEFORMAT, "%M:%S"}, 51 { 0x2f, DATEFORMAT, "%M:%S"},
24{ 0xa5, DATEFORMAT, "%m/%d/%y %I:%M %p"}, 52 { 0xa5, DATEFORMAT, "%m/%d/%y %I:%M %p"},
25{ 0x1 , NUMBERFORMAT, "%.0f"}, 53 { 0x1 , NUMBERFORMAT, "%.0f"},
26{ 0x2 , NUMBERFORMAT, "%.2f"}, 54 { 0x2 , NUMBERFORMAT, "%.2f"},
27{ 0x3 , NUMBERFORMAT, "#,##%.0f"}, 55 { 0x3 , NUMBERFORMAT, "#,##%.0f"},
28{ 0x4 , NUMBERFORMAT, "#,##%.2f"}, 56 { 0x4 , NUMBERFORMAT, "#,##%.2f"},
29{ 0x5 , NUMBERFORMAT, "$#,##%.0f"}, 57 { 0x5 , NUMBERFORMAT, "$#,##%.0f"},
30{ 0x6 , NUMBERFORMAT, "$#,##%.0f"}, 58 { 0x6 , NUMBERFORMAT, "$#,##%.0f"},
31{ 0x7 , NUMBERFORMAT, "$#,##%.2f"}, 59 { 0x7 , NUMBERFORMAT, "$#,##%.2f"},
32{ 0x8 , NUMBERFORMAT, "$#,##%.2f"}, 60 { 0x8 , NUMBERFORMAT, "$#,##%.2f"},
33{ 0x9 , NUMBERFORMAT, "%.0f%%"}, 61 { 0x9 , NUMBERFORMAT, "%.0f%%"},
34{ 0xa , NUMBERFORMAT, "%.2f%%"}, 62 { 0xa , NUMBERFORMAT, "%.2f%%"},
35{ 0xb , NUMBERFORMAT, "%e"}, 63 { 0xb , NUMBERFORMAT, "%e"},
36{ 0x25, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, 64 { 0x25, NUMBERFORMAT, "#,##%.0f;(#,##0)"},
37{ 0x26, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, 65 { 0x26, NUMBERFORMAT, "#,##%.0f;(#,##0)"},
38{ 0x27, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, 66 { 0x27, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"},
39{ 0x28, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, 67 { 0x28, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"},
40{ 0x29, NUMBERFORMAT, "#,##%.0f;(#,##0)"}, 68 { 0x29, NUMBERFORMAT, "#,##%.0f;(#,##0)"},
41{ 0x2a, NUMBERFORMAT, "$#,##%.0f;($#,##0)"}, 69 { 0x2a, NUMBERFORMAT, "$#,##%.0f;($#,##0)"},
42{ 0x2b, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"}, 70 { 0x2b, NUMBERFORMAT, "#,##%.2f;(#,##0.00)"},
43{ 0x2c, NUMBERFORMAT, "$#,##%.2f;($#,##0.00)"}, 71 { 0x2c, NUMBERFORMAT, "$#,##%.2f;($#,##0.00)"},
44{ 0x30, NUMBERFORMAT, "##0.0E0"}, 72 { 0x30, NUMBERFORMAT, "##0.0E0"},
45{ 0, 0, ""} 73 { 0, 0, ""}
46}; 74 };
47 75
48 76
49 77
50int ExcelBook::Integer2Byte(int b1, int b2) 78int ExcelBook::Integer2Byte(int b1, int b2)
51{ 79{
52 int i1 = b1 & 0xff; 80 int i1 = b1 & 0xff;
53 int i2 = b2 & 0xff; 81 int i2 = b2 & 0xff;
54 int val = i2 << 8 | i1; 82 int val = i2 << 8 | i1;
55 return val; 83 return val;
56}; 84};
57 85
58int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4) 86int ExcelBook::Integer4Byte(int b1,int b2,int b3,int b4)
59{ 87{
60 int i1 = Integer2Byte(b1, b2); 88 int i1 = Integer2Byte(b1, b2);
61 int i2 = Integer2Byte(b3, b4); 89 int i2 = Integer2Byte(b3, b4);
62 int val = i2 << 16 | i1; 90 int val = i2 << 16 | i1;
63 return val; 91 return val;
64}; 92};
65 93
66int ExcelBook::Integer2ByteFile(FILE *f) { 94int ExcelBook::Integer2ByteFile(FILE *f)
67 int i1, i2; 95{
68 i1 = fgetc(f); 96 int i1, i2;
69 i2 = fgetc(f); 97 i1 = fgetc(f);
70 return Integer2Byte(i1,i2); 98 i2 = fgetc(f);
99 return Integer2Byte(i1,i2);
71}; 100};
72 101
73float ExcelBook::Float4Byte(int b1, int b2, int b3, int b4) 102float ExcelBook::Float4Byte(int b1, int b2, int b3, int b4)
74{ 103{
75 int i; 104 int i;
76 float f; 105 float f;
77 unsigned char *ieee; 106 unsigned char *ieee;
78 ieee = (unsigned char *) &f; 107 ieee = (unsigned char *) &f;
79 for (i = 0; i < 4; i++) ieee[i] = 0; 108 for (i = 0; i < 4; i++) ieee[i] = 0;
80 ieee[0] = ((int)b4) & 0xff; 109 ieee[0] = ((int)b4) & 0xff;
81 ieee[1] = ((int)b3) & 0xff; 110 ieee[1] = ((int)b3) & 0xff;
82 ieee[2] = ((int)b2) & 0xff; 111 ieee[2] = ((int)b2) & 0xff;
83 ieee[3] = ((int)b1) & 0xff; 112 ieee[3] = ((int)b1) & 0xff;
84 return f; 113 return f;
85}; 114};
86 115
87double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4) 116double ExcelBook::Double4Byte(int b1, int b2, int b3, int b4)
88{ 117{
89 long int rk; 118 long int rk;
90 double value; 119 double value;
91 120
92 rk=Integer4Byte(b1,b2,b3,b4); 121 rk=Integer4Byte(b1,b2,b3,b4);
93 //printf("Double4Bytes:%d,%d,%d,%d\r\n",b1,b2,b3,b4); 122 //printf("Double4Bytes:%d,%d,%d,%d\r\n",b1,b2,b3,b4);
94 if ( (rk & 0x02) != 0) 123 if ( (rk & 0x02) != 0)
95 { 124 {
96 long int intval = rk >> 2; //drops the 2 bits 125 long int intval = rk >> 2; //drops the 2 bits
97 printf("Double4Byte:intval=%d, rk=%d, rk>>2=%d\r\n",intval,rk,rk>>2); 126 printf("Double4Byte:intval=%d, rk=%d, rk>>2=%d\r\n",intval,rk,rk>>2);
98 value = (double) intval; 127 value = (double) intval;
99 printf("Double4Byte: VALUEINT=%f\r\n",value); 128 printf("Double4Byte: VALUEINT=%f\r\n",value);
100 if ( (rk & 0x01) != 0) 129 if ( (rk & 0x01) != 0)
101 { 130 {
102 value /= 100.0; 131 value /= 100.0;
103 }; 132 };
104 return value; 133 return value;
105 }else 134 }
106 { 135 else
107 136 {
108 union { double d; unsigned long int b[2]; } dbl_byte; 137
109 unsigned long int valbits = (rk & 0xfffffffc); 138 union { double d; unsigned long int b[2]; } dbl_byte;
110 #if defined(__arm__) && !defined(__vfp__) 139 unsigned long int valbits = (rk & 0xfffffffc);
111 dbl_byte.b[0]=valbits; 140#if defined(__arm__) && !defined(__vfp__)
112 dbl_byte.b[1]=0; 141 dbl_byte.b[0]=valbits;
113 #else 142 dbl_byte.b[1]=0;
114 dbl_byte.b[0]=0; 143#else
115 dbl_byte.b[1]=valbits; 144 dbl_byte.b[0]=0;
116 #endif 145 dbl_byte.b[1]=valbits;
117 printf("dbl_byte.b[0]=%d,dbl_byte.b[1]=%d\r\n",dbl_byte.b[0],dbl_byte.b[1]); 146#endif
118 value=dbl_byte.d; 147 printf("dbl_byte.b[0]=%d,dbl_byte.b[1]=%d\r\n",dbl_byte.b[0],dbl_byte.b[1]);
119 printf("Double4Byte: VALUE=%f\r\n",value); 148 value=dbl_byte.d;
120 149 printf("Double4Byte: VALUE=%f\r\n",value);
121 if ( (rk & 0x01) != 0) 150
122 { 151 if ( (rk & 0x01) != 0)
123 value /= 100.0; 152 {
124 }; 153 value /= 100.0;
125 return value; 154 };
126 }; 155 return value;
156 };
127}; 157};
128 158
129void ExcelBook::DetectEndian(void) 159void ExcelBook::DetectEndian(void)
130{ 160{
131 int end; 161 int end;
132 long i = 0x44332211; 162 long i = 0x44332211;
133 unsigned char* a = (unsigned char*) &i; 163 unsigned char* a = (unsigned char*) &i;
134 end = (*a != 0x11); 164 end = (*a != 0x11);
135 if (end == 1) { 165 if (end == 1)
136 endian = BIG_ENDIAN; 166 {
137 printf("BIGENDIAN!\r\n"); 167 endian = BIG_ENDIAN;
138 } else { 168 printf("BIGENDIAN!\r\n");
139 endian = LITTLE_ENDIAN; 169 }
140 printf("LITTLEENDIAN!\r\n"); 170 else
141 } 171 {
172 endian = LITTLE_ENDIAN;
173 printf("LITTLEENDIAN!\r\n");
174 }
142}; 175};
143 176
144double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8) 177double ExcelBook::Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8)
145{ 178{
146 int i; 179 int i;
147 double d; 180 double d;
148 unsigned char *ieee; 181 unsigned char *ieee;
149 ieee = (unsigned char *)&d; 182 ieee = (unsigned char *)&d;
150 for (i = 0; i < 8; i++) ieee[i] = 0; 183 for (i = 0; i < 8; i++) ieee[i] = 0;
151 if (endian == BIG_ENDIAN) { 184 if (endian == BIG_ENDIAN)
152 ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff; 185 {
153 ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff; 186 ieee[0] = ((int)b8) & 0xff;ieee[1] = ((int)b7) & 0xff;
154 ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff; 187 ieee[2] = ((int)b6) & 0xff;ieee[3] = ((int)b5) & 0xff;
155 ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff; 188 ieee[4] = ((int)b4) & 0xff;ieee[5] = ((int)b3) & 0xff;
156 } else { 189 ieee[6] = ((int)b2) & 0xff;ieee[7] = ((int)b1) & 0xff;
157 ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff; 190 }
158 ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff; 191 else
159 ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff; 192 {
160 ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff; 193 ieee[0] = ((int)b1) & 0xff;ieee[1] = ((int)b2) & 0xff;
161 } 194 ieee[2] = ((int)b3) & 0xff;ieee[3] = ((int)b4) & 0xff;
162 return d; 195 ieee[4] = ((int)b5) & 0xff;ieee[5] = ((int)b6) & 0xff;
196 ieee[6] = ((int)b7) & 0xff;ieee[7] = ((int)b8) & 0xff;
197 }
198 return d;
163}; 199};
164 200
165bool ExcelBook::OpenFile(char *Filename) 201bool ExcelBook::OpenFile(char *Filename)
166{ 202{
167 printf("Opening excel file!\r\n"); 203 printf("Opening excel file!\r\n");
168 File= fopen(Filename, "r"); 204 File= fopen(Filename, "r");
169 Position=0; // first byte index in file 205 Position=0; // first byte index in file
170 XFRecords.resize(0); 206 XFRecords.resize(0);
171 SharedStrings.resize(0); 207 SharedStrings.resize(0);
172 Names.resize(0); 208 Names.resize(0);
173 Sheets.resize(0); 209 Sheets.resize(0);
174 if(File==NULL) return false; 210 if(File==NULL) return false;
175 printf("Opened excel file!\r\n"); 211 printf("Opened excel file!\r\n");
176 return true; 212 return true;
177}; 213};
178 214
179bool ExcelBook::CloseFile(void) 215bool ExcelBook::CloseFile(void)
180{ 216{
181 int w1; 217 int w1;
182 for(w1=0;w1<(int)XFRecords.count();w1++) 218 for(w1=0;w1<(int)XFRecords.count();w1++)
183 { 219 {
184 if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;}; 220 if(XFRecords[w1]!=NULL) {delete XFRecords[w1];XFRecords[w1]=NULL;};
185 }; 221 };
186 for(w1=0;w1<(int)SharedStrings.count();w1++) 222 for(w1=0;w1<(int)SharedStrings.count();w1++)
187 { 223 {
188 if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;}; 224 if(SharedStrings[w1]!=NULL) {delete SharedStrings[w1];SharedStrings[w1]=NULL;};
189 }; 225 };
190 for(w1=0;w1<(int)Names.count();w1++) 226 for(w1=0;w1<(int)Names.count();w1++)
191 { 227 {
192 if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;}; 228 if(Names[w1]!=NULL) {delete Names[w1];Names[w1]=NULL;};
193 }; 229 };
194 for(w1=0;w1<(int)Sheets.count();w1++) 230 for(w1=0;w1<(int)Sheets.count();w1++)
195 { 231 {
196 if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;}; 232 if(Sheets[w1]!=NULL) {delete Sheets[w1];Sheets[w1]=NULL;};
197 }; 233 };
198 XFRecords.resize(0); 234 XFRecords.resize(0);
199 SharedStrings.resize(0); 235 SharedStrings.resize(0);
200 Names.resize(0); 236 Names.resize(0);
201 Sheets.resize(0); 237 Sheets.resize(0);
202 fclose(File); 238 fclose(File);
203 printf("closed excel file!\r\n"); 239 printf("closed excel file!\r\n");
204 if(File==NULL) return true; 240 if(File==NULL) return true;
205 return false; 241 return false;
206}; 242};
207 243
208void ExcelBook::SeekPosition(int pos) 244void ExcelBook::SeekPosition(int pos)
209{ 245{
210 if(!feof(File)) 246 if(!feof(File))
211 { 247 {
212 Position=pos; 248 Position=pos;
213 //printf("SeekPosition:Pos:%d\r\n",Position); 249 //printf("SeekPosition:Pos:%d\r\n",Position);
214 fseek(File,pos,SEEK_SET); 250 fseek(File,pos,SEEK_SET);
215 }; 251 };
216}; 252};
217 253
218void ExcelBook::SeekSkip(int pos) 254void ExcelBook::SeekSkip(int pos)
219{ 255{
220 if(!feof(File)) 256 if(!feof(File))
221 { 257 {
222 Position=Position+pos; 258 Position=Position+pos;
223 //printf("SeekSkip:Pos:%d\r\n",Position); 259 //printf("SeekSkip:Pos:%d\r\n",Position);
224 fseek(File, Position, SEEK_SET); 260 fseek(File, Position, SEEK_SET);
225 }; 261 };
226}; 262};
227 263
228int ExcelBook::FileEOF(void) 264int ExcelBook::FileEOF(void)
229{ 265{
230 if(File!=NULL) return(feof(File)); else return 0; 266 if(File!=NULL) return(feof(File)); else return 0;
231 //EOF is defined in stdlib as -1 267 //EOF is defined in stdlib as -1
232}; 268};
233 269
234int ExcelBook::Get2Bytes(void) 270int ExcelBook::Get2Bytes(void)
235{ 271{
236 int i1,i2; 272 int i1,i2;
237 i1=0; i2=0; 273 i1=0; i2=0;
238 if (!feof(File)) 274 if (!feof(File))
239 { 275 {
240 i1=fgetc(File); 276 i1=fgetc(File);
241 Position++; 277 Position++;
242 }; 278 };
243 if (!feof(File)) 279 if (!feof(File))
244 { 280 {
245 i2=fgetc(File); 281 i2=fgetc(File);
246 Position++; 282 Position++;
247 }; 283 };
248 return Integer2Byte(i1,i2); 284 return Integer2Byte(i1,i2);
249}; 285};
250 286
251char* ExcelBook::Read(int pos, int length) 287char* ExcelBook::Read(int pos, int length)
252{ 288{
253 int i; 289 int i;
254 char *data; 290 char *data;
255 data= new char[length]; 291 data= new char[length];
256 SeekPosition(pos); 292 SeekPosition(pos);
257 for(i=0; i<length; i++) 293 for(i=0; i<length; i++)
258 { 294 {
259 if(!feof(File)) data[i]=fgetc(File); 295 if(!feof(File)) data[i]=fgetc(File);
260 }; 296 };
261 Position= Position+length; 297 Position= Position+length;
262 return data; 298 return data;
263}; 299};
264 300
265QString ExcelBook::ReadUnicodeChar(int pos, int length) 301QString ExcelBook::ReadUnicodeChar(int pos, int length)
266{ 302{
267 int i; 303 int i;
268 QString data; 304 QString data;
269 int i1=' ',i2=' ',ii; 305 int i1=' ',i2=' ',ii;
270 SeekPosition(pos); 306 SeekPosition(pos);
271 for(i=0; i<length; i++) 307 for(i=0; i<length; i++)
272 { 308 {
273 if(!feof(File)) i1=fgetc(File); 309 if(!feof(File)) i1=fgetc(File);
274 if(!feof(File)) i2=fgetc(File); 310 if(!feof(File)) i2=fgetc(File);
275 ii=Integer2Byte(i1,i2); 311 ii=Integer2Byte(i1,i2);
276 data.append(ii); 312 data.append(ii);
277 Position+=2; 313 Position+=2;
278 }; 314 };
279 return data; 315 return data;
280}; 316};
281 317
282QString* ExcelBook::GetString(int num) 318QString* ExcelBook::GetString(int num)
283{ 319{
284 if(num>=0 && num<(int)SharedStrings.count()) 320 if(num>=0 && num<(int)SharedStrings.count())
285 { 321 {
286 return SharedStrings[num]; 322 return SharedStrings[num];
287 }; 323 };
288 return new QString(""); 324 return new QString("");
289}; 325};
290 326
291int ExcelBook::SeekBOF(void) 327int ExcelBook::SeekBOF(void)
292{ 328{
293 int opcode,version,streamtype,length,ret=0; 329 int opcode,version,streamtype,length,ret=0;
294 char *data; 330 char *data;
295 while(!feof(File)) 331 while(!feof(File))
296 { 332 {
297 opcode=Get2Bytes(); 333 opcode=Get2Bytes();
298 if(opcode==XL_BOF) 334 if(opcode==XL_BOF)
299 { 335 {
300 length=Get2Bytes(); 336 length=Get2Bytes();
301 data=Read(Position,length); 337 data=Read(Position,length);
302 version=Integer2Byte(data[0], data[1]); 338 version=Integer2Byte(data[0], data[1]);
303 streamtype=Integer2Byte(data[2], data[3]); 339 streamtype=Integer2Byte(data[2], data[3]);
304 printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version); 340 printf("SEEKBOF:opcode=XLBOF, %d ,version %d\r\n",Position,version);
305 delete data; data=NULL; 341 delete data; data=NULL;
306 if (version==BIFF8) ret=8; 342 if (version==BIFF8) ret=8;
307 else if(version==BIFF7) ret=7; 343 else if(version==BIFF7) ret=7;
308 printf("SEEKBOF:versionBIFF%d\r\n",ret); 344 printf("SEEKBOF:versionBIFF%d\r\n",ret);
309 if(streamtype==WBKGLOBAL) return ret *2; 345 if(streamtype==WBKGLOBAL) return ret *2;
310 else if(streamtype==WRKSHEET) return ret *1; 346 else if(streamtype==WRKSHEET) return ret *1;
311 return 1; 347 return 1;
312 }; 348 };
313 }; 349 };
314 return 0; 350 return 0;
315}; 351};
316 352
317ExcelBREC* ExcelBook::GetBREC(void) 353ExcelBREC* ExcelBook::GetBREC(void)
318{ 354{
319 ExcelBREC* rec; 355 ExcelBREC* rec;
320 rec= new ExcelBREC; 356 rec= new ExcelBREC;
321 if(FileEOF()) return NULL; 357 if(FileEOF()) return NULL;
322 rec->data=NULL; 358 rec->data=NULL;
323 rec->code=Get2Bytes(); 359 rec->code=Get2Bytes();
324 rec->length=Get2Bytes(); 360 rec->length=Get2Bytes();
325 rec->position=Position; 361 rec->position=Position;
326 SeekSkip(rec->length); 362 SeekSkip(rec->length);
327 return rec; 363 return rec;
328}; 364};
329 365
330ExcelBREC* ExcelBook::PeekBREC(void) 366ExcelBREC* ExcelBook::PeekBREC(void)
331{ 367{
332 int oldpos; 368 int oldpos;
333 ExcelBREC* NextRec; 369 ExcelBREC* NextRec;
334 oldpos=Position; 370 oldpos=Position;
335 NextRec=GetBREC(); 371 NextRec=GetBREC();
336 SeekPosition(oldpos); 372 SeekPosition(oldpos);
337 return NextRec; 373 return NextRec;
338}; 374};
339 375
340char* ExcelBook::GetDataOfBREC(ExcelBREC* record) 376char* ExcelBook::GetDataOfBREC(ExcelBREC* record)
341{ 377{
342 if(record->data==NULL) 378 if(record->data==NULL)
343 { 379 {
344 ConvertCharToArray(record,Read(record->position,record->length),record->length); 380 ConvertCharToArray(record,Read(record->position,record->length),record->length);
345 }; 381 };
346 return record->data;//new? 382 return record->data;//new?
347}; 383};
348 384
349void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length) 385void ExcelBook::ConvertCharToArray(ExcelBREC* record, char* chars, int length)
350{ 386{
351 record->data=new char[length]; 387 record->data=new char[length];
352 for(int w1=0;w1<=length-1;w1++) 388 for(int w1=0;w1<=length-1;w1++)
353 record->data[w1]=chars[w1]; 389 record->data[w1]=chars[w1];
354}; 390};
355 391
356 392
357bool ExcelSheet::InitCells() 393bool ExcelSheet::InitCells()
358{ 394{
359 int r; 395 int r;
360 Cells.resize(rows * cols + cols+1); 396 Cells.resize(rows * cols + cols+1);
361 if(Cells.count()==0) return false; 397 if(Cells.count()==0) return false;
362 for(r=0;r < Cells.count();r++) 398 for(r=0;r < Cells.count();r++)
363 { 399 {
364 Cells[r]=NULL; 400 Cells[r]=NULL;
365 }; 401 };
366 return true; 402 return true;
367}; 403};
368 404
369void ExcelSheet::Set(int row, int col, ExcelCell* cell) 405void ExcelSheet::Set(int row, int col, ExcelCell* cell)
370{ 406{
371 if(cell!=NULL&&(row*cols+col)<Cells.count()) 407 if(cell!=NULL&&(row*cols+col)<Cells.count())
372 { 408 {
373 Cells[row*cols+col]=cell; 409 Cells[row*cols+col]=cell;
374 }; 410 };
375}; 411};
376 412
377ExcelCell* ExcelSheet::Get(int row, int col) 413ExcelCell* ExcelSheet::Get(int row, int col)
378{ 414{
379 ExcelCell* cell; 415 ExcelCell* cell;
380 cell=Cells[row*cols+col]; 416 cell=Cells[row*cols+col];
381 if(cell==NULL) return NULL; 417 if(cell==NULL) return NULL;
382 return cell; 418 return cell;
383}; 419};
384 420
385int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record) 421int ExcelBook::SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record)
386{ 422{
387 char* data=NULL; 423 char* data=NULL;
388 switch (record->code) 424 switch (record->code)
389 { 425 {
390 case XL_DIMENSION: 426 case XL_DIMENSION:
391 data = GetDataOfBREC(record); 427 data = GetDataOfBREC(record);
392 if (record->length == 10) 428 if (record->length == 10)
393 { 429 {
394 sheet->rows = Integer2Byte(data[2], data[3]); 430 sheet->rows = Integer2Byte(data[2], data[3]);
395 sheet->cols = Integer2Byte(data[6], data[7]); 431 sheet->cols = Integer2Byte(data[6], data[7]);
396 } else 432 }
397 { 433 else
398 sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]); 434 {
399 sheet->cols = Integer2Byte(data[10], data[11]); 435 sheet->rows = Integer4Byte(data[4], data[5], data[6], data[7]);
400 } 436 sheet->cols = Integer2Byte(data[10], data[11]);
401 sheet->InitCells(); 437 }
402 break; 438 sheet->InitCells();
403 439 break;
404 case XL_LABELSST: 440
405 HandleLabelSST(sheet, record); 441 case XL_LABELSST:
406 break; 442 HandleLabelSST(sheet, record);
407 443 break;
408 case XL_RK: 444
409 case XL_RK2: 445 case XL_RK:
410 HandleRK(sheet, record); 446 case XL_RK2:
411 break; 447 HandleRK(sheet, record);
412 448 break;
413 case XL_MULRK: 449
414 HandleMulrk(sheet, record); 450 case XL_MULRK:
415 break; 451 HandleMulrk(sheet, record);
416 452 break;
417 case XL_ROW: 453
418 break; 454 case XL_ROW:
419 455 break;
420 case XL_NUMBER: 456
421 HandleNumber(sheet, record); 457 case XL_NUMBER:
422 break; 458 HandleNumber(sheet, record);
423 459 break;
424 case XL_BOOLERR: 460
425 break; 461 case XL_BOOLERR:
426 462 break;
427 case XL_CONTINUE: 463
428 break; 464 case XL_CONTINUE:
429 465 break;
430 case XL_FORMULA: 466
431 case XL_FORMULA2: 467 case XL_FORMULA:
432 HandleFormula(sheet, record); 468 case XL_FORMULA2:
433 break; 469 HandleFormula(sheet, record);
434 470 break;
435 case XL_LABEL: 471
436 break; 472 case XL_LABEL:
437 473 break;
438 case XL_NAME: 474
439 HandleName(sheet, record); 475 case XL_NAME:
440 break; 476 HandleName(sheet, record);
441 477 break;
442 case XL_BOF: 478
443 break; 479 case XL_BOF:
444 case XL_EOF: 480 break;
445 return 0; 481 case XL_EOF:
446 default: 482 return 0;
447 break; 483 default:
448 }; 484 break;
449 return 1; 485 };
486 return 1;
450}; 487};
451 488
452int ExcelBook::ReadSheet(ExcelSheet* sheet) 489int ExcelBook::ReadSheet(ExcelSheet* sheet)
453{ 490{
454 ExcelBREC* record; 491 ExcelBREC* record;
455 int oldpos; 492 int oldpos;
456 oldpos = Position; 493 oldpos = Position;
457 SeekPosition(sheet->position); 494 SeekPosition(sheet->position);
458 record = GetBREC(); 495 record = GetBREC();
459 while (record!=NULL) 496 while (record!=NULL)
460 { 497 {
461 if (!SheetHandleRecord(sheet, record)) break; 498 if (!SheetHandleRecord(sheet, record)) break;
462 record=GetBREC(); 499 record=GetBREC();
463 }; 500 };
464 SeekPosition(oldpos); 501 SeekPosition(oldpos);
465 return 1; 502 return 1;
466}; 503};
467 504
468ExcelSheet* ExcelBook::GetSheet(void) 505ExcelSheet* ExcelBook::GetSheet(void)
469{ 506{
470 ExcelSheet* sh=NULL; 507 ExcelSheet* sh=NULL;
471 int type; 508 int type;
472 type=SeekBOF(); 509 type=SeekBOF();
473 Version=type; 510 Version=type;
474 sh=new ExcelSheet; 511 sh=new ExcelSheet;
475 if(type) 512 if(type)
476 { 513 {
477 sh->type=type; 514 sh->type=type;
478 sh->position=Position; 515 sh->position=Position;
479 sh->name=QString(""); 516 sh->name=QString("");
480 }; 517 };
481 if(type==8||type==7) 518 if(type==8||type==7)
482 { 519 {
483 ReadSheet(sh); 520 ReadSheet(sh);
484 }; 521 };
485 return sh; 522 return sh;
486}; 523};
487 524
488void ExcelBook::ParseSheets(void) 525void ExcelBook::ParseSheets(void)
489{ 526{
490 int BOFs; 527 int BOFs;
491 ExcelBREC* r; 528 ExcelBREC* r;
492 BOFs=1; 529 BOFs=1;
493 r=GetBREC(); 530 r=GetBREC();
494 while(BOFs) 531 while(BOFs)
495 { 532 {
496 r=GetBREC(); 533 r=GetBREC();
497 switch(r->code) 534 switch(r->code)
498 { 535 {
499 case XL_SST: 536 case XL_SST:
500 HandleSST(r); 537 HandleSST(r);
501 break; 538 break;
502 539
503 case XL_TXO: 540 case XL_TXO:
504 break; 541 break;
505 case XL_NAME: 542 case XL_NAME:
506 break; 543 break;
507 case XL_ROW: 544 case XL_ROW:
508 break; 545 break;
509 546
510 case XL_FORMAT: 547 case XL_FORMAT:
511 HandleFormat(r); 548 HandleFormat(r);
512 break; 549 break;
513 550
514 case XL_XF: 551 case XL_XF:
515 HandleXF(r); 552 HandleXF(r);
516 break; 553 break;
517 554
518 case XL_BOUNDSHEET: 555 case XL_BOUNDSHEET:
519 HandleBoundSheet(r); 556 HandleBoundSheet(r);
520 break; 557 break;
521 558
522 case XL_EXTSST: 559 case XL_EXTSST:
523 break; 560 break;
524 case XL_CONTINUE: 561 case XL_CONTINUE:
525 break; 562 break;
526 563
527 case XL_EOF: 564 case XL_EOF:
528 BOFs--; 565 BOFs--;
529 break; 566 break;
530 567
531 default: 568 default:
532 break; 569 break;
533 }; 570 };
534 }; 571 };
535}; 572};
536 573
537void ExcelBook::GetSheets(void) 574void ExcelBook::GetSheets(void)
538{ 575{
539 ExcelSheet* sheet; 576 ExcelSheet* sheet;
540 Sheets.resize(0); 577 Sheets.resize(0);
541 sheet=GetSheet(); 578 sheet=GetSheet();
542 while (sheet->Cells.count()!= 0 ) 579 while (sheet->Cells.count()!= 0 )
543 { 580 {
544 Sheets.resize(Sheets.count()+1); 581 Sheets.resize(Sheets.count()+1);
545 Sheets[Sheets.count()-1]=sheet; 582 Sheets[Sheets.count()-1]=sheet;
546 sheet->name=*Names[Sheets.count()-1]; 583 sheet->name=*Names[Sheets.count()-1];
547 sheet=GetSheet(); 584 sheet=GetSheet();
548 }; 585 };
549}; 586};
550 587
551bool ExcelBook::ParseBook(char *file) 588bool ExcelBook::ParseBook(char *file)
552{ 589{
553 dateformat=QString(""); 590 dateformat=QString("");
554 DetectEndian(); 591 DetectEndian();
555 OpenFile(file); 592 OpenFile(file);
556 SeekBOF(); 593 SeekBOF();
557 ParseSheets(); 594 ParseSheets();
558 GetSheets(); 595 GetSheets();
559 return true; 596 return true;
560}; 597};
561 598
562QString ExcelBook::GetASCII(char* inbytes, int pos, int chars) 599QString ExcelBook::GetASCII(char* inbytes, int pos, int chars)
563{ 600{
564 int i; 601 int i;
565 QString outstr=""; 602 QString outstr="";
566 for (i = 0; i < chars; i++) 603 for (i = 0; i < chars; i++)
567 { 604 {
568 outstr.append(inbytes[i+pos]); 605 outstr.append(inbytes[i+pos]);
569 }; 606 };
570 return outstr; 607 return outstr;
571}; 608};
572 609
573QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars) 610QString ExcelBook::GetUnicode(char * inbytes, int pos, int chars)
574{ 611{
575 QString outstr=""; 612 QString outstr="";
576 int i; 613 int i;
577 int rc; 614 int rc;
578 for (i=0; i<chars*2; i++) 615 for (i=0; i<chars*2; i++)
579 { 616 {
580 rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]); 617 rc=Integer2Byte(inbytes[i+pos],inbytes[i+pos+1]);
581 outstr.append(QChar(rc)); 618 outstr.append(QChar(rc));
582 i++; 619 i++;
583 }; 620 };
584 return outstr; 621 return outstr;
585}; 622};
586 623
587 624
588void ExcelBook::HandleBoundSheet(ExcelBREC* rec) 625void ExcelBook::HandleBoundSheet(ExcelBREC* rec)
589{ 626{
590 char* data; 627 char* data;
591 int type; 628 int type;
592 int visibility; 629 int visibility;
593 int length; 630 int length;
594 int pos; 631 int pos;
595 QString name; 632 QString name;
596 pos = 8; 633 pos = 8;
597 data = GetDataOfBREC(rec); 634 data = GetDataOfBREC(rec);
598 type = data[4]; 635 type = data[4];
599 visibility = data[5]; 636 visibility = data[5];
600 length = data[6]; 637 length = data[6];
601 if(data[7]==0) 638 if(data[7]==0)
602 { 639 {
603 //ascii 640 //ascii
604 name=GetASCII(data,pos,length); 641 name=GetASCII(data,pos,length);
605 }else 642 }
606 { 643 else
607 name=GetUnicode(data,pos,length); 644 {
608 }; 645 name=GetUnicode(data,pos,length);
609 Names.resize(Names.count()+1); 646 };
610 Names[Names.count()-1]=new QString(name); 647 Names.resize(Names.count()+1);
648 Names[Names.count()-1]=new QString(name);
611}; 649};
612 650
613void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec) 651void ExcelBook::HandleName(ExcelSheet* sheet, ExcelBREC* rec)
614{ 652{
615 char* data; 653 char* data;
616 QString name; 654 QString name;
617 int length; 655 int length;
618 int pos; 656 int pos;
619 pos = 15; 657 pos = 15;
620 data = GetDataOfBREC(rec); 658 data = GetDataOfBREC(rec);
621 length = data[3]; 659 length = data[3];
622 name = GetASCII(data,pos,length); 660 name = GetASCII(data,pos,length);
623 661
624 662
625}; 663};
626 664
627ExcelFormat* ExcelBook::GetFormatting(int xf) 665ExcelFormat* ExcelBook::GetFormatting(int xf)
628{ 666{
629 int i; 667 int i;
630 ExcelFormat* rec; 668 ExcelFormat* rec;
631 rec=new ExcelFormat(); 669 rec=new ExcelFormat();
632 for (i = 0; formatter[i].code != 0; i++) 670 for (i = 0; formatter[i].code != 0; i++)
633 { 671 {
634 if (xf == formatter[i].code) break; 672 if (xf == formatter[i].code) break;
635 }; 673 };
636 if (formatter[i].format ==NULL) return NULL; 674 if (formatter[i].format ==NULL) return NULL;
637 rec->code = xf; 675 rec->code = xf;
638 rec->type = formatter[i].type; 676 rec->type = formatter[i].type;
639 rec->format = formatter[i].format; 677 rec->format = formatter[i].format;
640 return rec; 678 return rec;
641}; 679};
642 680
643void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes) 681void ExcelBook::HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes)
644{ 682{
645 QString str=QString(""); 683 QString str=QString("");
646 char* data; 684 char* data;
647 int chars, pos, options, i; 685 int chars, pos, options, i;
648 int richstring, fareaststring, runlength=0; 686 int richstring, fareaststring, runlength=0;
649 int richruns=0,fareastsize=0; 687 int richruns=0,fareastsize=0;
650 int totalstrings; 688 int totalstrings;
651 int uniquestrings; 689 int uniquestrings;
652 data = GetDataOfBREC(rec); 690 data = GetDataOfBREC(rec);
653 totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]); 691 totalstrings = Integer4Byte(data[0], data[1], data[2], data[3]);
654 uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]); 692 uniquestrings = Integer4Byte(data[4], data[5], data[6], data[7]);
655 pos = 8; 693 pos = 8;
656 for (i = 0; i < uniquestrings; i++) 694 for (i = 0; i < uniquestrings; i++)
657 { 695 {
658 richruns=0; fareastsize=0; 696 richruns=0; fareastsize=0;
659 chars = Integer2Byte(data[pos], data[pos+1]); 697 chars = Integer2Byte(data[pos], data[pos+1]);
660 pos += 2; 698 pos += 2;
661 options = data[pos]; 699 options = data[pos];
662 pos++; 700 pos++;
663 fareaststring = ((options & 0x04) != 0); 701 fareaststring = ((options & 0x04) != 0);
664 richstring = ((options & 0x08) != 0); 702 richstring = ((options & 0x08) != 0);
665 if(richstring) 703 if(richstring)
666 { 704 {
667 richruns= Integer2Byte(data[pos],data[pos+1]); 705 richruns= Integer2Byte(data[pos],data[pos+1]);
668 pos+=2; 706 pos+=2;
669 }; 707 };
670 if(fareaststring) 708 if(fareaststring)
671 { 709 {
672 fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]); 710 fareastsize=Integer4Byte(data[pos], data[pos+1], data[pos+2], data[pos+3]);
673 pos+=4; 711 pos+=4;
674 }; 712 };
675 713
676 if ((options & 0x01) == 0) //8 bit chars 714 if ((options & 0x01) == 0) //8 bit chars
677 { 715 {
678 /* ascii */ 716 /* ascii */
679 str = GetASCII(bytes,pos,chars); 717 str = GetASCII(bytes,pos,chars);
680 pos=pos+chars; 718 pos=pos+chars;
681 if(str[0]=='=') str[0]=' '; 719 if(str[0]=='=') str[0]=' ';
682 }else //16 bit chars 720 }else //16 bit chars
683 { 721 {
684 /* unicode */ 722 /* unicode */
685 str = GetUnicode(bytes,pos,chars); 723 str = GetUnicode(bytes,pos,chars);
686 pos=pos+chars*2; 724 pos=pos+chars*2;
687 }; 725 };
688 // HERE TO PUT richformat handling 726 // HERE TO PUT richformat handling
689 if (richstring) 727 if (richstring)
690 { 728 {
691 pos += 4 * richruns; 729 pos += 4 * richruns;
692 }; 730 };
693 if (fareaststring) 731 if (fareaststring)
694 { 732 {
695 pos += fareastsize; 733 pos += fareastsize;
696 }; 734 };
697 //printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode()); 735 //printf("String=%s, length=%d first=0x%x\r\n",str.ascii(),str.length(),str[0].unicode());
698 SharedStrings.resize(SharedStrings.count()+1); 736 SharedStrings.resize(SharedStrings.count()+1);
699 SharedStrings[SharedStrings.count()-1]=new QString(str); 737 SharedStrings[SharedStrings.count()-1]=new QString(str);
700 } 738 }
701}; 739};
702 740
703 741
704char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont) 742char* ExcelBook::MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont)
705{ 743{
706 int i, pos; 744 int i, pos;
707 int length; 745 int length;
708 746
709 char* data; 747 char* data;
710 char* bytes; 748 char* bytes;
711 length = rec->length; 749 length = rec->length;
712 for (i = 0; i < (int) cont->rec.count(); i++) 750 for (i = 0; i < (int) cont->rec.count(); i++)
713 { 751 {
714 length += cont->rec[i]->length; 752 length += cont->rec[i]->length;
715 } 753 }
716 bytes = GetDataOfBREC(rec); 754 bytes = GetDataOfBREC(rec);
717 pos = rec->length; 755 pos = rec->length;
718 for (i = 0; i < (int) cont->rec.count(); i++) 756 for (i = 0; i < (int) cont->rec.count(); i++)
719 { 757 {
720 data = GetDataOfBREC(cont->rec[i]); 758 data = GetDataOfBREC(cont->rec[i]);
721 *bytes += pos; 759 *bytes += pos;
722 bytes = data; 760 bytes = data;
723 pos += cont->rec[i]->length; 761 pos += cont->rec[i]->length;
724 } 762 }
725 return bytes; 763 return bytes;
726}; 764};
727 765
728 766
729void ExcelBook::HandleSST(ExcelBREC* rec) 767void ExcelBook::HandleSST(ExcelBREC* rec)
730{ 768{
731 char* bytes; 769 char* bytes;
732 SSTList* cont; 770 SSTList* cont;
733 cont= new SSTList; 771 cont= new SSTList;
734 ExcelBREC* nr; 772 ExcelBREC* nr;
735 nr = PeekBREC(); 773 nr = PeekBREC();
736 while (nr->code == XL_CONTINUE) 774 while (nr->code == XL_CONTINUE)
737 { 775 {
738 cont->rec.resize(cont->rec.count()+1); 776 cont->rec.resize(cont->rec.count()+1);
739 cont->rec[cont->rec.count()-1]=GetBREC(); 777 cont->rec[cont->rec.count()-1]=GetBREC();
740 nr = PeekBREC(); 778 nr = PeekBREC();
741 } 779 }
742 bytes = MergeBytesFromSSTs(rec,cont); 780 bytes = MergeBytesFromSSTs(rec,cont);
743 HandleSetOfSST(rec, bytes); 781 HandleSetOfSST(rec, bytes);
744 for(int w1=0;w1<(int)cont->rec.count();w1++) 782 for(int w1=0;w1<(int)cont->rec.count();w1++)
745 { 783 {
746 if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;}; 784 if(cont->rec[w1]!=NULL) {delete cont->rec[w1];cont->rec[w1]=NULL;};
747 }; 785 };
748 cont->rec.resize(0); 786 cont->rec.resize(0);
749}; 787};
750 788
751void ExcelBook::HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec) 789void ExcelBook::HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec)
752{ 790{
753 int index, row, col; 791 int index, row, col;
754 char* data; 792 char* data;
755 data = GetDataOfBREC(rec); 793 data = GetDataOfBREC(rec);
756 index = Integer4Byte(data[6], data[7], data[8], data[9]); 794 index = Integer4Byte(data[6], data[7], data[8], data[9]);
757 row = Integer2Byte(data[0], data[1]); 795 row = Integer2Byte(data[0], data[1]);
758 col = Integer2Byte(data[2], data[3]); 796 col = Integer2Byte(data[2], data[3]);
759 sheet->Set(row,col, CellLabel(row, col, *GetString(index))); 797 sheet->Set(row,col, CellLabel(row, col, *GetString(index)));
760}; 798};
761 799
762ExcelCell* ExcelBook::CellLabel(int row, int col, QString str) 800ExcelCell* ExcelBook::CellLabel(int row, int col, QString str)
763{ 801{
764 ExcelCell* c; 802 ExcelCell* c;
765 c= new ExcelCell; 803 c= new ExcelCell;
766 c->row = row; 804 c->row = row;
767 c->col = col; 805 c->col = col;
768 c->type = CELL_LABEL; 806 c->type = CELL_LABEL;
769 c->valuec = str; 807 c->valuec = str;
770 return c; 808 return c;
771}; 809};
772 810
773ExcelCell* ExcelBook::CellNumber(int row, int col, int index, double d) 811ExcelCell* ExcelBook::CellNumber(int row, int col, int index, double d)
774{ 812{
775 ExcelCell* c; 813 ExcelCell* c;
776 c=new ExcelCell; 814 c=new ExcelCell;
777 c->row = row; 815 c->row = row;
778 c->col = col; 816 c->col = col;
779 c->xfindex = index; 817 c->xfindex = index;
780 c->type = CELL_NUMBER; 818 c->type = CELL_NUMBER;
781 c->valued = d; 819 c->valued = d;
782 return c; 820 return c;
783}; 821};
784 822
785QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col) 823QString* ExcelBook::CellDataString(ExcelSheet* sh, int row, int col)
786{ 824{
787 time_t date; 825 time_t date;
788 struct tm *tmptr; 826 struct tm *tmptr;
789 ExcelCell* c; 827 ExcelCell* c;
790 char str[128]; 828 char str[128];
791 QString format; 829 QString format;
792 int precision; 830 int precision;
793 int utcOffsetDays = 25569; 831 int utcOffsetDays = 25569;
794 int sInADay = 24 * 60 * 60; 832 int sInADay = 24 * 60 * 60;
795 c = sh->Get(row,col); 833 c = sh->Get(row,col);
796 if (c == NULL) return new QString(""); 834 if (c == NULL) return new QString("");
797 switch (c->type) 835 switch (c->type)
798 { 836 {
799 case CELL_LABEL: 837 case CELL_LABEL:
800 return new QString(c->valuec); 838 return new QString(c->valuec);
801 case CELL_NUMBER: 839 case CELL_NUMBER:
802 if (XFRecords[c->xfindex]->type == DATEFORMAT) 840 if (XFRecords[c->xfindex]->type == DATEFORMAT)
803 { 841 {
804 842
805 format = XFRecords[c->xfindex]->format; 843 format = XFRecords[c->xfindex]->format;
806 date = (time_t) ((c->valued - utcOffsetDays) * sInADay); 844 date = (time_t) ((c->valued - utcOffsetDays) * sInADay);
807 tmptr = gmtime(&date); 845 tmptr = gmtime(&date);
808 if (dateformat) 846 if (dateformat)
809 { 847 {
810 strftime(str,1024,dateformat.ascii(),tmptr); 848 strftime(str,1024,dateformat.ascii(),tmptr);
811 } else 849 }
812 { 850 else
813 strftime(str,1024,format.ascii(),tmptr); 851 {
814 }; 852 strftime(str,1024,format.ascii(),tmptr);
815 } else 853 };
816 if (XFRecords[c->xfindex]->type == NUMBERFORMAT) 854 }
817 { 855 else
818 format = XFRecords[c->xfindex]->format; 856 if (XFRecords[c->xfindex]->type == NUMBERFORMAT)
819 //sprintf(str,format.ascii(),c->valued); 857 {
820 // the real format is ignored... 858 format = XFRecords[c->xfindex]->format;
821 // because there is more work to be done in the field 859 //sprintf(str,format.ascii(),c->valued);
822 precision = CellGetPrecision(c->valued); 860 // the real format is ignored...
823 sprintf(str,"%.*f",precision,c->valued); 861 // because there is more work to be done in the field
824 }else 862 precision = CellGetPrecision(c->valued);
825 { 863 sprintf(str,"%.*f",precision,c->valued);
826 precision = CellGetPrecision(c->valued); 864 }
827 sprintf(str,"%.*f",precision,c->valued); 865 else
828 }; 866 {
829 break; 867 precision = CellGetPrecision(c->valued);
830 case CELL_DATE: 868 sprintf(str,"%.*f",precision,c->valued);
831 break; 869 };
832 case CELL_BOOLEAN: 870 break;
833 break; 871 case CELL_DATE:
834 case CELL_ERROR: 872 break;
835 break; 873 case CELL_BOOLEAN:
836 } 874 break;
837 return new QString(str); 875 case CELL_ERROR:
876 break;
877 }
878 return new QString(str);
838}; 879};
839 880
840int ExcelBook::CellGetPrecision(double d) 881int ExcelBook::CellGetPrecision(double d)
841{ 882{
842 double t; 883 double t;
843 int i,x; 884 int i,x;
844 int count; 885 int count;
845 if (d < 0) d *= -1; 886 if (d < 0) d *= -1;
846 i = (int)d; 887 i = (int)d;
847 t = d - (double)i; 888 t = d - (double)i;
848 if (t <= 0) 889 if (t <= 0)
849 { 890 {
850 return 0; 891 return 0;
851 }; 892 };
852 count = 0; 893 count = 0;
853 for (x = 6; x > 1; x--) 894 for (x = 6; x > 1; x--)
854 { 895 {
855 i = (int)d; 896 i = (int)d;
856 t = d - (double)i; 897 t = d - (double)i;
857 t *= pow(10,x - 2); 898 t *= pow(10,x - 2);
858 i = (int)t; 899 i = (int)t;
859 t = t - (double)i; 900 t = t - (double)i;
860 t *= 10; 901 t *= 10;
861 i = (int)t; 902 i = (int)t;
862 if (i > 0) break; 903 if (i > 0) break;
863 count++; 904 count++;
864 }; 905 };
865 return (5 - count); 906 return (5 - count);
866}; 907};
867 908
868 909
869void ExcelBook::CellSetDateFormat(char *d) 910void ExcelBook::CellSetDateFormat(char *d)
870{ 911{
871 dateformat = QString(d); 912 dateformat = QString(d);
872}; 913};
873 914
874void ExcelBook::HandleMulrk(ExcelSheet* sheet, ExcelBREC* record) 915void ExcelBook::HandleMulrk(ExcelSheet* sheet, ExcelBREC* record)
875{ 916{
876 struct mulrk mulrk; 917 struct mulrk mulrk;
877 char* data; 918 char* data;
878 ExcelCell* cell; 919 ExcelCell* cell;
879 int len; 920 int len;
880 int i; 921 int i;
881 len = record->length; 922 len = record->length;
882 data = GetDataOfBREC(record); 923 data = GetDataOfBREC(record);
883 mulrk.row = Integer2Byte(data[0],data[1]); 924 mulrk.row = Integer2Byte(data[0],data[1]);
884 mulrk.first = Integer2Byte(data[2],data[3]); 925 mulrk.first = Integer2Byte(data[2],data[3]);
885 mulrk.last = Integer2Byte(data[len - 2],data[len - 1]); 926 mulrk.last = Integer2Byte(data[len - 2],data[len - 1]);
886 mulrk.numrks = mulrk.last - mulrk.first + 1; 927 mulrk.numrks = mulrk.last - mulrk.first + 1;
887 MulrkRead(&mulrk, data); 928 MulrkRead(&mulrk, data);
888 for (i = 0; i < mulrk.numrks; i++) 929 for (i = 0; i < mulrk.numrks; i++)
889 { 930 {
890 cell = CellNumber(mulrk.row, mulrk.first + i, mulrk.xfindices[i], mulrk.rkdbls[i]); 931 cell = CellNumber(mulrk.row, mulrk.first + i, mulrk.xfindices[i], mulrk.rkdbls[i]);
891 sheet->Set(mulrk.row,mulrk.first+ i, cell); 932 sheet->Set(mulrk.row,mulrk.first+ i, cell);
892 //printf("handleMULRK:row=%d,col=%d,val=%f\r\n",mulrk.row,mulrk.first+i,mulrk.rkdbls[i]); 933 //printf("handleMULRK:row=%d,col=%d,val=%f\r\n",mulrk.row,mulrk.first+i,mulrk.rkdbls[i]);
893 } 934 }
894 //delete(mulrk.xfindices); 935 //delete(mulrk.xfindices);
895 //delete(mulrk.rkdbls); 936 //delete(mulrk.rkdbls);
896}; 937};
897 938
898void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data) 939void ExcelBook::MulrkRead(struct mulrk *mulrk, char* data)
899{ 940{
900 double d; 941 double d;
901 int i; 942 int i;
902 int pos; 943 int pos;
903 pos = 4; 944 pos = 4;
904 mulrk->xfindices.resize(mulrk->numrks); 945 mulrk->xfindices.resize(mulrk->numrks);
905 mulrk->rkdbls.resize(mulrk->numrks); 946 mulrk->rkdbls.resize(mulrk->numrks);
906 for (i = 0; i < mulrk->numrks; i++) 947 for (i = 0; i < mulrk->numrks; i++)
907 { 948 {
908 mulrk->xfindices[i] = Integer2Byte(data[pos], data[pos+1]); 949 mulrk->xfindices[i] = Integer2Byte(data[pos], data[pos+1]);
909 d=Double4Byte(data[pos+2], data[pos+3], data[pos+4], data[pos+5]); 950 d=Double4Byte(data[pos+2], data[pos+3], data[pos+4], data[pos+5]);
910 //printf("double:%f\r\n",d); 951 //printf("double:%f\r\n",d);
911 mulrk->rkdbls[i] = d; 952 mulrk->rkdbls[i] = d;
912 pos += 6; 953 pos += 6;
913 } 954 }
914}; 955};
915 956
916 957
917void ExcelBook::HandleNumber(ExcelSheet* sheet, ExcelBREC* record) 958void ExcelBook::HandleNumber(ExcelSheet* sheet, ExcelBREC* record)
918{ 959{
919 int xfindex, row, col; 960 int xfindex, row, col;
920 char* data; 961 char* data;
921 double d; 962 double d;
922 data = GetDataOfBREC(record); 963 data = GetDataOfBREC(record);
923 row = Integer2Byte(data[0], data[1]); 964 row = Integer2Byte(data[0], data[1]);
924 col = Integer2Byte(data[2], data[3]); 965 col = Integer2Byte(data[2], data[3]);
925 xfindex = Integer2Byte(data[4], data[5]); 966 xfindex = Integer2Byte(data[4], data[5]);
926 #if defined(__arm__) && !defined(__vfp__) 967#if defined(__arm__) && !defined(__vfp__)
927 d=Double8Byte(data[10], data[11], data[12], data[13],data[6], data[7], data[8], data[9]); 968 d=Double8Byte(data[10], data[11], data[12], data[13],data[6], data[7], data[8], data[9]);
928 #else 969#else
929 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); 970 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]);
930 #endif 971#endif
931 //even if ARM is little endian... doubles are been placed as bigendian words. 972 //even if ARM is little endian... doubles are been placed as bigendian words.
932 //thanks pb_ for that. :) 973 //thanks pb_ for that. :)
933 sheet->Set(row,col, CellNumber(row,col,xfindex,d)); 974 sheet->Set(row,col, CellNumber(row,col,xfindex,d));
934 //printf("handleNumber:row=%d,col=%d,val=%f\r\n",row,col,d); 975 //printf("handleNumber:row=%d,col=%d,val=%f\r\n",row,col,d);
935}; 976};
936 977
937ExcelFormat::ExcelFormat() 978ExcelFormat::ExcelFormat()
938{ 979{
939code=0;type=0;format=""; 980 code=0;type=0;format="";
940}; 981};
941 982
942ExcelFormat::ExcelFormat(int c,int t, QString s) 983ExcelFormat::ExcelFormat(int c,int t, QString s)
943{ 984{
944 code=c;type=t;format=s; 985 code=c;type=t;format=s;
945}; 986};
946 987
947 988
948void ExcelBook::HandleFormat(ExcelBREC* rec) 989void ExcelBook::HandleFormat(ExcelBREC* rec)
949{ 990{
950 ExcelFormat* xfrec; 991 ExcelFormat* xfrec;
951 char* data; 992 char* data;
952 int format; 993 int format;
953 data = GetDataOfBREC(rec); 994 data = GetDataOfBREC(rec);
954 format = Integer2Byte(data[2],data[3]); 995 format = Integer2Byte(data[2],data[3]);
955 xfrec = GetFormatting(format); 996 xfrec = GetFormatting(format);
956 /*int idx; 997 /*int idx;
957 idx=XFRecords.count()-1; 998 idx=XFRecords.count()-1;
958 XFRecords[idx]->code=xfrec->code; 999 XFRecords[idx]->code=xfrec->code;
959 XFRecords[idx]->type=xfrec->type; 1000 XFRecords[idx]->type=xfrec->type;
960 XFRecords[idx]->format="manos"; 1001 XFRecords[idx]->format="manos";
961 //XFRecords[XFRecords.count()-1]=xfrec; 1002 //XFRecords[XFRecords.count()-1]=xfrec;
962 printf("6\r\n");*/ 1003 printf("6\r\n");*/
963}; 1004};
964 1005
965void ExcelBook::HandleXF(ExcelBREC* rec) 1006void ExcelBook::HandleXF(ExcelBREC* rec)
966{ 1007{
967 ExcelFormat* xfrec; 1008 ExcelFormat* xfrec;
968 char* data; 1009 char* data;
969 int format; 1010 int format;
970 data = GetDataOfBREC(rec); 1011 data = GetDataOfBREC(rec);
971 format = Integer2Byte(data[2],data[3]); 1012 format = Integer2Byte(data[2],data[3]);
972 xfrec = GetFormatting(format); 1013 xfrec = GetFormatting(format);
973 XFRecords.resize(XFRecords.count()+1); 1014 XFRecords.resize(XFRecords.count()+1);
974 XFRecords[XFRecords.count()-1]=xfrec; 1015 XFRecords[XFRecords.count()-1]=xfrec;
975}; 1016};
976 1017
977 1018
978 1019
979void ExcelBook::HandleRK(ExcelSheet* sheet, ExcelBREC* record) 1020void ExcelBook::HandleRK(ExcelSheet* sheet, ExcelBREC* record)
980{ 1021{
981 int xfindex, row, col; 1022 int xfindex, row, col;
982 char* data; 1023 char* data;
983 double d; 1024 double d;
984 data = GetDataOfBREC(record); 1025 data = GetDataOfBREC(record);
985 row = Integer2Byte(data[0], data[1]); 1026 row = Integer2Byte(data[0], data[1]);
986 col = Integer2Byte(data[2], data[3]); 1027 col = Integer2Byte(data[2], data[3]);
987 xfindex = Integer2Byte(data[4], data[5]); 1028 xfindex = Integer2Byte(data[4], data[5]);
988 d=Double4Byte(data[6], data[7], data[8], data[9]); 1029 d=Double4Byte(data[6], data[7], data[8], data[9]);
989 sheet->Set(row,col,CellNumber(row,col,xfindex,d)); 1030 sheet->Set(row,col,CellNumber(row,col,xfindex,d));
990 //printf("handleRK:row=%d,col=%d,val=%f\r\n",row,col,d); 1031 //printf("handleRK:row=%d,col=%d,val=%f\r\n",row,col,d);
991}; 1032};
992 1033
993 1034
994void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record) 1035void ExcelBook::HandleFormula(ExcelSheet* sheet, ExcelBREC* record)
995{ 1036{
996 int xfindex, row, col; 1037 int xfindex, row, col;
997 char* data; 1038 char* data;
998 double d; 1039 double d;
999 data = GetDataOfBREC(record); 1040 data = GetDataOfBREC(record);
1000 row = Integer2Byte(data[0], data[1]); 1041 row = Integer2Byte(data[0], data[1]);
1001 col = Integer2Byte(data[2], data[3]); 1042 col = Integer2Byte(data[2], data[3]);
1002 if (data[6] == 0 && data[12] == -1 && data[13] == -1) 1043 if (data[6] == 0 && data[12] == -1 && data[13] == -1)
1003 { 1044 {
1004 // string 1045 // string
1005 } else 1046 }
1006 if (data[6] == 1 && data[12] == -1 && data[13] == -1) 1047 else
1007 { 1048 if (data[6] == 1 && data[12] == -1 && data[13] == -1)
1008 // boolean 1049 {
1009 } else 1050 // boolean
1010 if ( data[6] == 2 && data[12] == -1 && data[13] == -1) 1051 }
1011 { 1052 else
1012 // error 1053 if ( data[6] == 2 && data[12] == -1 && data[13] == -1)
1013 } 1054 {
1014 else 1055 // error
1015 { 1056 }
1016 // number 1057 else
1017 xfindex = Integer2Byte(data[4], data[5]); 1058 {
1018 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]); 1059 // number
1019 QString s1; 1060 xfindex = Integer2Byte(data[4], data[5]);
1020 int sz; 1061 d=Double8Byte(data[6], data[7], data[8], data[9],data[10], data[11], data[12], data[13]);
1021 sz=Integer2Byte(data[20],data[21]);// size of the formula 1062 QString s1;
1022 char* formuladata; 1063 int sz;
1023 formuladata=new char[sz]; 1064 sz=Integer2Byte(data[20],data[21]);// size of the formula
1024 for(int w1=0;w1<sz;w1++) 1065 char* formuladata;
1025 { 1066 formuladata=new char[sz];
1026 formuladata[w1]=data[22+w1]; 1067 for(int w1=0;w1<sz;w1++)
1027 }; 1068 {
1028 //22 is the first 0 idx of formula data 1069 formuladata[w1]=data[22+w1];
1029 s1="="+GetFormula(row,col,sheet,formuladata,sz); 1070 };
1030 //printf("GetFormula:Formula=%s\r\n",s1.ascii()); 1071 //22 is the first 0 idx of formula data
1031 sheet->Set(row,col,CellLabel(row,col,s1)); 1072 s1="="+GetFormula(row,col,sheet,formuladata,sz);
1032 } 1073 //printf("GetFormula:Formula=%s\r\n",s1.ascii());
1074 sheet->Set(row,col,CellLabel(row,col,s1));
1075 }
1033}; 1076};
1034 1077
1035 1078
1036QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz) 1079QString ExcelBook::GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz)
1037{ 1080{
1038 int length=sz; 1081 int length=sz;
1039 printf("{FormulaParser}\r\n"); 1082 printf("{FormulaParser}\r\n");
1040 printf("row=%d, col=%d, length=%d\r\n",row,col,length); 1083 printf("row=%d, col=%d, length=%d\r\n",row,col,length);
1041 int idx=0; 1084 int idx=0;
1042 int w1,w2,w3,w4; 1085 int w1,w2,w3,w4;
1043 double d1; 1086 double d1;
1044 int token; 1087 int token;
1045 QString s1; 1088 QString s1;
1046 QList <QString> operands; 1089 QList <QString> operands;
1047 operands.setAutoDelete(TRUE); 1090 operands.setAutoDelete(TRUE);
1048 QString formula; 1091 QString formula;
1049 operands.clear(); 1092 operands.clear();
1050 while( idx<length ) 1093 while( idx<length )
1051 { 1094 {
1052 token= data[idx]; idx++; 1095 token= data[idx]; idx++;
1053 switch(token) 1096 switch(token)
1054 { 1097 {
1055 case 0x1E: //prtInt 1098 case 0x1E: //prtInt
1056 w1=Integer2Byte(data[idx],data[idx+1]); 1099 w1=Integer2Byte(data[idx],data[idx+1]);
1057 idx=idx+2; 1100 idx=idx+2;
1058 operands.prepend(new QString(QString::number(w1))); 1101 operands.prepend(new QString(QString::number(w1)));
1059 printf(" token:ptgInt,num=%d\r\n",w1); 1102 printf(" token:ptgInt,num=%d\r\n",w1);
1060 break; 1103 break;
1061 case 0x1F: //ptgNumber 1104 case 0x1F: //ptgNumber
1062 #if defined(__arm__) && !defined(__vfp__) 1105#if defined(__arm__) && !defined(__vfp__)
1063 d1=Double8Byte(data[idx+4],data[idx+5],data[idx+6],data[idx+7] 1106 d1=Double8Byte(data[idx+4],data[idx+5],data[idx+6],data[idx+7]
1064 ,data[idx],data[idx+1],data[idx+2],data[idx+3]); 1107 ,data[idx],data[idx+1],data[idx+2],data[idx+3]);
1065 #else 1108#else
1066 d1=Double8Byte(data[idx],data[idx+1],data[idx+2],data[idx+3] 1109 d1=Double8Byte(data[idx],data[idx+1],data[idx+2],data[idx+3]
1067 ,data[idx+4],data[idx+5],data[idx+6],data[idx+7]); 1110 ,data[idx+4],data[idx+5],data[idx+6],data[idx+7]);
1068 #endif 1111#endif
1069 idx=idx+8; 1112 idx=idx+8;
1070 operands.prepend(new QString(QString::number(d1))); 1113 operands.prepend(new QString(QString::number(d1)));
1071 printf(" token:ptgNumber,num=%f\r\n",d1); 1114 printf(" token:ptgNumber,num=%f\r\n",d1);
1072 break; 1115 break;
1073 case 0x17: //ptgStr 1116 case 0x17: //ptgStr
1074 if(Version==8) 1117 if(Version==8)
1075 { 1118 {
1076 //unicode string 1119 //unicode string
1077 //w1=Integer2Byte(data[idx],data[idx+1]);idx+=2; 1120 //w1=Integer2Byte(data[idx],data[idx+1]);idx+=2;
1078 w1=data[idx];idx++; 1121 w1=data[idx];idx++;
1079 printf("len=%d\r\n",w1); 1122 printf("len=%d\r\n",w1);
1080 int richruns=0; int fareastsize=0; 1123 int richruns=0; int fareastsize=0;
1081 int richstring,fareaststring; 1124 int richstring,fareaststring;
1082 int options = data[idx];idx++; 1125 int options = data[idx];idx++;
1083 fareaststring = ((options & 0x04) != 0); 1126 fareaststring = ((options & 0x04) != 0);
1084 richstring = ((options & 0x08) != 0); 1127 richstring = ((options & 0x08) != 0);
1085 if(richstring) 1128 if(richstring)
1086 { 1129 {
1087 //containts rich string formatting. 1130 //containts rich string formatting.
1088 printf("STRING:richstring\r\n"); 1131 printf("STRING:richstring\r\n");
1089 richruns= Integer2Byte(data[idx],data[idx+1]); 1132 richruns= Integer2Byte(data[idx],data[idx+1]);
1090 printf("richruns:%d\r\n",richruns); 1133 printf("richruns:%d\r\n",richruns);
1091 idx+=2; 1134 idx+=2;
1092 }; 1135 };
1093 if(fareaststring) 1136 if(fareaststring)
1094 { 1137 {
1095 //contains far east formatting 1138 //contains far east formatting
1096 printf("STRING:fareast!\r\n"); 1139 printf("STRING:fareast!\r\n");
1097 fareastsize=Integer4Byte(data[idx], data[idx+1], 1140 fareastsize=Integer4Byte(data[idx], data[idx+1],
1098 data[idx+2], data[idx+3]); 1141 data[idx+2], data[idx+3]);
1099 printf("fareastsize=%d",fareastsize); 1142 printf("fareastsize=%d",fareastsize);
1100 idx+=4; 1143 idx+=4;
1101 }; 1144 };
1102 if ((options & 0x01) == 0) //8 bit chars 1145 if ((options & 0x01) == 0) //8 bit chars
1103 { 1146 {
1104 /* ascii */ 1147 /* ascii */
1105 s1 = GetASCII(data,idx,w1); 1148 s1 = GetASCII(data,idx,w1);
1106 idx=idx+w1; 1149 idx=idx+w1;
1107 printf("STRING:ASCII=%s\r\n",s1.ascii()); 1150 printf("STRING:ASCII=%s\r\n",s1.ascii());
1108 }else //16 bit chars 1151 }else //16 bit chars
1109 { 1152 {
1110 /* unicode */ 1153 /* unicode */
1111 s1 = GetUnicode(data,idx,w1); 1154 s1 = GetUnicode(data,idx,w1);
1112 idx=idx+w1*2; 1155 idx=idx+w1*2;
1113 printf("STRING:unicode=%s\r\n",s1.ascii()); 1156 printf("STRING:unicode=%s\r\n",s1.ascii());
1114 }; 1157 };
1115 // HERE TO PUT richformat handling 1158 // HERE TO PUT richformat handling
1116 if (richstring) 1159 if (richstring)
1117 { 1160 {
1118 idx += 4 * richruns; 1161 idx += 4 * richruns;
1119 }; 1162 };
1120 if (fareaststring) 1163 if (fareaststring)
1121 { 1164 {
1122 idx += fareastsize; 1165 idx += fareastsize;
1123 }; 1166 };
1124 s1=QString("""")+s1+QString(""""); 1167 s1=QString("""")+s1+QString("""");
1125 operands.prepend(new QString(s1)); 1168 operands.prepend(new QString(s1));
1126 }else 1169 }
1127 { 1170 else
1128 w1=data[idx];idx++; 1171 {
1129 s1=GetASCII(data,idx,w1); 1172 w1=data[idx];idx++;
1130 s1=QString("""")+s1+QString(""""); 1173 s1=GetASCII(data,idx,w1);
1131 idx=idx+w1; 1174 s1=QString("""")+s1+QString("""");
1132 operands.prepend(new QString(s1)); 1175 idx=idx+w1;
1133 }; 1176 operands.prepend(new QString(s1));
1134 printf(" token:ptgStr,num=%d\r\n",w1); 1177 };
1135 break; 1178 printf(" token:ptgStr,num=%d\r\n",w1);
1136 case 0x25: 1179 break;
1137 case 0x45: 1180 case 0x25:
1138 case 0x65: // ptgArea 1181 case 0x45:
1139 if(Version==8) 1182 case 0x65: // ptgArea
1140 { 1183 if(Version==8)
1141 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row1 1184 {
1142 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2 1185 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row1
1143 w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1 1186 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row2
1144 w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2 1187 w3=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col1
1145 }else 1188 w4=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col2
1146 { 1189 }
1147 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1 1190 else
1148 w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2 1191 {
1149 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col1 1192 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row1
1150 w4=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col2 1193 w2=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row2
1151 }; 1194 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col1
1152 //ignores relative or absolute refs 1195 w4=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col2
1153 s1=FindCellName(w1,w3)+":"+FindCellName(w2,w4); 1196 };
1154 printf(" token:ptgArea,ref=%s\r\n",s1.ascii()); 1197 //ignores relative or absolute refs
1155 operands.prepend(new QString(s1)); 1198 s1=FindCellName(w1,w3)+":"+FindCellName(w2,w4);
1156 break; 1199 printf(" token:ptgArea,ref=%s\r\n",s1.ascii());
1157 case 0x24: 1200 operands.prepend(new QString(s1));
1158 case 0x44: 1201 break;
1159 case 0x64://ptgRef 1202 case 0x24:
1160 if(Version==8) 1203 case 0x44:
1161 { 1204 case 0x64://ptgRef
1162 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row 1205 if(Version==8)
1163 w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col 1206 {
1164 }else 1207 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//row
1165 { 1208 w2=Integer2Byte(data[idx],data[idx+1]) & 0x00FF;idx=idx+2;//col
1166 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row 1209 }
1167 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col 1210 else
1168 }; 1211 {
1169 s1=FindCellName(w1,w2); 1212 w1=Integer2Byte(data[idx],data[idx+1]) & 0x3FFF;idx=idx+2;//row
1170 printf("token:ptgRef,ref=%s\r\n",s1.ascii()); 1213 w2=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;//col
1171 operands.prepend(new QString(s1)); 1214 };
1172 break; 1215 s1=FindCellName(w1,w2);
1173 case 0x1D: // ptgBool 1216 printf("token:ptgRef,ref=%s\r\n",s1.ascii());
1174 w1=data[idx];idx++; 1217 operands.prepend(new QString(s1));
1175 printf("token:ptgBool,val=%d\r\n",w1); 1218 break;
1176 operands.prepend(new QString(QString::number(w1))); 1219 case 0x1D: // ptgBool
1177 break; 1220 w1=data[idx];idx++;
1178 case 0x16://ptg MissArg 1221 printf("token:ptgBool,val=%d\r\n",w1);
1179 printf("token:ptgMissArg, val=' '\r\n"); 1222 operands.prepend(new QString(QString::number(w1)));
1180 operands.prepend(new QString("0")); 1223 break;
1181 break; 1224 case 0x16://ptg MissArg
1182 case 0x12://ptgUplus== 1225 printf("token:ptgMissArg, val=' '\r\n");
1183 printf("token:ptgUplus\r\n"); 1226 operands.prepend(new QString("0"));
1184 s1=QString("+")+operands.first()->ascii(); 1227 break;
1185 operands.removeFirst(); 1228 case 0x12://ptgUplus==
1186 operands.prepend(new QString(s1)); 1229 printf("token:ptgUplus\r\n");
1187 break; 1230 s1=QString("+")+operands.first()->ascii();
1188 case 0x13://ptgUminus 1231 operands.removeFirst();
1189 printf("token:ptgUminus\r\n"); 1232 operands.prepend(new QString(s1));
1190 s1=QString("-")+operands.first()->ascii(); 1233 break;
1191 operands.removeFirst(); 1234 case 0x13://ptgUminus
1192 operands.prepend(new QString(s1)); 1235 printf("token:ptgUminus\r\n");
1193 break; 1236 s1=QString("-")+operands.first()->ascii();
1194 case 0x03://ptgAdd 1237 operands.removeFirst();
1195 printf("token:ptgAdd\r\n"); 1238 operands.prepend(new QString(s1));
1196 operands.first(); 1239 break;
1197 s1=operands.next()->ascii() 1240 case 0x03://ptgAdd
1198 +QString("+")+operands.first()->ascii(); 1241 printf("token:ptgAdd\r\n");
1199 operands.removeFirst();operands.removeFirst(); 1242 operands.first();
1200 operands.prepend(new QString(s1)); 1243 s1=operands.next()->ascii()
1201 break; 1244 +QString("+")+operands.first()->ascii();
1202 case 0x04://ptgSub 1245 operands.removeFirst();operands.removeFirst();
1203 printf("token:ptgSub\r\n"); 1246 operands.prepend(new QString(s1));
1204 operands.first(); 1247 break;
1205 s1=operands.next()->ascii() 1248 case 0x04://ptgSub
1206 +QString("-")+operands.first()->ascii(); 1249 printf("token:ptgSub\r\n");
1207 operands.removeFirst();operands.removeFirst(); 1250 operands.first();
1208 operands.prepend(new QString(s1)); 1251 s1=operands.next()->ascii()
1209 break; 1252 +QString("-")+operands.first()->ascii();
1210 case 0x05://ptgMul 1253 operands.removeFirst();operands.removeFirst();
1211 printf("token:ptgMul\r\n"); 1254 operands.prepend(new QString(s1));
1212 operands.first(); 1255 break;
1213 s1=operands.next()->ascii() 1256 case 0x05://ptgMul
1214 +QString("*")+operands.first()->ascii(); 1257 printf("token:ptgMul\r\n");
1215 operands.removeFirst();operands.removeFirst(); 1258 operands.first();
1216 operands.prepend(new QString(s1)); 1259 s1=operands.next()->ascii()
1217 break; 1260 +QString("*")+operands.first()->ascii();
1218 case 0x06://ptgDiv 1261 operands.removeFirst();operands.removeFirst();
1219 printf("token:ptgDiv\r\n"); 1262 operands.prepend(new QString(s1));
1220 operands.first(); 1263 break;
1221 s1=operands.next()->ascii() 1264 case 0x06://ptgDiv
1222 +QString("/")+operands.first()->ascii(); 1265 printf("token:ptgDiv\r\n");
1223 operands.removeFirst();operands.removeFirst(); 1266 operands.first();
1224 operands.prepend(new QString(s1)); 1267 s1=operands.next()->ascii()
1225 break; 1268 +QString("/")+operands.first()->ascii();
1226 case 0x07://ptgPOWER 1269 operands.removeFirst();operands.removeFirst();
1227 printf("token:ptgPow\r\n"); 1270 operands.prepend(new QString(s1));
1228 operands.first(); 1271 break;
1229 s1=QString("POWER(")+operands.next()->ascii() 1272 case 0x07://ptgPOWER
1230 +QString(",")+operands.first()->ascii()+QString(")"); 1273 printf("token:ptgPow\r\n");
1231 operands.removeFirst();operands.removeFirst(); 1274 operands.first();
1232 operands.prepend(new QString(s1)); 1275 s1=QString("POWER(")+operands.next()->ascii()
1233 break; 1276 +QString(",")+operands.first()->ascii()+QString(")");
1234 case 0x08://ptgConcat 1277 operands.removeFirst();operands.removeFirst();
1235 printf("token:ptgConcat\r\n"); 1278 operands.prepend(new QString(s1));
1236 operands.first(); 1279 break;
1237 s1=QString("CONCATENATE(")+operands.next()->ascii() 1280 case 0x08://ptgConcat
1238 +QString(",")+operands.first()->ascii()+QString(")"); 1281 printf("token:ptgConcat\r\n");
1239 operands.removeFirst();operands.removeFirst(); 1282 operands.first();
1240 operands.prepend(new QString(s1)); 1283 s1=QString("CONCATENATE(")+operands.next()->ascii()
1241 break; 1284 +QString(",")+operands.first()->ascii()+QString(")");
1242 case 0x15://ptgParenthesis 1285 operands.removeFirst();operands.removeFirst();
1243 printf("token:ptgParenthesis\r\n"); 1286 operands.prepend(new QString(s1));
1244 s1=QString("(")+operands.first()->ascii()+QString(")"); 1287 break;
1245 operands.removeFirst(); 1288 case 0x15://ptgParenthesis
1246 operands.prepend(new QString(s1)); 1289 printf("token:ptgParenthesis\r\n");
1247 break; 1290 s1=QString("(")+operands.first()->ascii()+QString(")");
1248 case 0x14://ptgPercent 1291 operands.removeFirst();
1249 printf("token:ptgPercent\r\n"); 1292 operands.prepend(new QString(s1));
1250 s1=operands.first()->ascii()+QString("*0.01"); 1293 break;
1251 operands.removeFirst(); 1294 case 0x14://ptgPercent
1252 operands.prepend(new QString(s1)); 1295 printf("token:ptgPercent\r\n");
1253 break; 1296 s1=operands.first()->ascii()+QString("*0.01");
1254 case 0x9://ptgLessThan 1297 operands.removeFirst();
1255 printf("token:ptgLESS\r\n"); 1298 operands.prepend(new QString(s1));
1256 operands.first(); 1299 break;
1257 s1=operands.next()->ascii() 1300 case 0x9://ptgLessThan
1258 +QString("<")+operands.first()->ascii(); 1301 printf("token:ptgLESS\r\n");
1259 operands.removeFirst();operands.removeFirst(); 1302 operands.first();
1260 operands.prepend(new QString(s1)); 1303 s1=operands.next()->ascii()
1261 break; 1304 +QString("<")+operands.first()->ascii();
1262 case 0xa://ptgLessEqual 1305 operands.removeFirst();operands.removeFirst();
1263 printf("token:ptgLESS_EQUAL\r\n"); 1306 operands.prepend(new QString(s1));
1264 operands.first(); 1307 break;
1265 s1=operands.next()->ascii() 1308 case 0xa://ptgLessEqual
1266 +QString("<=")+operands.first()->ascii(); 1309 printf("token:ptgLESS_EQUAL\r\n");
1267 operands.removeFirst();operands.removeFirst(); 1310 operands.first();
1268 operands.prepend(new QString(s1)); 1311 s1=operands.next()->ascii()
1269 break; 1312 +QString("<=")+operands.first()->ascii();
1270 case 0xb://ptgEQUAL 1313 operands.removeFirst();operands.removeFirst();
1271 printf("token:ptgEQUAL\r\n"); 1314 operands.prepend(new QString(s1));
1272 operands.first(); 1315 break;
1273 s1=operands.next()->ascii() 1316 case 0xb://ptgEQUAL
1274 +QString("==")+operands.first()->ascii(); 1317 printf("token:ptgEQUAL\r\n");
1275 operands.removeFirst();operands.removeFirst(); 1318 operands.first();
1276 operands.prepend(new QString(s1)); 1319 s1=operands.next()->ascii()
1277 break; 1320 +QString("==")+operands.first()->ascii();
1278 case 0xc://ptgGREATER_EQUAL 1321 operands.removeFirst();operands.removeFirst();
1279 printf("token:ptgGREAT_EQUAL\r\n"); 1322 operands.prepend(new QString(s1));
1280 operands.first(); 1323 break;
1281 s1=operands.next()->ascii() 1324 case 0xc://ptgGREATER_EQUAL
1282 +QString(">=")+operands.first()->ascii(); 1325 printf("token:ptgGREAT_EQUAL\r\n");
1283 operands.removeFirst();operands.removeFirst(); 1326 operands.first();
1284 operands.prepend(new QString(s1)); 1327 s1=operands.next()->ascii()
1285 break; 1328 +QString(">=")+operands.first()->ascii();
1286 case 0xd://ptgGREAT_THAN 1329 operands.removeFirst();operands.removeFirst();
1287 printf("token:ptgGREAT_THAN\r\n"); 1330 operands.prepend(new QString(s1));
1288 operands.first(); 1331 break;
1289 s1=operands.next()->ascii() 1332 case 0xd://ptgGREAT_THAN
1290 +QString(">")+operands.first()->ascii(); 1333 printf("token:ptgGREAT_THAN\r\n");
1291 operands.removeFirst();operands.removeFirst(); 1334 operands.first();
1292 operands.prepend(new QString(s1)); 1335 s1=operands.next()->ascii()
1293 break; 1336 +QString(">")+operands.first()->ascii();
1294 case 0xe://ptgNOT_EQUAL 1337 operands.removeFirst();operands.removeFirst();
1295 printf("token:ptgNOTequal\r\n"); 1338 operands.prepend(new QString(s1));
1296 operands.first(); 1339 break;
1297 s1=operands.next()->ascii() 1340 case 0xe://ptgNOT_EQUAL
1298 +QString("!=")+operands.first()->ascii(); 1341 printf("token:ptgNOTequal\r\n");
1299 operands.removeFirst();operands.removeFirst(); 1342 operands.first();
1300 operands.prepend(new QString(s1)); 1343 s1=operands.next()->ascii()
1301 break; 1344 +QString("!=")+operands.first()->ascii();
1302 case 0x19://attribute can be Sum,If,Choose 1345 operands.removeFirst();operands.removeFirst();
1303 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; 1346 operands.prepend(new QString(s1));
1304 idx++; 1347 break;
1305 printf("token:ATTRIBUTE:0x%x\r\n",w3); 1348 case 0x19://attribute can be Sum,If,Choose
1306 for(w4=idx;w4<length;w4++) 1349 w3=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;
1307 printf("0x%x, ",data[w4]); 1350 idx++;
1308 if(w3&0x01)//choose 1351 printf("token:ATTRIBUTE:0x%x\r\n",w3);
1309 { 1352 for(w4=idx;w4<length;w4++)
1310 printf("token:CHOOSE\r\n"); 1353 printf("0x%x, ",data[w4]);
1311 } 1354 if(w3&0x01)//choose
1312 else if(w3&0x02)//if 1355 {
1313 { 1356 printf("token:CHOOSE\r\n");
1314 printf("token:IF\r\n"); 1357 }
1315 } 1358 else if(w3&0x02)//if
1316 else if(w3&0x10)//sum 1359 {
1317 { 1360 printf("token:IF\r\n");
1318 printf("token:SUM\r\n"); 1361 }
1319 }; 1362 else if(w3&0x10)//sum
1320 1363 {
1321 break; 1364 printf("token:SUM\r\n");
1322 1365 };
1323 1366
1324 case 0x21: 1367 break;
1325 case 0x22: 1368
1326 case 0x42: 1369
1327 case 0x62: 1370 case 0x21:
1328 case 0x41: 1371 case 0x22:
1329 case 0x61://ptgFunction 1372 case 0x42:
1330 printf("token:ptgFunction\r\n"); 1373 case 0x62:
1331 if(token==0x22||token==0x42||token==0x62) 1374 case 0x41:
1332 { 1375 case 0x61://ptgFunction
1333 w2=(int)data[idx];idx++; 1376 printf("token:ptgFunction\r\n");
1334 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; 1377 if(token==0x22||token==0x42||token==0x62)
1335 }else 1378 {
1336 { 1379 w2=(int)data[idx];idx++;
1337 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2; 1380 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;
1338 }; 1381 }
1339 switch(w1) 1382 else
1340 { 1383 {
1341 case 0xf://SIN 1384 w1=Integer2Byte(data[idx],data[idx+1]);idx=idx+2;
1342 s1=QString("SIN(")+operands.first()->ascii()+QString(")"); 1385 };
1343 operands.removeFirst(); 1386 switch(w1)
1344 operands.prepend(new QString(s1)); 1387 {
1345 break; 1388 case 0xf://SIN
1346 case 0x10://COS 1389 s1=QString("SIN(")+operands.first()->ascii()+QString(")");
1347 s1=QString("COS(")+operands.first()->ascii()+QString(")"); 1390 operands.removeFirst();
1348 operands.removeFirst(); 1391 operands.prepend(new QString(s1));
1349 operands.prepend(new QString(s1)); 1392 break;
1350 break; 1393 case 0x10://COS
1351 case 0x11://tan 1394 s1=QString("COS(")+operands.first()->ascii()+QString(")");
1352 s1=QString("TAN(")+operands.first()->ascii()+QString(")"); 1395 operands.removeFirst();
1353 operands.removeFirst(); 1396 operands.prepend(new QString(s1));
1354 operands.prepend(new QString(s1)); 1397 break;
1355 break; 1398 case 0x11://tan
1356 case 0x62://asin 1399 s1=QString("TAN(")+operands.first()->ascii()+QString(")");
1357 s1=QString("ASIN(")+operands.first()->ascii()+QString(")"); 1400 operands.removeFirst();
1358 operands.removeFirst(); 1401 operands.prepend(new QString(s1));
1359 operands.prepend(new QString(s1)); 1402 break;
1360 break; 1403 case 0x62://asin
1361 case 0x63://ACOS 1404 s1=QString("ASIN(")+operands.first()->ascii()+QString(")");
1362 s1=QString("ACOS(")+operands.first()->ascii()+QString(")"); 1405 operands.removeFirst();
1363 operands.removeFirst(); 1406 operands.prepend(new QString(s1));
1364 operands.prepend(new QString(s1)); 1407 break;
1365 break; 1408 case 0x63://ACOS
1366 case 0x12://ATAN 1409 s1=QString("ACOS(")+operands.first()->ascii()+QString(")");
1367 s1=QString("ATAN(")+operands.first()->ascii()+QString(")"); 1410 operands.removeFirst();
1368 operands.removeFirst(); 1411 operands.prepend(new QString(s1));
1369 operands.prepend(new QString(s1)); 1412 break;
1370 break; 1413 case 0x12://ATAN
1371 case 0xe5://SINH 1414 s1=QString("ATAN(")+operands.first()->ascii()+QString(")");
1372 s1=QString("SINH(")+operands.first()->ascii()+QString(")"); 1415 operands.removeFirst();
1373 operands.removeFirst(); 1416 operands.prepend(new QString(s1));
1374 operands.prepend(new QString(s1)); 1417 break;
1375 break; 1418 case 0xe5://SINH
1376 case 0xe6://COSH 1419 s1=QString("SINH(")+operands.first()->ascii()+QString(")");
1377 s1=QString("COSH(")+operands.first()->ascii()+QString(")"); 1420 operands.removeFirst();
1378 operands.removeFirst(); 1421 operands.prepend(new QString(s1));
1379 operands.prepend(new QString(s1)); 1422 break;
1380 break; 1423 case 0xe6://COSH
1381 case 0xe7://TANH 1424 s1=QString("COSH(")+operands.first()->ascii()+QString(")");
1382 s1=QString("TANH(")+operands.first()->ascii()+QString(")"); 1425 operands.removeFirst();
1383 operands.removeFirst(); 1426 operands.prepend(new QString(s1));
1384 operands.prepend(new QString(s1)); 1427 break;
1385 break; 1428 case 0xe7://TANH
1386 case 0xe8://ASINH 1429 s1=QString("TANH(")+operands.first()->ascii()+QString(")");
1387 s1=QString("ASINH(")+operands.first()->ascii()+QString(")"); 1430 operands.removeFirst();
1388 operands.removeFirst(); 1431 operands.prepend(new QString(s1));
1389 operands.prepend(new QString(s1)); 1432 break;
1390 break; 1433 case 0xe8://ASINH
1391 case 0xe9://ACOSH 1434 s1=QString("ASINH(")+operands.first()->ascii()+QString(")");
1392 s1=QString("ACOSH(")+operands.first()->ascii()+QString(")"); 1435 operands.removeFirst();
1393 operands.removeFirst(); 1436 operands.prepend(new QString(s1));
1394 operands.prepend(new QString(s1)); 1437 break;
1395 break; 1438 case 0xe9://ACOSH
1396 case 0xea://ATANH 1439 s1=QString("ACOSH(")+operands.first()->ascii()+QString(")");
1397 s1=QString("ATANH(")+operands.first()->ascii()+QString(")"); 1440 operands.removeFirst();
1398 operands.removeFirst(); 1441 operands.prepend(new QString(s1));
1399 operands.prepend(new QString(s1)); 1442 break;
1400 break; 1443 case 0xea://ATANH
1401 case 0x13://pi 1444 s1=QString("ATANH(")+operands.first()->ascii()+QString(")");
1402 s1="PI()"; 1445 operands.removeFirst();
1403 operands.prepend(new QString(s1)); 1446 operands.prepend(new QString(s1));
1404 break; 1447 break;
1405 case 0x14://sqrt 1448 case 0x13://pi
1406 s1=QString("SQRT(")+operands.first()->ascii()+QString(")"); 1449 s1="PI()";
1407 operands.removeFirst(); 1450 operands.prepend(new QString(s1));
1408 operands.prepend(new QString(s1)); 1451 break;
1409 break; 1452 case 0x14://sqrt
1410 case 0x15://exp 1453 s1=QString("SQRT(")+operands.first()->ascii()+QString(")");
1411 s1=QString("EXP(")+operands.first()->ascii()+QString(")"); 1454 operands.removeFirst();
1412 operands.removeFirst(); 1455 operands.prepend(new QString(s1));
1413 operands.prepend(new QString(s1)); 1456 break;
1414 break; 1457 case 0x15://exp
1415 case 0x16://LN 1458 s1=QString("EXP(")+operands.first()->ascii()+QString(")");
1416 s1=QString("LN(")+operands.first()->ascii()+QString(")"); 1459 operands.removeFirst();
1417 operands.removeFirst(); 1460 operands.prepend(new QString(s1));
1418 operands.prepend(new QString(s1)); 1461 break;
1419 break; 1462 case 0x16://LN
1420 case 0x17://LOG10 1463 s1=QString("LN(")+operands.first()->ascii()+QString(")");
1421 s1=QString("LOG10(")+operands.first()->ascii()+QString(")"); 1464 operands.removeFirst();
1422 operands.removeFirst(); 1465 operands.prepend(new QString(s1));
1423 operands.prepend(new QString(s1)); 1466 break;
1424 break; 1467 case 0x17://LOG10
1425 case 0x18://ABS 1468 s1=QString("LOG10(")+operands.first()->ascii()+QString(")");
1426 s1=QString("ABS(")+operands.first()->ascii()+QString(")"); 1469 operands.removeFirst();
1427 operands.removeFirst(); 1470 operands.prepend(new QString(s1));
1428 operands.prepend(new QString(s1)); 1471 break;
1429 break; 1472 case 0x18://ABS
1430 case 0x19://int 1473 s1=QString("ABS(")+operands.first()->ascii()+QString(")");
1431 s1=QString("INT(")+operands.first()->ascii()+QString(")"); 1474 operands.removeFirst();
1432 operands.removeFirst(); 1475 operands.prepend(new QString(s1));
1433 operands.prepend(new QString(s1)); 1476 break;
1434 break; 1477 case 0x19://int
1435 case 0x1a://sign 1478 s1=QString("INT(")+operands.first()->ascii()+QString(")");
1436 s1=QString("SIGN(")+operands.first()->ascii()+QString(")"); 1479 operands.removeFirst();
1437 operands.removeFirst(); 1480 operands.prepend(new QString(s1));
1438 operands.prepend(new QString(s1)); 1481 break;
1439 break; 1482 case 0x1a://sign
1440 case 0x1b://round 1483 s1=QString("SIGN(")+operands.first()->ascii()+QString(")");
1441 operands.first(); 1484 operands.removeFirst();
1442 s1=QString("ROUND(")+operands.next()->ascii() 1485 operands.prepend(new QString(s1));
1443 +QString(",")+operands.first()->ascii() 1486 break;
1444 +QString(")"); 1487 case 0x1b://round
1445 operands.removeFirst();operands.removeFirst(); 1488 operands.first();
1446 operands.prepend(new QString(s1)); 1489 s1=QString("ROUND(")+operands.next()->ascii()
1447 break; 1490 +QString(",")+operands.first()->ascii()
1448 case 0x1d://index 1491 +QString(")");
1449 operands.first(); 1492 operands.removeFirst();operands.removeFirst();
1450 s1=QString("INDEX(")+operands.next()->ascii() 1493 operands.prepend(new QString(s1));
1451 +QString(",") 1494 break;
1452 +operands.first()->ascii()+QString(")"); 1495 case 0x1d://index
1453 operands.removeFirst(); 1496 operands.first();
1454 operands.removeFirst(); 1497 s1=QString("INDEX(")+operands.next()->ascii()
1455 operands.prepend(new QString(s1)); 1498 +QString(",")
1456 break; 1499 +operands.first()->ascii()+QString(")");
1457 case 0x1: // if ATTRIBUTE 1500 operands.removeFirst();
1458 operands.first();operands.next(); 1501 operands.removeFirst();
1459 s1=QString("IF(")+operands.next()->ascii()+QString(","); 1502 operands.prepend(new QString(s1));
1460 operands.first(); 1503 break;
1461 s1=s1+operands.next()->ascii()+QString(","); 1504 case 0x1: // if ATTRIBUTE
1462 s1=s1+operands.first()->ascii()+QString(")"); 1505 operands.first();operands.next();
1463 operands.removeFirst(); 1506 s1=QString("IF(")+operands.next()->ascii()+QString(",");
1464 operands.removeFirst(); 1507 operands.first();
1465 operands.removeFirst(); 1508 s1=s1+operands.next()->ascii()+QString(",");
1466 operands.prepend(new QString(s1)); 1509 s1=s1+operands.first()->ascii()+QString(")");
1467 break; 1510 operands.removeFirst();
1468 case 0x81://isblank 1511 operands.removeFirst();
1469 s1=QString("ISBLANK(")+operands.first()->ascii() 1512 operands.removeFirst();
1470 +QString(")"); 1513 operands.prepend(new QString(s1));
1471 operands.removeFirst(); 1514 break;
1472 operands.prepend(new QString(s1)); 1515 case 0x81://isblank
1473 break; 1516 s1=QString("ISBLANK(")+operands.first()->ascii()
1474 case 0x80://isnumber 1517 +QString(")");
1475 s1=QString("ISNUMBER(")+operands.first()->ascii() 1518 operands.removeFirst();
1476 +QString(")"); 1519 operands.prepend(new QString(s1));
1477 operands.removeFirst(); 1520 break;
1478 operands.prepend(new QString(s1)); 1521 case 0x80://isnumber
1479 break; 1522 s1=QString("ISNUMBER(")+operands.first()->ascii()
1480 case 0x120://ceiling 1523 +QString(")");
1481 operands.first(); 1524 operands.removeFirst();
1482 s1=QString("CEILING(")+operands.next()->ascii() 1525 operands.prepend(new QString(s1));
1483 +QString(",")+operands.first()->ascii() 1526 break;
1484 +QString(")"); 1527 case 0x120://ceiling
1485 operands.removeFirst();operands.removeFirst(); 1528 operands.first();
1486 operands.prepend(new QString(s1)); 1529 s1=QString("CEILING(")+operands.next()->ascii()
1487 break; 1530 +QString(",")+operands.first()->ascii()
1488 case 0x11d://floor 1531 +QString(")");
1489 operands.first(); 1532 operands.removeFirst();operands.removeFirst();
1490 s1=QString("FLOOR(")+operands.next()->ascii() 1533 operands.prepend(new QString(s1));
1491 +QString(",")+operands.first()->ascii() 1534 break;
1492 +QString(")"); 1535 case 0x11d://floor
1493 operands.removeFirst();operands.removeFirst(); 1536 operands.first();
1494 operands.prepend(new QString(s1)); 1537 s1=QString("FLOOR(")+operands.next()->ascii()
1495 break; 1538 +QString(",")+operands.first()->ascii()
1496 case 0x157://degrees 1539 +QString(")");
1497 s1=QString("DEGREES(")+operands.first()->ascii() 1540 operands.removeFirst();operands.removeFirst();
1498 +QString(")"); 1541 operands.prepend(new QString(s1));
1499 operands.removeFirst(); 1542 break;
1500 operands.prepend(new QString(s1)); 1543 case 0x157://degrees
1501 break; 1544 s1=QString("DEGREES(")+operands.first()->ascii()
1502 case 0x156://radians 1545 +QString(")");
1503 s1=QString("RADIANS(")+operands.first()->ascii() 1546 operands.removeFirst();
1504 +QString(")"); 1547 operands.prepend(new QString(s1));
1505 operands.removeFirst(); 1548 break;
1506 operands.prepend(new QString(s1)); 1549 case 0x156://radians
1507 break; 1550 s1=QString("RADIANS(")+operands.first()->ascii()
1508 case 0xb8://fact 1551 +QString(")");
1509 s1=QString("FACT(")+operands.first()->ascii() 1552 operands.removeFirst();
1510 +QString(")"); 1553 operands.prepend(new QString(s1));
1511 operands.removeFirst(); 1554 break;
1512 operands.prepend(new QString(s1)); 1555 case 0xb8://fact
1513 break; 1556 s1=QString("FACT(")+operands.first()->ascii()
1514 case 0x27://MOD 1557 +QString(")");
1515 operands.first(); 1558 operands.removeFirst();
1516 s1=QString("MOD(")+operands.next()->ascii() 1559 operands.prepend(new QString(s1));
1517 +QString(",")+operands.first()->ascii() 1560 break;
1518 +QString(")"); 1561 case 0x27://MOD
1519 operands.removeFirst();operands.removeFirst(); 1562 operands.first();
1520 operands.prepend(new QString(s1)); 1563 s1=QString("MOD(")+operands.next()->ascii()
1521 break; 1564 +QString(",")+operands.first()->ascii()
1522 case 0x151://power 1565 +QString(")");
1523 operands.first(); 1566 operands.removeFirst();operands.removeFirst();
1524 s1=QString("POWER(")+operands.next()->ascii() 1567 operands.prepend(new QString(s1));
1525 +QString(",")+operands.first()->ascii() 1568 break;
1526 +QString(")"); 1569 case 0x151://power
1527 operands.removeFirst();operands.removeFirst(); 1570 operands.first();
1528 operands.prepend(new QString(s1)); 1571 s1=QString("POWER(")+operands.next()->ascii()
1529 break; 1572 +QString(",")+operands.first()->ascii()
1530 case 0x3f://rand() 1573 +QString(")");
1531 s1="RAND()"; 1574 operands.removeFirst();operands.removeFirst();
1532 operands.prepend(new QString(s1)); 1575 operands.prepend(new QString(s1));
1533 break; 1576 break;
1534 case 0x4://sum 1577 case 0x3f://rand()
1535 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1578 s1="RAND()";
1536 s1=QString("SUM(")+operands.first()->ascii() 1579 operands.prepend(new QString(s1));
1537 +QString(")"); 1580 break;
1538 operands.removeFirst(); 1581 case 0x4://sum
1539 operands.prepend(new QString(s1)); 1582 for(w4=1;w4<w2;w4++) operands.removeFirst();
1540 break; 1583 s1=QString("SUM(")+operands.first()->ascii()
1541 case 0x6://min 1584 +QString(")");
1542 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1585 operands.removeFirst();
1543 s1=QString("MIN(")+operands.first()->ascii() 1586 operands.prepend(new QString(s1));
1544 +QString(")"); 1587 break;
1545 operands.removeFirst(); 1588 case 0x6://min
1546 operands.prepend(new QString(s1)); 1589 for(w4=1;w4<w2;w4++) operands.removeFirst();
1547 break; 1590 s1=QString("MIN(")+operands.first()->ascii()
1548 case 0x7://max 1591 +QString(")");
1549 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1592 operands.removeFirst();
1550 s1=QString("MAX(")+operands.first()->ascii() 1593 operands.prepend(new QString(s1));
1551 +QString(")"); 1594 break;
1552 operands.removeFirst(); 1595 case 0x7://max
1553 operands.prepend(new QString(s1)); 1596 for(w4=1;w4<w2;w4++) operands.removeFirst();
1554 break; 1597 s1=QString("MAX(")+operands.first()->ascii()
1555 case 0x5://average 1598 +QString(")");
1556 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1599 operands.removeFirst();
1557 s1=QString("AVERAGE(")+operands.first()->ascii() 1600 operands.prepend(new QString(s1));
1558 +QString(")"); 1601 break;
1559 operands.removeFirst(); 1602 case 0x5://average
1560 operands.prepend(new QString(s1)); 1603 for(w4=1;w4<w2;w4++) operands.removeFirst();
1561 break; 1604 s1=QString("AVERAGE(")+operands.first()->ascii()
1562 case 0x2e://var 1605 +QString(")");
1563 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1606 operands.removeFirst();
1564 s1=QString("VAR(")+operands.first()->ascii() 1607 operands.prepend(new QString(s1));
1565 +QString(")"); 1608 break;
1566 operands.removeFirst(); 1609 case 0x2e://var
1567 operands.prepend(new QString(s1)); 1610 for(w4=1;w4<w2;w4++) operands.removeFirst();
1568 break; 1611 s1=QString("VAR(")+operands.first()->ascii()
1569 case 0xc2://varp 1612 +QString(")");
1570 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1613 operands.removeFirst();
1571 s1=QString("VARP(")+operands.first()->ascii() 1614 operands.prepend(new QString(s1));
1572 +QString(")"); 1615 break;
1573 operands.removeFirst(); 1616 case 0xc2://varp
1574 operands.prepend(new QString(s1)); 1617 for(w4=1;w4<w2;w4++) operands.removeFirst();
1575 break; 1618 s1=QString("VARP(")+operands.first()->ascii()
1576 case 0xc://stdev 1619 +QString(")");
1577 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1620 operands.removeFirst();
1578 s1=QString("STDEV(")+operands.first()->ascii() 1621 operands.prepend(new QString(s1));
1579 +QString(")"); 1622 break;
1580 operands.removeFirst(); 1623 case 0xc://stdev
1581 operands.prepend(new QString(s1)); 1624 for(w4=1;w4<w2;w4++) operands.removeFirst();
1582 break; 1625 s1=QString("STDEV(")+operands.first()->ascii()
1583 case 0xc1://stdevp 1626 +QString(")");
1584 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1627 operands.removeFirst();
1585 s1=QString("STDEVP(")+operands.first()->ascii() 1628 operands.prepend(new QString(s1));
1586 +QString(")"); 1629 break;
1587 operands.removeFirst(); 1630 case 0xc1://stdevp
1588 operands.prepend(new QString(s1)); 1631 for(w4=1;w4<w2;w4++) operands.removeFirst();
1589 break; 1632 s1=QString("STDEVP(")+operands.first()->ascii()
1590 case 0x143://skew 1633 +QString(")");
1591 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1634 operands.removeFirst();
1592 s1=QString("SKEW(")+operands.first()->ascii() 1635 operands.prepend(new QString(s1));
1593 +QString(")"); 1636 break;
1594 operands.removeFirst(); 1637 case 0x143://skew
1595 operands.prepend(new QString(s1)); 1638 for(w4=1;w4<w2;w4++) operands.removeFirst();
1596 break; 1639 s1=QString("SKEW(")+operands.first()->ascii()
1597 case 0x142://kurt 1640 +QString(")");
1598 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1641 operands.removeFirst();
1599 s1=QString("KURT(")+operands.first()->ascii() 1642 operands.prepend(new QString(s1));
1600 +QString(")"); 1643 break;
1601 operands.removeFirst(); 1644 case 0x142://kurt
1602 operands.prepend(new QString(s1)); 1645 for(w4=1;w4<w2;w4++) operands.removeFirst();
1603 break; 1646 s1=QString("KURT(")+operands.first()->ascii()
1604 case 0x0://count 1647 +QString(")");
1605 for(w4=1;w4<w2;w4++) operands.removeFirst(); 1648 operands.removeFirst();
1606 s1=QString("COUNT(")+operands.first()->ascii() 1649 operands.prepend(new QString(s1));
1607 +QString(")"); 1650 break;
1608 operands.removeFirst(); 1651 case 0x0://count
1609 operands.prepend(new QString(s1)); 1652 for(w4=1;w4<w2;w4++) operands.removeFirst();
1610 break; 1653 s1=QString("COUNT(")+operands.first()->ascii()
1611 1654 +QString(")");
1612 default: 1655 operands.removeFirst();
1613 printf("token:FUNCTION_UNKNOWN=0x%x\r\n",w1); 1656 operands.prepend(new QString(s1));
1614 return QString("FUNC_UNKNOWN"); 1657 break;
1615 break; 1658
1616 1659 default:
1617 }; 1660 printf("token:FUNCTION_UNKNOWN=0x%x\r\n",w1);
1618 1661 return QString("FUNC_UNKNOWN");
1619 break; 1662 break;
1620 1663
1621 default: 1664 };
1622 printf("tokenUNKNOWN=0x%x\r\n",token); 1665
1623 return QString("TOKEN_UKNOWN"); 1666 break;
1624 //it is dangerous to go to idx++ and not return 1667
1625 // because the result is unexpected. 1668 default:
1626 // but there is a possibility the the parser will give the correct 1669 printf("tokenUNKNOWN=0x%x\r\n",token);
1627 // answer, because there are some tokens in excel formulas that can be //ignored. 1670 return QString("TOKEN_UKNOWN");
1628 idx++; 1671 //it is dangerous to go to idx++ and not return
1629 break; 1672 // because the result is unexpected.
1630 }; 1673 // but there is a possibility the the parser will give the correct
1631 1674 // answer, because there are some tokens in excel formulas that can be //ignored.
1632 }; 1675 idx++;
1633 1676 break;
1634 1677 };
1635 1678
1636 printf("{////FormulaParser}\r\n"); 1679 };
1637 printf("GetFormula:::::::r=%d,c=%d,,,%s\r\n",row,col,s1.ascii()); 1680
1638 printf("\r\n"); 1681
1639 s1=operands.first()->ascii(); 1682
1640 operands.clear(); 1683 printf("{////FormulaParser}\r\n");
1641return QString(s1); 1684 printf("GetFormula:::::::r=%d,c=%d,,,%s\r\n",row,col,s1.ascii());
1685 printf("\r\n");
1686 s1=operands.first()->ascii();
1687 operands.clear();
1688 return QString(s1);
1642}; 1689};
1643 1690
1644QString ExcelBook::FindCellName(int row, int col) 1691QString ExcelBook::FindCellName(int row, int col)
1645{ 1692{
1646 row++;col++; 1693 row++;col++;
1647 QString s1=""; 1694 QString s1="";
1648 int i1=col % 26; 1695 int i1=col % 26;
1649 int i2=col / 26; 1696 int i2=col / 26;
1650 if (i2!=0) s1=(char)(i2+65); //65 =A 1697 if (i2!=0) s1=(char)(i2+65); //65 =A
1651 s1=s1+(char)(i1+65-1); 1698 s1=s1+(char)(i1+65-1);
1652 return (s1+QString::number(row)); 1699 return (s1+QString::number(row));
1653}; 1700};
1654 1701
1655 1702