74
OpenCalcExport::OpenCalcExport( KoFilter *, const char *, const QStringList & )
79
OpenCalcExport::OpenCalcExport( KoFilter *, const char *, const QStringList & )
80
: KoFilter(), m_locale( 0 )
79
KoFilter::ConversionStatus OpenCalcExport::convert( const QCString & from,
84
KoFilter::ConversionStatus OpenCalcExport::convert( const QCString & from,
80
85
const QCString & to )
83
88
KSpreadLeader * leader = new KSpreadLeader( m_chain );
84
89
OpenCalcWorker * worker = new OpenCalcWorker();
85
90
leader->setWorker( worker );
87
92
KoFilter::ConversionStatus status = leader->convert();
191
202
data = meta.createElement( "meta:initial-creator" );
192
203
data.appendChild( meta.createTextNode( authorPage->fullName() ) );
193
204
officeMeta.appendChild( data );
195
206
data = meta.createElement( "meta:creator" );
196
207
data.appendChild( meta.createTextNode( authorPage->fullName() ) );
197
208
officeMeta.appendChild( data );
199
data = meta.createElement( "meta:user-defined" );
200
data.setAttribute( "meta:name", "Info 1" );
210
data = meta.createElement( "dc:description" );
211
data.appendChild( meta.createTextNode( aboutPage->abstract() ) );
212
officeMeta.appendChild( data );
214
data = meta.createElement( "meta:keywords" );
215
QDomElement dataItem = meta.createElement( "meta:keyword" );
216
dataItem.appendChild( meta.createTextNode( aboutPage->keywords() ) );
217
data.appendChild( dataItem );
218
officeMeta.appendChild( data );
220
data = meta.createElement( "dc:title" );
201
221
data.appendChild( meta.createTextNode( aboutPage->title() ) );
202
222
officeMeta.appendChild( data );
204
data = meta.createElement( "meta:user-defined" );
205
data.setAttribute( "meta:name", "Info 2" );
206
data.appendChild( meta.createTextNode( aboutPage->abstract() ) );
224
data = meta.createElement( "dc:subject" );
225
data.appendChild( meta.createTextNode( aboutPage->subject() ) );
207
226
officeMeta.appendChild( data );
228
const QDateTime dt ( QDateTime::currentDateTime() );
231
data = meta.createElement( "dc:date" );
232
data.appendChild( meta.createTextNode( dt.toString( Qt::ISODate ) ) );
233
officeMeta.appendChild( data );
210
237
<meta:creation-date>2003-01-08T23:57:31</meta:creation-date>
211
<dc:date>2003-01-08T23:58:05</dc:date>
212
238
<dc:language>en-US</dc:language>
213
239
<meta:editing-cycles>2</meta:editing-cycles>
214
240
<meta:editing-duration>PT38S</meta:editing-duration>
238
bool OpenCalcExport::exportContent( KoStore * store, KSpreadDoc const * const ksdoc )
264
bool OpenCalcExport::exportSettings( KoStore * store, const KSpreadDoc * ksdoc )
266
if ( !store->open( "settings.xml" ) )
270
doc.appendChild( doc.createProcessingInstruction( "xml","version=\"1.0\" encoding=\"UTF-8\"" ) );
272
QDomElement settings = doc.createElement( "office:document-settings" );
273
settings.setAttribute( "xmlns:office", "http://openoffice.org/2000/office");
274
settings.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
275
settings.setAttribute( "xmlns:config", "http://openoffice.org/2001/config" );
276
settings.setAttribute( "office:version", "1.0" );
278
QDomElement begin = doc.createElement( "office:settings" );
280
QDomElement configItem = doc.createElement("config:config-item-set" );
281
configItem.setAttribute( "config:name", "view-settings" );
283
QDomElement mapIndexed = doc.createElement( "config:config-item-map-indexed" );
284
mapIndexed.setAttribute("config:name", "Views" );
285
configItem.appendChild( mapIndexed );
287
QDomElement mapItem = doc.createElement("config:config-item-map-entry" );
289
QDomElement attribute = doc.createElement("config:config-item" );
290
attribute.setAttribute( "config:name", "ActiveTable" );
291
attribute.setAttribute( "config:type", "string" );
293
KSpreadView * view = static_cast<KSpreadView*>( ksdoc->views().getFirst());
295
if ( view ) // no view if embedded document
297
KSpreadCanvas * canvas = view->canvasWidget();
298
activeTable = canvas->activeSheet()->sheetName();
299
// save current sheet selection before to save marker, otherwise current pos is not saved
300
view->saveCurrentSheetSelection();
302
attribute.appendChild( doc.createTextNode( activeTable ) );
303
mapItem.appendChild( attribute );
305
QDomElement configmaped = doc.createElement( "config:config-item-map-named" );
306
configmaped.setAttribute( "config:name","Tables" );
308
QPtrListIterator<KSpreadSheet> it( ksdoc->map()->sheetList() );
309
for( ; it.current(); ++it )
314
marker = view->markerFromSheet( *it );
316
QDomElement tmpItemMapNamed = doc.createElement( "config:config-item-map-entry" );
317
tmpItemMapNamed.setAttribute( "config:name", ( *it )->tableName() );
319
QDomElement sheetAttribute = doc.createElement( "config:config-item" );
320
sheetAttribute.setAttribute( "config:name", "CursorPositionX" );
321
sheetAttribute.setAttribute( "config:type", "int" );
322
sheetAttribute.appendChild( doc.createTextNode( QString::number(marker.x() ) ) );
323
tmpItemMapNamed.appendChild( sheetAttribute );
325
sheetAttribute = doc.createElement( "config:config-item" );
326
sheetAttribute.setAttribute( "config:name", "CursorPositionY" );
327
sheetAttribute.setAttribute( "config:type", "int" );
328
sheetAttribute.appendChild( doc.createTextNode( QString::number(marker.y() ) ) );
329
tmpItemMapNamed.appendChild( sheetAttribute );
331
configmaped.appendChild( tmpItemMapNamed );
333
mapItem.appendChild( configmaped );
337
mapIndexed.appendChild( mapItem );
339
begin.appendChild( configItem );
341
settings.appendChild( begin );
343
doc.appendChild( settings );
345
QCString f( doc.toCString() );
346
kdDebug(30518) << "Settings: " << (char const * ) f << endl;
348
store->write( f, f.length() );
350
if ( !store->close() )
356
bool OpenCalcExport::exportContent( KoStore * store, const KSpreadDoc * ksdoc )
240
358
if ( !store->open( "content.xml" ) )
307
432
QString s( "$" );
310
s += util_encodeColumnLabelText( topLeft.x() );
435
s += /*util_encodeColumnLabelText*/KSpreadCell::columnName( topLeft.x() );
312
437
s += QString::number( topLeft.y() );
314
s += util_encodeColumnLabelText( bottomRight.x() );
439
s += /*util_encodeColumnLabelText*/KSpreadCell::columnName( bottomRight.x() );
316
441
s += QString::number( bottomRight.y() );
321
void exportNamedExpr( QDomDocument & doc, QDomElement & parent,
446
void exportNamedExpr( QDomDocument & doc, QDomElement & parent,
322
447
AreaList const & namedAreas )
324
449
AreaList::const_iterator it = namedAreas.begin();
331
456
Reference ref = *it;
333
458
namedRange.setAttribute( "table:name", ref.ref_name );
334
namedRange.setAttribute( "table:base-cell-address", convertRefToBase( ref.table_name, ref.rect ) );
335
namedRange.setAttribute( "table:cell-range-address", convertRefToRange( ref.table_name, ref.rect ) );
459
namedRange.setAttribute( "table:base-cell-address", convertRefToBase( ref.sheet_name, ref.rect ) );
460
namedRange.setAttribute( "table:cell-range-address", convertRefToRange( ref.sheet_name, ref.rect ) );
337
462
parent.appendChild( namedRange );
349
474
if ( ksdoc->map()->isProtected() )
351
476
body.setAttribute( "table:structure-protected", "true" );
354
479
ksdoc->map()->password( passwd );
355
480
if ( passwd.length() > 0 )
357
482
QCString str( KCodecs::base64Encode( passwd ) );
358
body.setAttribute( "table:protection-key", QString( str.data() ) );
483
body.setAttribute( "table:protection-key", QString( str.data() ) );
362
QPtrListIterator<KSpreadSheet> it( ksdoc->map()->tableList() );
489
QPtrListIterator<KSpreadSheet> it( ksdoc->map()->sheetList() );
364
491
for( it.toFirst(); it.current(); ++it )
398
525
name = name.replace( ' ', "_" );
527
QRect _printRange = sheet->print()->printRange();
528
if ( _printRange != ( QRect( QPoint( 1, 1 ), QPoint( KS_colMax, KS_rowMax ) ) ) )
530
QString range= convertRangeToRef( name, _printRange );
531
//kdDebug(30518)<<" range : "<<range<<endl;
532
tabElem.setAttribute( "table:print-ranges", range );
400
536
tabElem.setAttribute( "table:name", name );
402
538
maxRowCols( sheet, maxCols, maxRows );
404
540
exportSheet( doc, tabElem, sheet, maxCols, maxRows );
406
542
body.appendChild( tabElem );
409
545
KoDocument * document = m_chain->inputDocument();
410
546
KSpreadDoc * kspreadDoc = static_cast<KSpreadDoc *>( document );
412
548
AreaList namedAreas = kspreadDoc->listArea();
413
549
if ( namedAreas.count() > 0 )
415
551
QDomElement namedExpr = doc.createElement( "table:named-expressions" );
416
552
exportNamedExpr( doc, namedExpr, namedAreas );
418
554
body.appendChild( namedExpr );
431
void OpenCalcExport::exportSheet( QDomDocument & doc, QDomElement & tabElem,
432
KSpreadSheet const * const sheet, int maxCols, int maxRows )
567
void OpenCalcExport::exportSheet( QDomDocument & doc, QDomElement & tabElem,
568
const KSpreadSheet * sheet, int maxCols, int maxRows )
434
570
kdDebug(30518) << "exportSheet: " << sheet->tableName() << endl;
437
573
while ( i <= maxCols )
439
ColumnFormat const * const column = sheet->columnFormat( i );
575
const ColumnFormat * column = sheet->columnFormat( i );
441
577
cs.breakB = Style::automatic;
442
578
cs.size = column->mmWidth() / 10;
492
void OpenCalcExport::exportCells( QDomDocument & doc, QDomElement & rowElem,
493
KSpreadSheet const * const sheet, int row, int maxCols )
628
void OpenCalcExport::exportCells( QDomDocument & doc, QDomElement & rowElem,
629
const KSpreadSheet *sheet, int row, int maxCols )
496
632
while ( i <= maxCols )
498
634
int repeated = 1;
499
635
bool hasComment = false;
500
KSpreadCell const * const cell = sheet->cellAt( i, row );
636
const KSpreadCell* cell = sheet->cellAt( i, row );
501
637
QDomElement cellElem;
503
639
if ( !cell->isObscuringForced() )
520
CellStyle::loadData( c, cell ); // TODO: number style
656
CellStyle::loadData( c, cell ); // TODO: number style
522
658
cellElem.setAttribute( "table:style-name", m_styles.cellStyle( c ) );
524
660
// group empty cells with the same style
525
if ( cell->isEmpty() && !hasComment && !cell->isObscuringForced() && !cell->isForceExtraCells() )
661
if ( cell->isEmpty() && !hasComment && !cell->isObscuringForced() && !cell->isForceExtraCells() )
528
664
while ( j <= maxCols )
530
KSpreadCell const * const cell1 = sheet->cellAt( j, row );
666
const KSpreadCell *cell1 = sheet->cellAt( j, row );
533
669
CellStyle::loadData( c1, cell1 ); // TODO: number style
535
if ( cell1->isEmpty() && !cell->hasProperty( KSpreadFormat::PComment )
671
if ( cell1->isEmpty() && !cell->hasProperty( KSpreadFormat::PComment )
536
672
&& CellStyle::isEqual( &c, c1 ) && !cell->isObscuringForced() && !cell->isForceExtraCells() )
552
688
else if ( value.isNumber() )
554
690
kdDebug(30518) << "Type: Number" << endl;
555
KSpreadFormat::FormatType type = cell->getFormatType( i, row );
691
FormatType type = cell->getFormatType( i, row );
557
if ( type == KSpreadFormat::Percentage )
693
if ( type == Percentage_format )
558
694
cellElem.setAttribute( "table:value-type", "percentage" );
560
696
cellElem.setAttribute( "table:value-type", "float" );
562
698
cellElem.setAttribute( "table:value", QString::number( value.asFloat() ) );
566
702
kdDebug(30518) << "Type: " << value.type() << endl;
573
709
QString formula( convertFormula( cell->text() ) );
574
710
cellElem.setAttribute( "table:formula", formula );
712
else if ( !cell->link().isEmpty() )
714
QDomElement link = doc.createElement( "text:p" );
715
QDomElement linkref = doc.createElement( "text:a" );
717
QString tmp = cell->link();
718
if ( localReferenceAnchor( tmp ) )
719
linkref.setAttribute( "xlink:href", ( "#"+tmp ) );
721
linkref.setAttribute( "xlink:href", tmp );
723
linkref.appendChild( doc.createTextNode( cell->text() ) );
725
link.appendChild( linkref );
726
cellElem.appendChild( link );
728
else if ( !cell->isEmpty() )
730
QDomElement textElem = doc.createElement( "text:p" );
731
textElem.appendChild( doc.createTextNode( cell->strOutText() ) );
733
cellElem.appendChild( textElem );
734
kdDebug(30518) << "Cell StrOut: " << cell->strOutText() << endl;
577
737
if ( cell->isForceExtraCells() )
579
739
int colSpan = cell->mergedXCells() + 1;
597
757
cellElem.appendChild( annotation );
600
if ( !cell->isEmpty() )
602
QDomElement textElem = doc.createElement( "text:p" );
603
textElem.appendChild( doc.createTextNode( cell->strOutText() ) );
605
cellElem.appendChild( textElem );
606
kdDebug(30518) << "Cell StrOut: " << cell->strOutText() << endl;
609
760
rowElem.appendChild( cellElem );
615
void OpenCalcExport::maxRowCols( KSpreadSheet const * const sheet,
766
void OpenCalcExport::maxRowCols( const KSpreadSheet *sheet,
616
767
int & maxCols, int & maxRows )
618
769
KSpreadCell const * cell = sheet->firstCell();
678
829
QDomElement officeStyles = doc.createElement( "office:styles" );
679
830
exportDefaultCellStyle( doc, officeStyles );
681
QDomElement fontDecls = doc.createElement( "office:font-decls" );
832
QDomElement fontDecls = doc.createElement( "office:font-decls" );
682
833
m_styles.writeFontDecl( doc, fontDecls );
684
835
// TODO: needs in new number/date/time parser...
685
836
// exportDefaultNumberStyles( doc, officeStyles );
687
838
QDomElement defaultStyle = doc.createElement( "style:style" );
688
839
defaultStyle.setAttribute( "style:name", "Default" );
689
840
defaultStyle.setAttribute( "style:family", "table-cell" );
813
964
void OpenCalcExport::exportMasterStyles( QDomDocument & doc, QDomElement & masterStyles,
814
KSpreadDoc const * const ksdoc )
965
const KSpreadDoc * ksdoc )
816
967
QDomElement masterPage = doc.createElement( "style:master-page" );
817
968
masterPage.setAttribute( "style:name", "Default" );
818
969
masterPage.setAttribute( "style:page-master-name", "pm1" );
820
QPtrListIterator<KSpreadSheet> it( ksdoc->map()->tableList() );
821
KSpreadSheet const * const sheet = it.toFirst();
971
QPtrListIterator<KSpreadSheet> it( ksdoc->map()->sheetList() );
972
const KSpreadSheet * sheet = it.toFirst();
823
974
QString headerLeft;
824
975
QString headerCenter;
912
1063
masterPage.appendChild( footer );
915
masterStyles.appendChild( masterPage );
1066
masterStyles.appendChild( masterPage );
918
void OpenCalcExport::addText( QString const & text, QDomDocument & doc,
1069
void OpenCalcExport::addText( QString const & text, QDomDocument & doc,
919
1070
QDomElement & parent )
921
1072
if (text.length() > 0 )
922
1073
parent.appendChild( doc.createTextNode( text ) );
925
void OpenCalcExport::convertPart( QString const & part, QDomDocument & doc,
926
QDomElement & parent, KSpreadDoc const * const ksdoc )
1076
void OpenCalcExport::convertPart( QString const & part, QDomDocument & doc,
1077
QDomElement & parent, const KSpreadDoc * ksdoc )
1068
1224
QString OpenCalcExport::convertFormula( QString const & formula ) const
1226
QChar decimalSymbol( '.' );
1229
const QString decimal ( m_locale->decimalSymbol() );
1230
if ( !decimal.isEmpty() )
1232
decimalSymbol = decimal.at( 0 );
1071
1237
QRegExp exp("(\\$?)([a-zA-Z]+)(\\$?)([0-9]+)");
1072
1238
int n = exp.search( formula, 0 );
1073
kdDebug(30518) << "Exp: " << formula << ", n: " << n << ", Length: " << formula.length()
1239
kdDebug(30518) << "Exp: " << formula << ", n: " << n << ", Length: " << formula.length()
1074
1240
<< ", Matched length: " << exp.matchedLength() << endl;
1076
bool inQuote1 = false;
1077
bool inQuote2 = false;
1242
bool inQuote1 = false;
1243
bool inQuote2 = false;
1079
1245
int l = (int) formula.length();