summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-sheet/Excel.h
authorhayzel <hayzel>2004-01-07 08:08:29 (UTC)
committer hayzel <hayzel>2004-01-07 08:08:29 (UTC)
commit08bc72c34cae85e5cc6541c9daaeba121597c961 (patch) (unidiff)
treedf5b263a84099ffdf8e0b86fda9a9fe61b90d30e /noncore/apps/opie-sheet/Excel.h
parent656e80e7b35c4aefd49ffe7756d895f4e7370de1 (diff)
downloadopie-08bc72c34cae85e5cc6541c9daaeba121597c961.zip
opie-08bc72c34cae85e5cc6541c9daaeba121597c961.tar.gz
opie-08bc72c34cae85e5cc6541c9daaeba121597c961.tar.bz2
January 7, 2004
* Release by hayzel (koppermind@panafonet.gr) This version has many valuable changes, though It may have some annoying bugs. Please if you are interested in opie-sheet try it hard, so I can fix some of them. Also If you want some other functions that must be here and are missing feel free to ask them. (no financial functions please. :) I really hate them ) -Fixed a bug with non closed parenthesis editing&recalculation infinite loop. -Added support for functions that can parse parameters not ONLY as numbers but also as strings. -Added many functions that cover many computational topics rendering opie-sheet a computational tool-spreadsheet at last. (total 90 functions!) -Maintained compatibility with the opie-fileformat. -New icons. -Found that the DataParser was not a real RPN compiler of the expressions. In fact it was returning faulty results in calculations, in both binary or unary operations. A1-A2-A3 was parsed as A1-(A2-A3). A1 was parsed as A1. -Added new class "Expression" a general Parser for spreadsheet-expression. Imported from an old C# project of mine. -Now can also parse <>=!%&^|"" in expressions. -Added experimental Excel File format import!. The opie-sheet can import any excel file in BIFF7/BIFF8 format. These formats are used in Excel XP,2000,95. The Excel Importer class is in a good coding level.. BUT it is not complete. Only strings,numbers,formulas are imported. Not formatting rules. Not all the functions are converted in the functions of opie-sheet. Infact FEW functions are converted. -Fixed a bug with Sheet Recalculation. Added ReCalc() function. Opie-sheet was calculating wrong the values of expression in opening/importing. if a value needed was not loaded yet in the time of calculation. Solved with ReCalc() each time the active sheet is changing. *known issues: -if someone enters directly text as parameter to a string function the text renders as uppercase due to the calculation engine that uppercases all the parsing sentence. -randbetween return only integer part random... if both limit numbers are integers. -skew and kurt function give different results compared to kspread-oofice equivalents. -unstable parser Excel Class -string vars and string functions are not correctly handled by excel importer. -unicode strings are converted FINE in QString unicode format, but cannot be rendered fine if a suitable unicode font is not setuped as the default string. So the string is junked in the opie-sheet and may crash the parser. *TODOs: -surelly a much full-stable excel importer. -Cell Manipulation of many Data is really slow.... must change the QList data type. To a structure more efficient. -maybe some more functions. -maybe some kind of charts drawing? -maybe kspread or ooffice files import/export.
Diffstat (limited to 'noncore/apps/opie-sheet/Excel.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/Excel.h205
1 files changed, 205 insertions, 0 deletions
diff --git a/noncore/apps/opie-sheet/Excel.h b/noncore/apps/opie-sheet/Excel.h
new file mode 100644
index 0000000..0a581cf
--- a/dev/null
+++ b/noncore/apps/opie-sheet/Excel.h
@@ -0,0 +1,205 @@
1
2#include <stdio.h>
3#include <stdlib.h>
4#include <math.h>
5#include <time.h>
6#include <sys/types.h>
7#include <strings.h>
8#include <qstring.h>
9#include <qarray.h>
10#include <qlist.h>
11
12#define DATEFORMAT 0x1
13#define NUMBERFORMAT 0x2
14
15#define BIFF8 0x600
16#define BIFF7 0x500
17#define WBKGLOBAL 0x5
18#define WRKSHEET 0x10
19
20#define XL_ARRAY 0x221
21#define XL_BOUNDSHEET 0x85
22#define XL_BOF 0x809
23#define XL_BOOLERR 0x205
24#define XL_CONTINUE 0x3c
25#define XL_DIMENSION 0x200
26#define XL_EOF 0x0a
27#define XL_EXTSST 0xff
28#define XL_FORMULA 0x406
29#define XL_FORMULA2 0x6
30#define XL_FORMAT 0x41e
31#define XL_INDEX 0x20b
32#define XL_LABEL 0x204
33#define XL_LABELSST 0xfd
34#define XL_MULRK 0xbd
35#define XL_NAME 0x18
36#define XL_NOTE 0x1c
37#define XL_NUMBER 0x203
38#define XL_RK 0x7e
39#define XL_RK2 0x27e
40#define XL_ROW 0x208
41#define XL_SST 0xfc
42#define XL_STRING 0x207
43#define XL_TXO 0x1b6
44#define XL_XF 0xe0
45#define XL_UNKNOWN 0xffff
46
47#define CELL_LABEL 0x2
48#define CELL_NUMBER 0x3
49#define CELL_DATE 0x4
50#define CELL_BOOLEAN 0x5
51#define CELL_ERROR 0x6
52
53
54
55class ExcelFormat
56{
57public:
58int code;
59int type;
60QString format;
61ExcelFormat();
62ExcelFormat(int c,int t, QString s);
63};
64
65struct xfrecord
66{
67int code;
68int type;
69QString format;
70};
71
72class ExcelCell
73{
74public:
75int type;
76int row,col;
77int xfindex; //xf format index of cell
78int valuei;
79double valued;
80QString valuec;
81
82};
83
84class ExcelBREC
85{
86public:
87 int code;
88 int length;
89 int position;
90 char* data;
91};
92
93class SSTList
94{
95public:
96 QArray <ExcelBREC*> rec;
97};
98
99class ExcelSheet
100{
101public:
102 QString name;
103 ExcelBREC BOFRecord;
104 int position;
105 int type;
106 int rows;
107 int cols;
108
109 int cellsize,rowalloc,cellalloc;
110 QArray <ExcelCell*> Cells;
111 bool InitCells(void); // true if ok
112 ExcelCell* Get(int row, int col);
113 void Set(int row, int col, ExcelCell* cell);
114
115};
116
117struct mulrk {
118 int row;
119 int first;
120 int last;
121 int numrks;
122 QArray<int> rknumbers;
123 QArray<double> rkdbls;
124 QArray<int> xfindices;
125};
126
127
128
129
130class ExcelBook
131{
132public:
133FILE *File;
134int Position;
135//int stringcount;
136QArray <QString*> SharedStrings;
137//int xfcount;
138QArray <ExcelFormat*> XFRecords;
139//int Sheetcount;
140QArray <ExcelSheet*> Sheets;
141//int name count;
142QArray <QString*> Names;
143
144QString dateformat;
145int Version;
146int endian;
147int Integer2Byte(int b1, int b2 );
148int Integer4Byte(int b1, int b2, int b3, int b4 );
149int Integer2ByteFile(FILE *f);
150float Float4Byte(int b1, int b2, int b3, int b4);
151double Double4Byte(int b1, int b2, int b3, int b4);
152double Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8);
153void DetectEndian(void);
154
155bool OpenFile(char *Filename); // true if ok
156bool CloseFile(void); // true if ok
157void SeekPosition(int pos); // go to Pos
158void SeekSkip(int pos); // skips pos bytes.
159int FileEOF(void); //returns -1 if EOF else 0
160int Get2Bytes(void); //gets an int from the file
161char* Read(int pos, int length);
162QString ReadUnicodeChar(int pos, int length);
163QString* GetString(int num); //gets the num string from SharedStrings;
164int SeekBOF(void);
165ExcelBREC* GetBREC(void);
166ExcelBREC* PeekBREC(void);
167char* GetDataOfBREC(ExcelBREC* record);
168void ConvertCharToArray(ExcelBREC* record, char* chars, int length);
169int SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record);
170int ReadSheet(ExcelSheet* sheet); //read the sheet sheet*
171ExcelSheet* GetSheet(void);
172void ParseSheets(void);
173void GetSheets(void);
174
175bool ParseBook(char *file); // THIS IS THE MAIN PARSE FUNCTION of file
176QString GetASCII(char* inbytes, int pos, int chars);
177QString GetUnicode(char * inbytes, int pos, int chars);
178void HandleBoundSheet( ExcelBREC* rec);
179void HandleName(ExcelSheet* sheet, ExcelBREC* rec);
180ExcelFormat* GetFormatting(int xf);
181void HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes);
182char* MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont);
183void HandleSST(ExcelBREC* rec);
184void HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec);
185ExcelCell* CellLabel(int row, int col, QString str);
186ExcelCell* CellNumber(int row, int col, int index, double d);
187QString* CellDataString(ExcelSheet* sh, int row, int col);
188int CellGetPrecision(double d);
189void CellSetDateFormat(char *d);
190void HandleMulrk(ExcelSheet* sheet, ExcelBREC* record);
191void MulrkRead(struct mulrk *mulrk, char* data);
192void HandleNumber(ExcelSheet* sheet, ExcelBREC* record);
193void HandleFormat(ExcelBREC* rec);
194void HandleXF(ExcelBREC* rec);
195void HandleRK(ExcelSheet* sheet, ExcelBREC* record);
196void HandleFormula(ExcelSheet* sheet, ExcelBREC* record);
197QString GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz);
198QString FindCellName(int row, int col);
199
200
201
202
203
204};
205