25#include <kspread_map.h>
27#include "kwmailmerge_kspread.h"
28#include "kwmailmerge_kspread_config.h"
30using namespace KSpread;
32KWMailMergeKSpread::KWMailMergeKSpread( TDEInstance *instance, TQObject *parent )
33 : KWMailMergeDataSource( instance, parent ), _spreadSheetNumber( 1 )
37KWMailMergeKSpread::~KWMailMergeKSpread()
41int KWMailMergeKSpread::getNumRecords()
const
46TQString KWMailMergeKSpread::getValue(
const TQString &name,
int record )
const
51 const Cell* cell = _sheet->cellAt( _columnMap[ name ], record + 2 );
54 return cellText( cell );
56 return i18n(
"Unkown mail merge variable: %1" ).arg( name );
59void KWMailMergeKSpread::load( TQDomElement& parentElem )
61 TQDomNode contentNode = parentElem.namedItem(
"CONTENT" );
62 if ( contentNode.isNull() )
65 TQDomElement element = contentNode.toElement();
66 if ( element.isNull() )
69 _url = element.attribute( TQString::fromLatin1(
"URL" ) );
70 _spreadSheetNumber = element.attribute( TQString::fromLatin1(
"SpreadSheetNumber" ) ).toInt();
75void KWMailMergeKSpread::save( TQDomDocument& doc, TQDomElement& parent )
77 TQDomElement content = doc.createElement( TQString::fromLatin1(
"CONTENT" ) );
78 parent.appendChild( content );
80 content.setAttribute(
"URL", _url.url() );
81 content.setAttribute(
"SpreadSheetNumber", _spreadSheetNumber );
84void KWMailMergeKSpread::refresh(
bool )
88bool KWMailMergeKSpread::showConfigDialog( TQWidget *parent,
int )
90 KWMailMergeKSpreadConfig dlg( parent,
this );
92 int retval = dlg.exec();
99void KWMailMergeKSpread::initDocument()
101 _document =
new Doc();
103 connect( _document, TQ_SIGNAL( completed() ), TQ_SLOT( initSpreadSheets() ) );
105 _document->openURL( _url );
108void KWMailMergeKSpread::initSpreadSheets()
112 sampleRecord.clear();
114 TQPtrListIterator<Sheet> it( _document->map()->sheetList() );
116 for ( it.toFirst(); it.current(), counter < _spreadSheetNumber; ++it ) {
117 _sheet = it.current();
122 kdError() <<
"No spread sheet available" << endl;
129 int cols = columns();
130 for (
int i = 1; i < cols; ++i ) {
131 const Cell* cell = _sheet->cellAt( i, 1 );
134 sampleRecord[ cellText( cell ) ] = cellText( cell );
135 _columnMap.insert( cellText( cell ), i );
139int KWMailMergeKSpread::rows()
const
146 for (; row < _sheet->maxRow(); ) {
147 const Cell* cell = _sheet->cellAt( 1, row );
148 if ( cellText( cell ).isEmpty() )
157int KWMailMergeKSpread::columns()
const
164 for (; col < _sheet->maxColumn(); ) {
165 const Cell* cell = _sheet->cellAt( col, 1 );
166 if ( cellText( cell ).isEmpty() )
175TQString KWMailMergeKSpread::cellText(
const Cell *cell )
const
177 TQString text = TQString();
179 if ( !cell->isDefault() && !cell->isEmpty() ) {
180 if ( cell->isFormula() )
181 text = cell->strOutText();
182 else if ( !cell->link().isEmpty() )
188 switch( cell->content() ) {
191 text = cell->strOutText();
194 case Cell::VisualFormula:
205 KWORD_MAILMERGE_EXPORT KWMailMergeDataSource *create_kwmailmerge_kspread( TDEInstance *instance, TQObject *parent )
207 return new KWMailMergeKSpread( instance, parent );
211#include "kwmailmerge_kspread.moc"