Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Excel.h

Go to the documentation of this file.
00001 /*
00002                =.            This file is part of the Opie Project
00003              .=l.            Copyright (C) 2004 Opie Developer Team <opie-devel@handhelds.org>
00004            .>+-=
00005  _;:,     .>    :=|.         This program is free software; you can
00006 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00007 :`=1 )Y*s>-.--   :           the terms of the GNU General Public
00008 .="- .-=="i,     .._         License as published by the Free Software
00009  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00010      ._= =}       :          or (at your option) any later version.
00011     .%`+i>       _;_.
00012     .i_,=:_.      -<s.       This program is distributed in the hope that
00013      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00014     : ..    .:,     . . .    without even the implied warranty of
00015     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00016   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00017 ..}^=.=       =       ;      Library General Public License for more
00018 ++=   -.     .`     .:       details.
00019  :     =  ...= . :.=-
00020  -.   .:....=;==+<;          You should have received a copy of the GNU
00021   -_. . .   )=.  =           Library General Public License along with
00022     --        :-=`           this library; see the file COPYING.LIB.
00023                              If not, write to the Free Software Foundation,
00024                              Inc., 59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 /* QT */
00030 #include <qstring.h>
00031 #include <qarray.h>
00032 #include <qlist.h>
00033 
00034 /* STD */
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include <math.h>
00038 #include <time.h>
00039 #include <sys/types.h>
00040 #include <strings.h>
00041 
00042 #define DATEFORMAT 0x1
00043 #define NUMBERFORMAT 0x2
00044 
00045 #define BIFF8 0x600
00046 #define BIFF7 0x500
00047 #define WBKGLOBAL 0x5
00048 #define WRKSHEET 0x10
00049 
00050 #define XL_ARRAY 0x221
00051 #define XL_BOUNDSHEET 0x85
00052 #define XL_BOF 0x809
00053 #define XL_BOOLERR 0x205
00054 #define XL_CONTINUE 0x3c
00055 #define XL_DIMENSION 0x200
00056 #define XL_EOF 0x0a
00057 #define XL_EXTSST 0xff
00058 #define XL_FORMULA 0x406
00059 #define XL_FORMULA2 0x6
00060 #define XL_FORMAT 0x41e
00061 #define XL_INDEX 0x20b
00062 #define XL_LABEL 0x204
00063 #define XL_LABELSST 0xfd
00064 #define XL_MULRK  0xbd
00065 #define XL_NAME 0x18
00066 #define XL_NOTE 0x1c
00067 #define XL_NUMBER 0x203
00068 #define XL_RK  0x7e
00069 #define XL_RK2  0x27e
00070 #define XL_ROW 0x208
00071 #define XL_SST 0xfc
00072 #define XL_STRING 0x207
00073 #define XL_TXO 0x1b6
00074 #define XL_XF 0xe0
00075 #define XL_UNKNOWN 0xffff
00076 
00077 #define CELL_LABEL 0x2
00078 #define CELL_NUMBER 0x3
00079 #define CELL_DATE 0x4
00080 #define CELL_BOOLEAN 0x5
00081 #define CELL_ERROR 0x6
00082 
00083 
00084 
00085 class ExcelFormat
00086 {
00087 public:
00088     int code;
00089     int type;
00090     QString format;
00091     ExcelFormat();
00092     ExcelFormat(int c,int t, QString s);
00093 };
00094 
00095 struct xfrecord
00096 {
00097     int code;
00098     int type;
00099     QString format;
00100 };
00101 
00102 class ExcelCell
00103 {
00104 public:
00105     int type;
00106     int row,col;
00107     int xfindex; //xf format index of cell
00108     int valuei;
00109     double valued;
00110     QString valuec;
00111 
00112 };
00113 
00114 class ExcelBREC
00115 {
00116 public:
00117     int code;
00118     int length;
00119     int position;
00120     char* data;
00121 };
00122 
00123 class SSTList
00124 {
00125 public:
00126     QArray <ExcelBREC*> rec;
00127 };
00128 
00129 class ExcelSheet
00130 {
00131 public:
00132     QString name;
00133     ExcelBREC BOFRecord;
00134     int position;
00135     int type;
00136     int rows;
00137     int cols;
00138 
00139     int cellsize,rowalloc,cellalloc;
00140     QArray <ExcelCell*> Cells;
00141     bool InitCells(void); // true if ok
00142     ExcelCell* Get(int row, int col);
00143     void Set(int row, int col, ExcelCell* cell);
00144 
00145 };
00146 
00147 struct mulrk
00148 {
00149     int row;
00150     int first;
00151     int last;
00152     int numrks;
00153     QArray<int> rknumbers;
00154     QArray<double> rkdbls;
00155     QArray<int> xfindices;
00156 };
00157 
00158 class ExcelBook
00159 {
00160 public:
00161     FILE *File;
00162     int Position;
00163     //int stringcount;
00164     QArray <QString*> SharedStrings;
00165     //int xfcount;
00166     QArray <ExcelFormat*> XFRecords;
00167     //int Sheetcount;
00168     QArray <ExcelSheet*> Sheets;
00169     //int name count;
00170     QArray <QString*> Names;
00171 
00172     QString dateformat;
00173     int Version;
00174     int endian;
00175     int Integer2Byte(int b1, int b2 );
00176     int Integer4Byte(int b1, int b2, int b3, int b4 );
00177     int Integer2ByteFile(FILE *f);
00178     float Float4Byte(int b1, int b2, int b3, int b4);
00179     double Double4Byte(int b1, int b2, int b3, int b4);
00180     double Double8Byte(int b1, int b2, int b3, int b4, int b5, int b6, int b7, int b8);
00181     void DetectEndian(void);
00182 
00183     bool OpenFile(char *Filename); // true if ok
00184     bool CloseFile(void); // true if ok
00185     void SeekPosition(int pos); // go to Pos
00186     void SeekSkip(int pos); // skips pos bytes.
00187     int FileEOF(void); //returns -1 if EOF else 0
00188     int Get2Bytes(void); //gets an int from the file
00189     char* Read(int pos, int length);
00190     QString ReadUnicodeChar(int pos, int length);
00191     QString* GetString(int num); //gets the num string from SharedStrings;
00192     int SeekBOF(void);
00193     ExcelBREC* GetBREC(void);
00194     ExcelBREC* PeekBREC(void);
00195     char* GetDataOfBREC(ExcelBREC* record);
00196     void ConvertCharToArray(ExcelBREC* record, char* chars, int length);
00197     int SheetHandleRecord(ExcelSheet* sheet, ExcelBREC* record);
00198     int ReadSheet(ExcelSheet* sheet); //read the sheet sheet*
00199     ExcelSheet* GetSheet(void);
00200     void ParseSheets(void);
00201     void GetSheets(void);
00202 
00203     bool ParseBook(char *file); // THIS IS THE MAIN PARSE FUNCTION of file
00204     QString GetASCII(char* inbytes, int pos, int chars);
00205     QString GetUnicode(char * inbytes, int pos, int chars);
00206     void HandleBoundSheet( ExcelBREC* rec);
00207     void HandleName(ExcelSheet* sheet, ExcelBREC* rec);
00208     ExcelFormat* GetFormatting(int xf);
00209     void HandleSetOfSST(ExcelBREC* rec/*, SSTList* cont*/, char* bytes);
00210     char* MergeBytesFromSSTs(ExcelBREC* rec,SSTList* cont);
00211     void HandleSST(ExcelBREC* rec);
00212     void HandleLabelSST(ExcelSheet* sheet, ExcelBREC* rec);
00213     ExcelCell* CellLabel(int row, int col, QString str);
00214     ExcelCell* CellNumber(int row, int col, int index, double d);
00215     QString* CellDataString(ExcelSheet* sh, int row, int col);
00216     int CellGetPrecision(double d);
00217     void CellSetDateFormat(char *d);
00218     void HandleMulrk(ExcelSheet* sheet, ExcelBREC* record);
00219     void MulrkRead(struct mulrk *mulrk, char* data);
00220     void HandleNumber(ExcelSheet* sheet, ExcelBREC* record);
00221     void HandleFormat(ExcelBREC* rec);
00222     void HandleXF(ExcelBREC* rec);
00223     void HandleRK(ExcelSheet* sheet, ExcelBREC* record);
00224     void HandleFormula(ExcelSheet* sheet, ExcelBREC* record);
00225     QString GetFormula(int row, int col, ExcelSheet* sheet, char* data, int sz);
00226     QString FindCellName(int row, int col);
00227 };
00228 

Generated on Sat Nov 5 16:17:00 2005 for OPIE by  doxygen 1.4.2