filters
workbook.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "workbook.h"
00021 #include "sheet.h"
00022 #include "excel.h"
00023 #include "format.h"
00024
00025 #include <iostream>
00026 #include <vector>
00027 #include <map>
00028
00029 using namespace Swinder;
00030
00031 class Workbook::Private
00032 {
00033 public:
00034 std::vector<Sheet*> sheets;
00035 bool autoCalc;
00036 bool passwordProtected;
00037 std::map<int,Format> formats;
00038 int maxFormatIndex;
00039 };
00040
00041 Workbook::Workbook()
00042 {
00043 d = new Workbook::Private();
00044 d->autoCalc = true;
00045 d->passwordProtected = false;
00046 d->maxFormatIndex = 0;
00047 }
00048
00049 Workbook::~Workbook()
00050 {
00051 clear();
00052 delete d;
00053 }
00054
00055 void Workbook::clear()
00056 {
00057
00058 for( unsigned i=0; i<sheetCount(); i++ )
00059 {
00060 Sheet* s = sheet( i );
00061 delete s;
00062 }
00063 d->sheets.clear();
00064 }
00065
00066 bool Workbook::load( const char* filename )
00067 {
00068 ExcelReader* reader = new ExcelReader;
00069 bool result = reader->load( this, filename );
00070 delete reader;
00071 return result;
00072 }
00073
00074 void Workbook::appendSheet( Sheet* sheet )
00075 {
00076 d->sheets.push_back( sheet );
00077 }
00078
00079 unsigned Workbook::sheetCount() const
00080 {
00081 return d->sheets.size();
00082 }
00083
00084 Sheet* Workbook::sheet( unsigned index )
00085 {
00086 if( index >= sheetCount() ) return (Sheet*)0;
00087 return d->sheets[index];
00088 }
00089
00090 int Workbook::indexOf( Sheet *s )
00091 {
00092 if( s )
00093 for( unsigned i = 0; i < sheetCount(); i++ )
00094 if( d->sheets[i] == s )
00095 return i;
00096
00097 return -1;
00098 }
00099
00100 bool Workbook::autoCalc() const
00101 {
00102 return d->autoCalc;
00103 }
00104
00105 void Workbook::setAutoCalc( bool a )
00106 {
00107 d->autoCalc = a;
00108 }
00109
00110 void Workbook::setFormat( int index, const Format& format )
00111 {
00112 d->formats[index] = format;
00113 if (index > d->maxFormatIndex)
00114 d->maxFormatIndex = index;
00115 }
00116
00117 const Format& Workbook::format( int index ) const
00118 {
00119 return d->formats[index];
00120 }
00121
00122 const int Workbook::maxFormatIndex() const
00123 {
00124 return d->maxFormatIndex;
00125 }
00126
00127 bool Workbook::isPasswordProtected() const
00128 {
00129 return d->passwordProtected;
00130 }
00131
00132 void Workbook::setPasswordProtected( bool p )
00133 {
00134 d->passwordProtected = p;
00135 }
|