filters

excel.h

00001 /* Swinder - Portable library for spreadsheet
00002    Copyright (C) 2003-2006 Ariya Hidayat <ariya@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008    
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA
00018 */
00019 
00020 #ifndef SWINDER_EXCEL_H
00021 #define SWINDER_EXCEL_H
00022 
00023 #include <string>
00024 #include <iostream>
00025 #include <vector>
00026 
00027 #include "swinder.h"
00028 
00029 namespace Swinder
00030 {
00031 
00035 enum { UnknownExcel = 0, Excel95, Excel97, Excel2000 };
00036 
00037 class Record;
00038 
00039 // rich-text, unicode, far-east support Excel string
00040 
00041 class EString
00042 {
00043 public:
00044 
00045   EString();
00046   
00047   EString( const EString& );
00048   
00049   EString& operator=( const EString& );
00050   
00051   ~EString();
00052   
00053   bool unicode() const;
00054   
00055   void setUnicode( bool u );
00056   
00057   bool richText() const;
00058   
00059   void setRichText( bool r );
00060     
00061   UString str() const;
00062   
00063   void setStr( const UString& str );
00064   
00065   // space allocate for the string, not length (use string.length() for that) 
00066   unsigned size() const;
00067   void setSize( unsigned size ); // HACKS
00068   
00069   
00070   static EString fromUnicodeString( const void* p, bool longString, unsigned maxsize = 0 );
00071   
00072   static EString fromSheetName( const void* p, unsigned maxsize = 0 );
00073   
00074   // from the buffer
00075   // longstring means 16-bit string length, usually for label
00076   // longstring=false is normally for sheet name
00077   static EString fromByteString( const void* p, bool longString, unsigned maxsize = 0 );
00078   
00079 private:
00080   class Private;
00081   Private* d;
00082 };
00083 
00084 class FormulaToken
00085 {
00086 public:
00087 
00088   enum
00089   {
00090     // should match Excel's PTG
00091     Unused      = 0x00,
00092     Matrix      = 0x01,
00093     Table       = 0x02,
00094     Add         = 0x03,
00095     Sub         = 0x04,
00096     Mul         = 0x05,
00097     Div         = 0x06,
00098     Power       = 0x07,
00099     Concat      = 0x08,
00100     LT          = 0x09,
00101     LE          = 0x0a,
00102     EQ          = 0x0b,
00103     GE          = 0x0c,
00104     GT          = 0x0d,
00105     NE          = 0x0e,
00106     Intersect   = 0x0f,
00107     List        = 0x10,
00108     Range       = 0x11,
00109     UPlus       = 0x12,
00110     UMinus      = 0x13,
00111     Percent     = 0x14,
00112     Paren       = 0x15,
00113     MissArg     = 0x16,
00114     String      = 0x17,
00115     NatFormula  = 0x18,
00116     Attr        = 0x19,
00117     Sheet       = 0x1a,
00118     EndSheet    = 0x1b,
00119     ErrorCode   = 0x1c,
00120     Bool        = 0x1d,
00121     Integer     = 0x1e,
00122     Float       = 0x1f,
00123     Array       = 0x20,
00124     Function    = 0x21,
00125     FunctionVar = 0x22,
00126     Name        = 0x23,
00127     Ref         = 0x24,
00128     Area        = 0x25,
00129     MemArea     = 0x26,
00130     MemErr      = 0x27,
00131     MemNoMem    = 0x28,
00132     MemFunc     = 0x29,
00133     RefErr      = 0x2a,
00134     AreaErr     = 0x2b,
00135     RefN        = 0x2c,
00136     AreaN       = 0x2d,
00137     MemAreaN    = 0x2e,
00138     MemNoMemN   = 0x2f,
00139     NameX       = 0x39,
00140     Ref3d       = 0x3a,
00141     Area3d      = 0x3b,
00142     RefErr3d    = 0x3c,
00143     AreaErr3d   = 0x3d
00144   };
00145 
00146   FormulaToken();
00147   FormulaToken( unsigned id );
00148   FormulaToken( const FormulaToken& );
00149   ~FormulaToken();
00150   
00151   // token id, excluding token class
00152   unsigned id() const;
00153   const char* idAsString() const;
00154   
00155   // Excel version
00156   unsigned version() const;
00157   void setVersion( unsigned version );  // Excel version
00158   
00159   // size of data, EXCLUDING the byte for token id
00160   unsigned size() const;
00161   void setData( unsigned size, const unsigned char* data );
00162   
00163   // only when id returns ErrorCode, Bool, Integer, Float, or String
00164   Value value() const;
00165   
00166   // only when id is Function or FunctionVar
00167   unsigned functionIndex() const;
00168   const char* functionName() const;  // for non external function
00169   unsigned functionParams() const;
00170   
00171   // only when id is Ref or Ref3d
00172   UString ref( unsigned row, unsigned col ) const;
00173 
00174   // only when id is Area or Area3d
00175   UString area( unsigned row, unsigned col ) const;
00176 
00177   // only when id is Ref3d or Area3d
00178   unsigned externSheetRef() const;
00179 
00180   // only when id is Attr
00181   unsigned attr() const;
00182 
00183   // only when id is NameX
00184   unsigned nameIndex() const;
00185 
00186   // only when id is Matrix
00187   unsigned refRow() const;
00188   unsigned refColumn() const;
00189 
00190 private:
00191   class Private;
00192   Private *d;  
00193 };
00194 
00195 typedef std::vector<FormulaToken> FormulaTokens;
00196 
00197 std::ostream& operator<<( std::ostream& s, FormulaToken token );
00198 
00204 class Record
00205 {
00206 public:
00207 
00212   static const unsigned int id;
00213   
00214   virtual unsigned int rtti(){
00215       return this->id;
00216   }
00217   
00221   Record();
00222   
00226   virtual ~Record();
00227   
00231   static Record* create( unsigned type );
00232   
00233   void setVersion( unsigned v ){ ver = v; };
00234   
00235   unsigned version(){ return ver; };
00236 
00240   virtual void setData( unsigned size, const unsigned char* data );
00241   
00246   void setPosition( unsigned pos );
00247   
00251   unsigned position() const;
00252   
00256   virtual const char* name(){ return "Unknown"; }
00257 
00261   virtual void dump( std::ostream& out ) const;
00262   
00263 protected:
00264 
00265    // position of this record in the OLE stream
00266    unsigned stream_position;
00267 
00268    // in which version does this record denote ?
00269    unsigned ver;
00270 
00271 private:
00272    // no copy or assign
00273    Record( const Record& );
00274    Record& operator=( const Record& );
00275    
00276 };
00277 
00283 class CellInfo
00284 {
00285 public:
00286 
00290   CellInfo();
00291 
00295   virtual ~CellInfo();
00296 
00303   virtual unsigned row() const;
00304 
00311   virtual unsigned column() const;
00312 
00318   virtual unsigned xfIndex() const;
00319 
00326   virtual void setRow( unsigned r );
00327 
00334   virtual void setColumn( unsigned c );
00335 
00341   virtual void setXfIndex( unsigned i );
00342 
00343 private:
00344    // no copy or assign
00345    CellInfo( const CellInfo& );
00346    CellInfo& operator=( const CellInfo& );
00347 
00348    class Private;
00349    Private* info;
00350 };
00351 
00357 class ColumnSpanInfo
00358 {
00359 public:
00360 
00364   ColumnSpanInfo();
00365 
00369   virtual ~ColumnSpanInfo();
00370 
00377   virtual unsigned firstColumn() const;
00378 
00385   virtual unsigned lastColumn() const;
00386 
00393   virtual void setFirstColumn( unsigned c );
00394 
00401   virtual void setLastColumn( unsigned c );
00402 
00403 private:
00404    // no copy or assign
00405    ColumnSpanInfo( const ColumnSpanInfo& );
00406    ColumnSpanInfo& operator=( const ColumnSpanInfo& );
00407 
00408    class Private;
00409    Private* spaninfo;
00410 };
00411 
00418 class BackupRecord : public Record
00419 {
00420 public:
00421 
00422   static const unsigned int id;
00423 
00427   BackupRecord();
00428   
00432   ~BackupRecord();
00433   
00434   unsigned int rtti(){
00435       return this->id;
00436   }
00442   bool backup() const;
00443   
00449   void setBackup( bool r );
00450 
00451   virtual void setData( unsigned size, const unsigned char* data );
00452 
00453   virtual const char* name(){ return "BACKUP"; }
00454 
00455   virtual void dump( std::ostream& out ) const;
00456 
00457 private:
00458   // no copy or assign
00459   BackupRecord( const BackupRecord& );
00460   BackupRecord& operator=( const BackupRecord& );
00461 
00462   class Private;
00463   Private* d;
00464 };
00465 
00466 
00480 class BOFRecord : public Record
00481 {
00482 public:
00483 
00487   static const unsigned int id;
00488 
00489   unsigned int rtti(){
00490       return this->id;
00491   }
00492 
00496   enum { UnknownType = 0, Workbook, Worksheet, Chart, VBModule, MacroSheet, Workspace };
00497 
00501   BOFRecord();
00502 
00506   virtual ~BOFRecord();
00507 
00508   virtual void setData( unsigned size, const unsigned char* data );
00509 
00516   unsigned version() const;
00517 
00521   const char* versionAsString() const;
00522 
00526   unsigned type() const;
00527 
00531   const char* typeAsString() const;
00532 
00533   virtual const char* name(){ return "BOF"; }
00534 
00535   virtual void dump( std::ostream& out ) const;
00536 
00537 private:
00538    // no copy or assign
00539    BOFRecord( const BOFRecord& );
00540    BOFRecord& operator=( const BOFRecord& );
00541 
00542    class Private;
00543    Private *d;
00544 };
00545 
00552 class BlankRecord : public Record, public CellInfo
00553 {
00554 public:
00555 
00556   static const unsigned int id;
00557 
00558   unsigned int rtti(){
00559       return this->id;
00560   }
00561 
00565   BlankRecord();
00566 
00567   virtual void setData( unsigned size, const unsigned char* data );
00568 
00569   virtual const char* name(){ return "BLANK"; }
00570 
00571   virtual void dump( std::ostream& out ) const;
00572 
00573 private:
00574    // no copy or assign
00575    BlankRecord( const BlankRecord& );
00576    BlankRecord& operator=( const BlankRecord& );
00577 };
00578 
00585 class BoolErrRecord : public Record, public CellInfo
00586 {
00587 public:
00588 
00592   static const unsigned int id;
00593 
00594   unsigned int rtti(){ return this->id; }
00595 
00599   BoolErrRecord();
00600 
00604   virtual ~BoolErrRecord();
00605 
00609   Value value() const;
00610 
00611   virtual void setData( unsigned size, const unsigned char* data );
00612 
00613   virtual const char* name(){ return "BOOLERR"; }
00614 
00615   virtual void dump( std::ostream& out ) const;
00616 
00617 private:
00618   // no copy or assign
00619   BoolErrRecord( const BoolErrRecord& );
00620   BoolErrRecord& operator=( const BoolErrRecord& );
00621 
00622   class Private;
00623   Private* d;
00624 };
00625 
00632 class BottomMarginRecord : public Record
00633 {
00634 public:
00635 
00636   static const unsigned int id;
00637 
00638   unsigned int rtti(){
00639       return this->id;
00640   }
00644   BottomMarginRecord();
00645   
00649   ~BottomMarginRecord();
00650   
00654   double bottomMargin() const;
00655   
00659   void setBottomMargin( double m );
00660 
00661   virtual void setData( unsigned size, const unsigned char* data );
00662 
00663   virtual const char* name(){ return "BOTTOMMARGIN"; }
00664 
00665   virtual void dump( std::ostream& out ) const;
00666 
00667 private:
00668   // no copy or assign
00669   BottomMarginRecord( const BottomMarginRecord& );
00670   BottomMarginRecord& operator=( const BottomMarginRecord& );
00671 
00672   class Private;
00673   Private* d;
00674 };
00675 
00689 // TODO support for strong visible
00690 
00691 class BoundSheetRecord : public Record
00692 {
00693 public:
00694 
00695   static const unsigned int id;
00696 
00697   unsigned int rtti(){
00698       return this->id;
00699   }
00700 
00704   BoundSheetRecord();
00705 
00709   virtual ~BoundSheetRecord();
00710   
00714   enum { Worksheet=0, Chart=2, VBModule=6 };
00715   
00720   void setType( unsigned type );
00721   
00726   unsigned type() const;
00727   
00733   const char* typeAsString() const;
00734   
00738   void setVisible( bool visible );
00739   
00743   bool visible() const;
00744   
00748   void setSheetName( const UString& name );
00749   
00753   UString sheetName() const;
00754   
00758   void setBofPosition( unsigned pos );
00759   
00763   unsigned bofPosition() const;
00764 
00765   virtual void setData( unsigned size, const unsigned char* data );
00766   
00767   virtual const char* name(){ return "BOUNDSHEET"; }
00768   
00769   virtual void dump( std::ostream& out ) const;
00770 
00771 private:
00772   // no copy or assign
00773   BoundSheetRecord( const BoundSheetRecord& );
00774   BoundSheetRecord& operator=( const BoundSheetRecord& );
00775 
00776   class Private;
00777   Private* d;
00778 };
00779 
00786 class CalcModeRecord : public Record
00787 {
00788 public:
00789 
00790   static const unsigned int id;
00791 
00792   unsigned int rtti(){
00793       return this->id;
00794   }
00795 
00799   CalcModeRecord();
00800   
00804   ~CalcModeRecord();
00805   
00811   bool autoCalc() const;
00812   
00818   void setAutoCalc( bool r );
00819 
00820   virtual void setData( unsigned size, const unsigned char* data );
00821 
00822   virtual const char* name(){ return "CALCMODE"; }
00823 
00824   virtual void dump( std::ostream& out ) const;
00825 
00826 private:
00827   // no copy or assign
00828   CalcModeRecord( const CalcModeRecord& );
00829   CalcModeRecord& operator=( const CalcModeRecord& );
00830 
00831   class Private;
00832   Private* d;
00833 };
00834 
00841 class ColInfoRecord : public Record, public ColumnSpanInfo
00842 {
00843 public:
00844 
00845   static const unsigned int id;
00846 
00847   unsigned int rtti(){
00848       return this->id;
00849   }
00850 
00854   ColInfoRecord();
00855 
00859   virtual ~ColInfoRecord();
00860   
00866   unsigned xfIndex() const;
00867   
00873   void setXfIndex( unsigned i );
00874   
00882   unsigned width() const;
00883   
00891   void setWidth( unsigned w );
00892   
00898   bool hidden() const;
00899   
00905   void setHidden( bool h );
00906 
00912   bool collapsed() const;
00913   
00919   void setCollapsed( bool c );
00920   
00927   unsigned outlineLevel() const;
00928   
00935   void setOutlineLevel( unsigned l );
00936   
00937   virtual void setData( unsigned size, const unsigned char* data );
00938 
00939   virtual const char* name(){ return "COLINFO"; }
00940 
00941   virtual void dump( std::ostream& out ) const;
00942 
00943 private:
00944    // no copy or assign
00945    ColInfoRecord( const ColInfoRecord& );
00946    ColInfoRecord& operator=( const ColInfoRecord& );
00947 
00948    class Private;
00949    Private *d;
00950 };
00951 
00962 class DateModeRecord : public Record
00963 {
00964 public:
00965 
00966   static const unsigned int id;
00967 
00968   unsigned int rtti(){
00969       return this->id;
00970   }
00971 
00975   DateModeRecord();
00976   
00980   ~DateModeRecord();
00981   
00988   bool base1904() const;
00989   
00996   void setBase1904( bool r );
00997 
00998   virtual void setData( unsigned size, const unsigned char* data );
00999 
01000   virtual const char* name(){ return "DATEMODE"; }
01001 
01002   virtual void dump( std::ostream& out ) const;
01003 
01004 private:
01005   // no copy or assign
01006   DateModeRecord( const DateModeRecord& );
01007   DateModeRecord& operator=( const DateModeRecord& );
01008 
01009   class Private;
01010   Private* d;
01011 };
01012 
01019 class DimensionRecord : public Record
01020 {
01021 public:
01022 
01023   static const unsigned int id;
01024 
01025   unsigned int rtti(){
01026       return this->id;
01027   }
01028 
01032   DimensionRecord();
01033   
01037   ~DimensionRecord();
01038   
01044   unsigned firstRow() const;
01045   
01051   void setFirstRow( unsigned r );
01052   
01058   unsigned lastRow() const;
01059   
01065   void setLastRow( unsigned r );
01066   
01072   unsigned firstColumn() const;
01073   
01079   void setFirstColumn( unsigned r );
01080   
01086   unsigned lastColumn() const;
01087   
01093   void setLastColumn( unsigned r );
01094   
01095   virtual const char* name(){ return "DIMENSION"; }
01096   
01097   virtual void setData( unsigned size, const unsigned char* data );
01098   
01099   virtual void dump( std::ostream& out ) const;
01100 
01101 private:
01102    // no copy or assign
01103    DimensionRecord( const DimensionRecord& );
01104    DimensionRecord& operator=( const DimensionRecord& );
01105    
01106    class Private;
01107    Private *d;
01108 };
01109 
01110 class ExternNameRecord : public Record
01111 {
01112 public:
01113 
01114   static const unsigned int id;
01115 
01116   unsigned int rtti(){
01117     return this->id;
01118   }
01119 
01120   ExternNameRecord();
01121 
01122   ~ExternNameRecord();
01123 
01124   // one-based sheet index
01125   // if 0 means AddIn function
01126   unsigned sheetIndex() const;
01127 
01128   void setSheetIndex( unsigned sheetIndex );
01129 
01130   UString externName() const;
01131 
01132   void setExternName( const UString& name );
01133 
01134   virtual void setData( unsigned size, const unsigned char* data );
01135 
01136 
01137 
01138   virtual const char* name(){ return "EXTERNNAME"; }
01139 
01140   virtual void dump( std::ostream& out ) const;
01141 
01142 private:
01143    // no copy or assign
01144    ExternNameRecord( const ExternNameRecord& );
01145    ExternNameRecord& operator=( const ExternNameRecord& );
01146    
01147    class Private;
01148    Private *d;
01149 };
01150 
01151 class ExternSheetRecord : public Record
01152 {
01153 public:
01154 
01155   static const unsigned int id;
01156 
01157   unsigned int rtti(){
01158     return this->id;
01159   }
01160 
01161   ExternSheetRecord();
01162 
01163   ~ExternSheetRecord();
01164 
01165   unsigned count() const;
01166 
01167   unsigned refIndex(unsigned i) const;
01168   unsigned firstSheet(unsigned i) const;
01169   unsigned lastSheet(unsigned i) const;
01170 
01171   UString refName() const;
01172 
01173   virtual void setData( unsigned size, const unsigned char* data );
01174 
01175   virtual const char* name(){ return "EXTERNSHEET"; }
01176 
01177   virtual void dump( std::ostream& out ) const;
01178 
01179 private:
01180    // no copy or assign
01181    ExternSheetRecord( const ExternNameRecord& );
01182    ExternSheetRecord& operator=( const ExternNameRecord& );
01183    
01184    class Private;
01185    Private *d;
01186 };
01187 
01188 
01198 class EOFRecord : public Record
01199 {
01200 public:
01201 
01202   static const unsigned int id;
01203 
01204   unsigned int rtti(){
01205       return this->id;
01206   }
01207 
01211   EOFRecord();
01212 
01216   virtual ~EOFRecord();
01217   
01218   virtual void setData( unsigned size, const unsigned char* data );
01219 
01220   virtual const char* name(){ return "EOF"; }
01221 
01222   virtual void dump( std::ostream& out ) const;
01223 
01224 private:
01225    // no copy or assign
01226    EOFRecord( const EOFRecord& );
01227    EOFRecord& operator=( const EOFRecord& );
01228 };
01229 
01230 class FilepassRecord : public Record
01231 {
01232 public:
01233 
01234   static const unsigned int id;
01235 
01236   unsigned int rtti(){
01237     return this->id;
01238   }
01239 
01243   FilepassRecord();
01244 
01248   virtual ~FilepassRecord();
01249   
01250   virtual void setData( unsigned size, const unsigned char* data );
01251 
01252   virtual const char* name(){ return "FILEPASS"; }
01253 
01254   virtual void dump( std::ostream& out ) const;
01255 
01256 private:
01257    // no copy or assign
01258    FilepassRecord( const FilepassRecord& );
01259    FilepassRecord& operator=( const FilepassRecord& );
01260 };
01261 
01276 class FontRecord : public Record
01277 {
01278 public:
01279 
01280   static const unsigned int id;
01281 
01282   unsigned int rtti(){
01283       return this->id;
01284   }
01285 
01289   FontRecord();
01290   
01294   FontRecord( const FontRecord& fr );
01295   
01299   FontRecord& operator=( const FontRecord& fr );
01300 
01304   virtual ~FontRecord();
01305   
01306   enum { 
01307     Normal = 0, 
01308     Superscript = 1,
01309     Subscript = 2 };
01310     
01311   enum { 
01312     None = 0, 
01313     Single = 1, 
01314     Double = 2, 
01315     SingleAccounting = 0x21, 
01316     DoubleAccounting = 0x22 };
01317   
01318   unsigned height() const;
01319   void setHeight( unsigned h );
01320   
01326   UString fontName() const;
01327   
01333   void setFontName( const UString& fn );
01334 
01335   // FIXME what is this font family ? index ?  
01336   unsigned fontFamily() const;
01337   void setFontFamily( unsigned f );
01338   
01339   // FIXME and character set index ?
01340   unsigned characterSet() const;
01341   void setCharacterSet( unsigned s );
01342   
01348   unsigned colorIndex() const;
01349   
01355   void setColorIndex( unsigned c );
01356   
01363   unsigned boldness() const;
01364   
01371   void setBoldness( unsigned b );
01372   
01378   bool italic() const;
01379   
01385   void setItalic( bool i );
01386   
01392   bool strikeout() const;
01393   
01399   void setStrikeout( bool s );
01400   
01407   unsigned escapement() const;
01408   
01415   void setEscapement( unsigned s );
01416   
01424   unsigned underline() const;
01425   
01433   void setUnderline( unsigned u );
01434   
01435   virtual void setData( unsigned size, const unsigned char* data );
01436 
01437   virtual const char* name(){ return "FONT"; }
01438 
01439   virtual void dump( std::ostream& out ) const;
01440 
01441 private:
01442    class Private;
01443    Private *d;
01444 };
01445 
01452 class FooterRecord : public Record
01453 {
01454 public:
01455 
01456   static const unsigned int id;
01457 
01458   unsigned int rtti(){
01459       return this->id;
01460   }
01461 
01465   FooterRecord();
01466   
01470   ~FooterRecord();
01471   
01475   UString footer() const;
01476   
01480   void setFooter( const UString& f );
01481   
01482   virtual void setData( unsigned size, const unsigned char* data );
01483 
01484   virtual const char* name(){ return "FOOTER"; }
01485 
01486   virtual void dump( std::ostream& out ) const;
01487 
01488 private:
01489   // no copy or assign
01490   FooterRecord( const FooterRecord& );
01491   FooterRecord& operator=( const FooterRecord& );
01492 
01493   class Private;
01494   Private* d;
01495 };
01496 
01508 class FormatRecord : public Record
01509 {
01510 public:
01511 
01512   static const unsigned int id;
01513 
01514   unsigned int rtti(){
01515       return this->id;
01516   }
01517 
01521   FormatRecord();
01522   
01526   ~FormatRecord();
01527   
01531   FormatRecord( const FormatRecord& fr );
01532   
01536   FormatRecord& operator=( const FormatRecord& fr );
01537   
01544   unsigned index() const;
01545   
01552   void setIndex( unsigned i );
01553 
01560   UString formatString() const;
01561   
01567   void setFormatString( const UString& fs );
01568     
01569   virtual const char* name(){ return "FORMAT"; }
01570   
01571   virtual void setData( unsigned size, const unsigned char* data );
01572 
01573   virtual void dump( std::ostream& out ) const;
01574 
01575 private:
01576    class Private;
01577    Private *d;
01578 };
01579 
01586 class FormulaRecord : public Record, public CellInfo
01587 {
01588 public:
01589 
01590   static const unsigned int id;
01591   static const unsigned int idOld; // for Pocket Excel support
01592 
01593   unsigned int rtti(){
01594       return this->id;
01595   }
01596 
01600   FormulaRecord();
01601   
01605   ~FormulaRecord();
01606   
01610   Value result() const;
01611   
01615   void setResult( const Value& v );
01616   
01617   FormulaTokens tokens() const;
01618   
01619   virtual void setData( unsigned size, const unsigned char* data );
01620 
01621   virtual const char* name(){ return "FORMULA"; }
01622 
01623   virtual void dump( std::ostream& out ) const;
01624 
01625 private:
01626   // no copy or assign
01627   FormulaRecord( const FormulaRecord& );
01628   FormulaRecord& operator=( const FormulaRecord& );
01629 
01630   class Private;
01631   Private* d;
01632 };
01633 
01640 class HeaderRecord : public Record
01641 {
01642 public:
01643 
01644   static const unsigned int id;
01645 
01646   unsigned int rtti(){
01647       return this->id;
01648   }
01649 
01653   HeaderRecord();
01654   
01658   ~HeaderRecord();
01659   
01663   UString header() const;
01664   
01668   void setHeader( const UString& h );
01669   
01670   virtual void setData( unsigned size, const unsigned char* data );
01671 
01672   virtual const char* name(){ return "HEADER"; }
01673 
01674   virtual void dump( std::ostream& out ) const;
01675 
01676 private:
01677   // no copy or assign
01678   HeaderRecord( const HeaderRecord& );
01679   HeaderRecord& operator=( const HeaderRecord& );
01680 
01681   class Private;
01682   Private* d;
01683 };
01684 
01685 
01695 class LabelRecord : public Record, public CellInfo
01696 {
01697 public:
01698 
01699   static const unsigned int id;
01700 
01701   unsigned int rtti(){
01702       return this->id;
01703   }
01704 
01708   LabelRecord();
01709 
01713   virtual ~LabelRecord();
01714 
01718   UString label() const;
01719   
01723   void setLabel( const UString& l );
01724 
01725   virtual void setData( unsigned size, const unsigned char* data );
01726 
01727   virtual const char* name(){ return "LABEL"; }
01728   
01729   virtual void dump( std::ostream& out ) const;
01730 
01731 private:
01732    // no copy or assign
01733    LabelRecord( const LabelRecord& );
01734    LabelRecord& operator=( const LabelRecord& );
01735 
01736    class Private;
01737    Private *d;
01738 };
01739 
01749 class LabelSSTRecord : public Record, public CellInfo
01750 {
01751 public:
01752 
01753   static const unsigned int id;
01754 
01755   unsigned int rtti(){
01756       return this->id;
01757   }
01758 
01762   LabelSSTRecord();
01763 
01767   virtual ~LabelSSTRecord();
01768 
01773   unsigned sstIndex() const;
01774 
01775   virtual void setData( unsigned size, const unsigned char* data );
01776 
01777   virtual const char* name(){ return "LABELSST"; }
01778   
01779   virtual void dump( std::ostream& out ) const;
01780 
01781 private:
01782    // no copy or assign
01783    LabelSSTRecord( const LabelSSTRecord& );
01784    LabelSSTRecord& operator=( const LabelSSTRecord& );
01785 
01786    class Private;
01787    Private *d;
01788 };
01789 
01794 class LeftMarginRecord : public Record
01795 {
01796 public:
01797 
01798   static const unsigned int id;
01799 
01800   unsigned int rtti(){
01801       return this->id;
01802   }
01803 
01807   LeftMarginRecord();
01808   
01812   ~LeftMarginRecord();
01813   
01817   double leftMargin() const;
01818   
01822   void setLeftMargin( double m );
01823 
01824   virtual void setData( unsigned size, const unsigned char* data );
01825 
01826   virtual const char* name(){ return "LEFTMARGIN"; }
01827 
01828   virtual void dump( std::ostream& out ) const;
01829 
01830 private:
01831   // no copy or assign
01832   LeftMarginRecord( const LeftMarginRecord& );
01833   LeftMarginRecord& operator=( const LeftMarginRecord& );
01834 
01835   class Private;
01836   Private* d;
01837 };
01838 
01839 
01847 class MergedCellsRecord : public Record
01848 {
01849 public:
01850 
01851   static const unsigned int id;
01852 
01853   unsigned int rtti(){
01854       return this->id;
01855   }
01856 
01860   MergedCellsRecord();
01861 
01865   virtual ~MergedCellsRecord();
01866   
01870   unsigned count() const;
01871   
01875   unsigned firstRow( unsigned i ) const;
01876   
01880   unsigned lastRow( unsigned i ) const;
01881   
01885   unsigned firstColumn( unsigned i ) const;
01886   
01890   unsigned lastColumn( unsigned i ) const;
01891 
01892   virtual void setData( unsigned size, const unsigned char* data );
01893   
01894   virtual const char* name(){ return "MERGEDCELLS"; }
01895 
01896   virtual void dump( std::ostream& out ) const;
01897 
01898 private:
01899    // no copy or assign
01900    MergedCellsRecord( const MergedCellsRecord& );
01901    MergedCellsRecord& operator=( const MergedCellsRecord& );
01902 
01903    class Private;
01904    Private *d;
01905 };
01906 
01914 class MulBlankRecord : public Record, public CellInfo, public ColumnSpanInfo
01915 {
01916 public:
01917 
01918   static const unsigned int id;
01919 
01920   unsigned int rtti(){
01921       return this->id;
01922   }
01923 
01927   MulBlankRecord();
01928 
01932   virtual ~MulBlankRecord();
01933 
01934   virtual void setData( unsigned size, const unsigned char* data );
01935 
01939   unsigned xfIndex( unsigned i ) const;
01940 
01941   virtual const char* name(){ return "MULBLANK"; }
01942 
01943   virtual void dump( std::ostream& out ) const;
01944 
01945 private:
01946    // no copy or assign
01947    MulBlankRecord( const MulBlankRecord& );
01948    MulBlankRecord& operator=( const MulBlankRecord& );
01949 
01950    class Private;
01951    Private *d;
01952 
01953    // from CellInfo, we don't need it
01954    // mark as private so nobody can call them
01955    virtual unsigned column() const { return CellInfo::column(); }
01956    virtual unsigned xfIndex() const { return CellInfo::xfIndex(); }
01957 };
01958 
01966 class MulRKRecord : public Record, public CellInfo, public ColumnSpanInfo
01967 {
01968 public:
01969 
01970   static const unsigned int id;
01971 
01972   unsigned int rtti(){
01973       return this->id;
01974   }
01975 
01979   MulRKRecord();
01980 
01984   virtual ~MulRKRecord();
01985 
01986   virtual void setData( unsigned size, const unsigned char* data );
01987 
01991   unsigned xfIndex( unsigned i ) const;
01992   
01998   bool isInteger( unsigned i ) const;
01999   
02006   int asInteger( unsigned i ) const;
02007   
02014   double asFloat( unsigned i ) const;
02015   
02016   unsigned encodedRK( unsigned i ) const;
02017   
02018   virtual const char* name(){ return "MULRK"; }
02019 
02020   virtual void dump( std::ostream& out ) const;
02021 
02022 private:
02023    // no copy or assign
02024    MulRKRecord( const MulRKRecord& );
02025    MulRKRecord& operator=( const MulRKRecord& );
02026 
02027    class Private;
02028    Private *d;
02029 
02030    // from CellInfo, we don't need it
02031    // mark as private so nobody can call them
02032    virtual unsigned column() const { return CellInfo::column(); }
02033    virtual unsigned xfIndex() const { return CellInfo::xfIndex(); }
02034 };
02035 
02036 
02037 class NameRecord : public Record
02038 {
02039 public:
02040 
02041   static const unsigned int id;
02042 
02043   unsigned int rtti(){
02044     return this->id;
02045   }
02046 
02047   NameRecord();
02048 
02049   ~NameRecord();
02050 
02051   UString definedName() const;
02052 
02053   void setDefinedName( const UString& name );
02054 
02055   virtual void setData( unsigned size, const unsigned char* data );
02056 
02057   virtual const char* name(){ return "NAME"; }
02058 
02059   virtual void dump( std::ostream& out ) const;
02060 
02061 private:
02062    // no copy or assign
02063    NameRecord( const NameRecord& );
02064    NameRecord& operator=( const NameRecord& );
02065    
02066    class Private;
02067    Private *d;
02068 };
02069 
02070 
02075 class NumberRecord : public Record, public CellInfo
02076 {
02077 public:
02078 
02079   static const unsigned int id;
02080 
02081   unsigned int rtti(){
02082       return this->id;
02083   }
02084 
02088   NumberRecord();
02089 
02093   virtual ~NumberRecord();
02094 
02095   virtual void setData( unsigned size, const unsigned char* data );
02096   
02102   double number() const;
02103   
02109   void setNumber( double f );
02110 
02111   virtual const char* name(){ return "NUMBER"; }
02112   
02113   virtual void dump( std::ostream& out ) const;
02114 
02115 private:
02116    // no copy or assign
02117    NumberRecord( const NumberRecord& );
02118    NumberRecord& operator=( const NumberRecord& );
02119 
02120    class Private;
02121    Private *d;
02122 };
02123 
02128 class PaletteRecord : public Record
02129 {
02130 public:
02131 
02132   static const unsigned int id;
02133 
02134   unsigned int rtti(){
02135       return this->id;
02136   }
02137 
02141   PaletteRecord();
02142   
02146   ~PaletteRecord();
02147 
02151   Color color( unsigned i ) const;
02152 
02156   unsigned count() const;
02157   
02158   virtual void setData( unsigned size, const unsigned char* data );
02159 
02160   virtual const char* name(){ return "PALETTE"; }
02161 
02162   virtual void dump( std::ostream& out ) const;
02163 
02164 private:
02165   // no copy or assign
02166   PaletteRecord( const PaletteRecord& );
02167   PaletteRecord& operator=( const PaletteRecord& );
02168 
02169   class Private;
02170   Private* d;
02171 };
02172 
02173 
02174 
02179 class RightMarginRecord : public Record
02180 {
02181 public:
02182 
02183   static const unsigned int id;
02184 
02185   unsigned int rtti(){
02186       return this->id;
02187   }
02188 
02192   RightMarginRecord();
02193   
02197   ~RightMarginRecord();
02198   
02202   double rightMargin() const;
02203   
02207   void setRightMargin( double m );
02208 
02209   virtual void setData( unsigned size, const unsigned char* data );
02210 
02211   virtual const char* name(){ return "RIGHTMARGIN"; }
02212 
02213   virtual void dump( std::ostream& out ) const;
02214 
02215 private:
02216   // no copy or assign
02217   RightMarginRecord( const RightMarginRecord& );
02218   RightMarginRecord& operator=( const RightMarginRecord& );
02219 
02220   class Private;
02221   Private* d;
02222 };
02223 
02224 
02225 
02231 class RKRecord : public Record, public CellInfo
02232 {
02233 public:
02234 
02235   static const unsigned int id;
02236 
02237   unsigned int rtti(){
02238       return this->id;
02239   }
02240 
02244   RKRecord();
02245 
02249   virtual ~RKRecord();
02250 
02251   virtual void setData( unsigned size, const unsigned char* data );
02252   
02258   bool isInteger() const;
02259   
02265   bool isFloat() const;
02266     
02273   int asInteger() const;
02274   
02281   double asFloat() const;
02282   
02288   void setInteger( int i );
02289   
02295   void setFloat( double f );
02296 
02297   unsigned encodedRK() const;
02298   
02299   virtual const char* name(){ return "RK"; }
02300   
02301   virtual void dump( std::ostream& out ) const;
02302 
02303 private:
02304    // no copy or assign
02305    RKRecord( const RKRecord& );
02306    RKRecord& operator=( const RKRecord& );
02307 
02308    class Private;
02309    Private *d;
02310 };
02311 
02316 class RowRecord : public Record, public ColumnSpanInfo
02317 {
02318 public:
02319 
02320   static const unsigned int id;
02321 
02322   unsigned int rtti(){
02323       return this->id;
02324   }
02325 
02329   RowRecord();
02330 
02334   virtual ~RowRecord();
02335   
02341   unsigned row() const;
02342   
02348   void setRow( unsigned r );
02349     
02355   unsigned xfIndex() const;
02356   
02362   void setXfIndex( unsigned i );
02363   
02369   unsigned height() const;
02370   
02376   void setHeight( unsigned h );
02377   
02383   bool hidden() const;
02384   
02390   void setHidden( bool h );
02391 
02392   virtual void setData( unsigned size, const unsigned char* data );
02393 
02394   virtual const char* name(){ return "ROW"; }
02395 
02396   virtual void dump( std::ostream& out ) const;
02397 
02398 private:
02399    // no copy or assign
02400    RowRecord( const RowRecord& );
02401    RowRecord& operator=( const RowRecord& );
02402 
02403    class Private;
02404    Private *d;
02405 };
02406 
02407 
02418 class RStringRecord : public Record, public CellInfo
02419 {
02420 public:
02421 
02422   static const unsigned int id;
02423 
02424   unsigned int rtti(){
02425       return this->id;
02426   }
02427 
02431   RStringRecord();
02432 
02436   virtual ~RStringRecord();
02437 
02443   UString label() const;
02444   
02450   void setLabel( const UString& l );
02451 
02452   virtual void setData( unsigned size, const unsigned char* data );
02453 
02454   virtual const char* name(){ return "RSTRING"; }
02455   
02456   virtual void dump( std::ostream& out ) const;
02457 
02458 private:
02459    // no copy or assign
02460    RStringRecord( const RStringRecord& );
02461    RStringRecord& operator=( const RStringRecord& );
02462 
02463    class Private;
02464    Private *d;
02465 };
02466 
02467 
02475 class SSTRecord : public Record
02476 {
02477 public:
02478 
02479   static const unsigned int id;
02480   
02481   unsigned int rtti(){
02482       return this->id;
02483   }
02484 
02488   SSTRecord();
02489   
02493   virtual ~SSTRecord();
02494 
02495   virtual void setData( unsigned size, const unsigned char* data );
02496   
02500   unsigned count() const;
02501   
02507   UString stringAt( unsigned index ) const;
02508   
02509   virtual const char* name(){ return "SST"; }
02510   
02511   virtual void dump( std::ostream& out ) const;
02512   
02513 private:
02514    // no copy or assign
02515    SSTRecord( const SSTRecord& );
02516    SSTRecord& operator=( const SSTRecord& );
02517 
02518    class Private;
02519    Private *d;
02520 };
02521 
02522 
02531 class StringRecord : public Record
02532 {
02533 public:
02534 
02535   static const unsigned int id;
02536   
02537   unsigned int rtti(){ return this->id; }
02538 
02542   StringRecord();
02543   
02547   virtual ~StringRecord();
02548 
02549   virtual void setData( unsigned size, const unsigned char* data );
02550   
02554   UString ustring() const;
02555   
02559   Value value() const;
02560   
02561   virtual const char* name(){ return "STRING"; }
02562   
02563   virtual void dump( std::ostream& out ) const;
02564   
02565 private:
02566    // no copy or assign
02567    StringRecord( const SSTRecord& );
02568    StringRecord& operator=( const SSTRecord& );
02569 
02570    class Private;
02571    Private *d;
02572 };
02573 
02578 class SupbookRecord : public Record
02579 {
02580 public:
02581 
02582   static const unsigned int id;
02583 
02584   typedef enum 
02585   {
02586       UnknownRef,
02587       ExternalRef,
02588       InternalRef,
02589       AddInRef,
02590       ObjectLink
02591   } ReferenceType;
02592 
02593   unsigned int rtti(){
02594       return this->id;
02595   }
02596 
02600   SupbookRecord();
02601 
02605   ~SupbookRecord();
02606 
02610   ReferenceType referenceType() const;
02611 
02615   void setReferenceType(ReferenceType type);
02616 
02617   virtual void setData( unsigned size, const unsigned char* data );
02618 
02619   virtual const char* name(){ return "SUPBOOK"; }
02620 
02621   virtual void dump( std::ostream& out ) const;
02622 
02623 private:
02624   // no copy or assign
02625   SupbookRecord( const SupbookRecord& );
02626   SupbookRecord& operator=( const SupbookRecord& );
02627 
02628   class Private;
02629   Private* d;
02630 };
02631 
02636 class TopMarginRecord : public Record
02637 {
02638 public:
02639 
02640   static const unsigned int id;
02641 
02642   unsigned int rtti(){
02643       return this->id;
02644   }
02645 
02649   TopMarginRecord();
02650   
02654   ~TopMarginRecord();
02655   
02659   double topMargin() const;
02660   
02664   void setTopMargin( double m );
02665 
02666   virtual void setData( unsigned size, const unsigned char* data );
02667 
02668   virtual const char* name(){ return "TOPMARGIN"; }
02669 
02670   virtual void dump( std::ostream& out ) const;
02671 
02672 private:
02673   // no copy or assign
02674   TopMarginRecord( const TopMarginRecord& );
02675   TopMarginRecord& operator=( const TopMarginRecord& );
02676 
02677   class Private;
02678   Private* d;
02679 };
02680 
02687 class XFRecord : public Record
02688 {
02689 public:
02690 
02691   static const unsigned int id;
02692 
02693   unsigned int rtti(){
02694       return this->id;
02695   }
02696 
02700   XFRecord();
02701   
02705   XFRecord( const XFRecord& xf );
02706   
02710   XFRecord& operator=( const XFRecord& xf );
02711   
02715   ~XFRecord();
02716   
02723   unsigned fontIndex() const;
02724   
02731   void setFontIndex( unsigned fi );
02732 
02739   unsigned formatIndex() const;
02740   
02747   void setFormatIndex( unsigned fi );
02748   
02754   bool locked() const;
02755   
02761   void setLocked( bool l );
02762   
02769   bool formulaHidden() const;
02770 
02777   void setFormulaHidden( bool f );
02778   
02786   unsigned parentStyle() const;
02787   
02795   void setParentStyle( unsigned ps );
02796 
02797   enum { 
02798     General = 0, 
02799     Left, 
02800     Centered, 
02801     Right, 
02802     Filled, 
02803     Justified,
02804     CenteredSelection,
02805     Distributed };
02806   
02810   unsigned horizontalAlignment() const;
02811   
02815   void setHorizontalAlignment( unsigned ha );
02816   
02821   const char* horizontalAlignmentAsString() const; 
02822   
02823   enum { 
02824     Top = 0, 
02825     VCentered = 1, 
02826     Bottom = 2, 
02827     VJustified = 3, 
02828     VDistributed = 4 };
02829   
02835   unsigned verticalAlignment() const;
02836   
02842   void setVerticalAlignment( unsigned va );
02843   
02848   const char* verticalAlignmentAsString() const; 
02849   
02855   bool textWrap() const;
02856   
02862   void setTextWrap( bool wrap );
02863   
02871   unsigned rotationAngle() const;
02872   
02880   void setRotationAngle( unsigned angle );
02881   
02888   bool stackedLetters() const;
02889   
02895   void setStackedLetters( bool stacked );
02896 
02902   unsigned indentLevel() const;
02903   
02909   void setIndentLevel( unsigned i );
02910   
02916   bool shrinkContent() const;
02917   
02923   void setShrinkContent( bool s );
02924   
02925   enum
02926   {
02927     NoLine = 0,
02928     Thin = 1,
02929     Medium = 2,
02930     Dashed = 3,
02931     Dotted = 4,
02932     Thick = 5,
02933     Double = 6,
02934     Hair = 7,
02935     MediumDashed = 8,
02936     ThinDashDotted = 9,
02937     MediumDashDotted = 10,
02938     ThinDashDotDotted = 11,
02939     MediumDashDotDotted = 12,
02940     SlantedMediumDashDotted = 13    
02941   };
02942   
02948   unsigned leftBorderStyle() const;
02949   
02955   void setLeftBorderStyle( unsigned style );
02956   
02963   unsigned leftBorderColor() const;
02964   
02971   void setLeftBorderColor( unsigned color );
02972 
02978   unsigned rightBorderStyle() const;
02979   
02985   void setRightBorderStyle( unsigned style );
02986   
02993   unsigned rightBorderColor() const;
02994   
03001   void setRightBorderColor( unsigned color );
03002   
03008   unsigned topBorderStyle() const;
03009   
03015   void setTopBorderStyle( unsigned style );
03016   
03023   unsigned topBorderColor() const;
03024   
03031   void setTopBorderColor( unsigned color );
03032   
03038   unsigned bottomBorderStyle() const;
03039   
03045   void setBottomBorderStyle( unsigned style );
03046   
03053   unsigned bottomBorderColor() const;
03054   
03061   void setBottomBorderColor( unsigned color );
03062   
03068   bool diagonalTopLeft() const;
03069   
03075   void setDiagonalTopLeft( bool d );
03076   
03082   bool diagonalBottomLeft() const;
03083   
03089   void setDiagonalBottomLeft( bool d );
03090   
03096   unsigned diagonalStyle() const;
03097   
03103   void setDiagonalStyle( unsigned style );
03104   
03111   unsigned diagonalColor() const;
03112   
03119   void setDiagonalColor( unsigned color );
03120   
03126   unsigned fillPattern() const;
03127   
03133   void setFillPattern( unsigned pattern );
03134   
03141   unsigned patternForeColor() const;
03142   
03149   void setPatternForeColor( unsigned color );
03150   
03157   unsigned patternBackColor() const;    
03158   
03165   void setPatternBackColor( unsigned color );
03166   
03167   virtual const char* name(){ return "XF"; }
03168   
03169   virtual void setData( unsigned size, const unsigned char* data );
03170   
03171   virtual void dump( std::ostream& out ) const;
03172 
03173 private:
03174   class Private;
03175   Private* d;
03176 };
03177 
03178 typedef std::vector<UString> UStringStack;
03179 
03180 
03181 class ExcelReader
03182 {
03183 public:
03184   ExcelReader();
03185   virtual ~ExcelReader();
03186   bool load( Workbook* workbook, const char* filename );
03187   
03188 protected:  
03189   virtual void handleRecord( Record* record );
03190     
03191 private:  
03192   void handleBoundSheet( BoundSheetRecord* record );
03193   void handleBOF( BOFRecord* record );
03194   void handleBoolErr( BoolErrRecord* record );
03195   void handleBottomMargin( BottomMarginRecord* record );
03196   void handleBlank( BlankRecord* record );
03197   void handleCalcMode( CalcModeRecord* record );
03198   void handleColInfo( ColInfoRecord* record );
03199   void handleDateMode( DateModeRecord* record );
03200   void handleDimension( DimensionRecord* record );
03201   void handleExternName( ExternNameRecord* record );
03202   void handleExternSheet( ExternSheetRecord* record );
03203   void handleFilepass( FilepassRecord* record );
03204   void handleFormat( FormatRecord* record );
03205   void handleFormula( FormulaRecord* record );
03206   void handleFont( FontRecord* record );
03207   void handleFooter( FooterRecord* record );
03208   void handleHeader( HeaderRecord* record );
03209   void handleLabel( LabelRecord* record );
03210   void handleLabelSST( LabelSSTRecord* record );
03211   void handleLeftMargin( LeftMarginRecord* record );
03212   void handleMergedCells( MergedCellsRecord* record );
03213   void handleMulBlank( MulBlankRecord* record );
03214   void handleMulRK( MulRKRecord* record );
03215   void handleName( NameRecord* record );
03216   void handleNumber( NumberRecord* record );
03217   void handlePalette( PaletteRecord* record );
03218   void handleRightMargin( RightMarginRecord* record );
03219   void handleRString( RStringRecord* record );
03220   void handleRK( RKRecord* record );
03221   void handleRow( RowRecord* record );
03222   void handleSST( SSTRecord* record );
03223   void handleString( StringRecord* record );
03224   void handleSupbook( SupbookRecord* record );
03225   void handleTopMargin( TopMarginRecord* record );
03226   void handleXF( XFRecord* record );    
03227   
03228   Color convertColor( unsigned colorIndex );
03229   FormatFont convertFont( unsigned fontIndex );
03230   Format convertFormat( unsigned xfIndex );
03231   UString decodeFormula( unsigned row, unsigned col, 
03232     const FormulaTokens& tokens, bool openDocumentFormat=false );
03233   
03234   void mergeTokens( UStringStack* stack, int count, char mergeChar );
03235   void mergeTokens( UStringStack* stack, int count, const char* mergeString );
03236   
03237   // no copy or assign
03238   ExcelReader( const ExcelReader& );
03239   ExcelReader& operator=( const ExcelReader& );
03240   
03241   class Private;
03242   Private* d;
03243 };
03244 
03245 
03246 } // namespace Swinder
03247 
03248 
03249 
03250 #endif // SWINDER_EXCEL_H
KDE Home | KDE Accessibility Home | Description of Access Keys