filters

workbook.cpp

00001 /* Swinder - Portable library for spreadsheet 
00002    Copyright (C) 2003 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 #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   // FIXME use iterator
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys