30#include "opencalcimport.h"
33#include <KoDocumentInfo.h>
34#include <kgenericfactory.h>
35#include <tdemessagebox.h>
37#include <KoFilterChain.h>
40#include <KoStyleStack.h>
44#include <kspread_cell.h>
45#include <kspread_condition.h>
46#include <kspread_doc.h>
47#include <kspread_global.h>
48#include <kspread_map.h>
49#include <kspread_sheet.h>
50#include <kspread_sheetprint.h>
51#include <kspread_style.h>
52#include <kspread_style_manager.h>
53#include <kspread_util.h>
54#include <kspread_value.h>
56#define SECSPERDAY (24 * 60 * 60)
58using namespace KSpread;
60class OpenCalcImportFactory : KGenericFactory<OpenCalcImport, KoFilter>
63 OpenCalcImportFactory(
void) : KGenericFactory<OpenCalcImport, KoFilter> (
"kspreadopencalcimport")
66 virtual void setupTranslations(
void )
68 TDEGlobal::locale()->insertCatalogue(
"kofficefilters" );
72K_EXPORT_COMPONENT_FACTORY( libopencalcimport, OpenCalcImportFactory() )
74OpenCalcImport::OpenCalcPoint::OpenCalcPoint( TQString const & str )
84 for (
int i = 0; i < l; ++i )
92 else if ( str[i] ==
'.' )
96 if ( i != 0 && i != (colonPos + 1) )
102 else if ( str[i] ==
':' )
119 KSpread::Range newRange( range );
120 table = newRange.sheetName();
121 topLeft = newRange.range().topLeft();
122 botRight = newRange.range().bottomRight();
126 Point newPoint( range );
127 table = newPoint.sheetName();
128 topLeft = newPoint.pos();
129 botRight = newPoint.pos();
134OpenCalcImport::OpenCalcImport( KoFilter *,
const char *,
const TQStringList & )
136 m_styles( 17, true ),
137 m_defaultStyles( 17, true ),
138 m_formats( 17, true )
140 m_styles.setAutoDelete(
true );
141 m_defaultStyles.setAutoDelete(
true );
142 m_formats.setAutoDelete(
true );
145OpenCalcImport::~OpenCalcImport()
149double timeToNum(
int h,
int m,
int s )
151 int secs = h * 3600 + m * 60 + s;
152 return (
double) secs / (double) SECSPERDAY;
155bool OpenCalcImport::readRowFormat( TQDomElement & rowNode, TQDomElement * rowStyle,
156 Sheet * table,
int & row,
int & number,
159 if ( rowNode.isNull() )
165 node = rowStyle->firstChild();
166 kdDebug(30518) <<
"RowStyle: " << rowStyle <<
", " << rowStyle->tagName() << endl;
169 double height = -1.0;
170 bool insertPageBreak =
false;
171 Format layout( table, table->doc()->styleManager()->defaultStyle() );
173 while( !node.isNull() )
175 TQDomElement
property = node.toElement();
177 kdDebug(30518) <<
"Row: Child exists: " <<
property.tagName() << endl;
178 if ( !property.isNull() && property.localName() ==
"properties" && property.namespaceURI() == ooNS::style )
180 if ( property.hasAttributeNS( ooNS::style,
"row-height" ) )
182 height = KoUnit::parseValue( property.attributeNS( ooNS::style,
"row-height", TQString() ) , -1 );
185 if ( property.hasAttributeNS( ooNS::fo,
"break-before" ) )
187 if ( property.attributeNS( ooNS::fo,
"break-before", TQString() ) ==
"page" )
189 insertPageBreak =
true;
193 loadStyleProperties( &layout, property );
196 node = node.nextSibling();
199 if ( rowNode.hasAttributeNS( ooNS::table,
"number-rows-repeated" ) )
202 int n = rowNode.attributeNS( ooNS::table,
"number-rows-repeated", TQString() ).toInt( &ok );
205 kdDebug(30518) <<
"Row repeated: " << number << endl;
219 for (
int i = 0; i < number; ++i )
221 RowFormat * rowL = table->nonDefaultRowFormat( row );
222 rowL->copy( layout );
226 kdDebug(30518) <<
"Setting row height to " << height << endl;
227 rowL->setHeight(
int( height ) );
240TQString OpenCalcImport::translatePar( TQString & par )
const
242 OpenCalcPoint point( par );
243 kdDebug(30518) <<
" Parameter: " << par <<
", Translation: " << point.translation << endl;
245 return point.translation;
248void OpenCalcImport::checkForNamedAreas( TQString & formula )
const
250 int l = formula.length();
256 if ( formula[i].isLetterOrNumber() )
262 if ( word.length() > 0 )
264 if ( m_namedAreas.find( word ) != m_namedAreas.end() )
266 formula = formula.replace( start, word.length(),
"'" + word +
"'" );
267 l = formula.length();
269 kdDebug(30518) <<
"Formula: " << formula <<
", L: " << l <<
", i: " << i + 1 <<endl;
277 if ( word.length() > 0 )
279 if ( m_namedAreas.find( word ) != m_namedAreas.end() )
281 formula = formula.replace( start, word.length(),
"'" + word +
"'" );
282 l = formula.length();
284 kdDebug(30518) <<
"Formula: " << formula <<
", L: " << l <<
", i: " << i + 1 <<endl;
289void OpenCalcImport::convertFormula( TQString & text, TQString
const & f )
const
291 kdDebug(30518) <<
"Parsing formula: " << f << endl;
301 if ( f[p] ==
'(' || f[p] ==
'[' )
310 if ( parameter.isEmpty() )
312 checkForNamedAreas( formula );
315 kdDebug(30518) <<
"Formula: " << formula <<
", Parameter: " << parameter <<
", P: " << p << endl;
319 if ( formula ==
"=MULTIPLE.OPERATIONS" )
320 formula =
"=MULTIPLEOPERATIONS";
324 bool inQuote =
false;
333 else if ( f[p] ==
'[' )
340 else if ( f[p] ==
']' )
349 parameter += translatePar( par );
356 else if ( f[p] ==
'=' )
363 else if ( f[p] ==
')' )
373 checkForNamedAreas( parameter );
376 text = formula + parameter;
377 kdDebug(30518) <<
"New formula: " << text << endl;
380bool OpenCalcImport::readCells( TQDomElement & rowNode, Sheet * table,
int row,
int & columns )
387 TQDomNode cellNode = KoDom::namedItemNS( rowNode, ooNS::table,
"table-cell" );
389 while ( !cellNode.isNull() )
391 spanR = 1; spanC = 1;
393 TQDomElement e = cellNode.toElement();
398 cellNode = cellNode.nextSibling();
404 kdDebug(30518) <<
" Cell: " << columns <<
", " << row << endl;
407 if ( e.hasAttributeNS( ooNS::table,
"number-columns-spanned" ) )
409 int span = e.attributeNS( ooNS::table,
"number-columns-spanned", TQString() ).toInt( &ok );
413 if ( e.hasAttributeNS( ooNS::table,
"number-rows-spanned" ) )
415 int span = e.attributeNS( ooNS::table,
"number-rows-spanned", TQString() ).toInt( &ok );
421 TQDomElement textP = KoDom::namedItemNS( e, ooNS::text,
"p" );
422 if ( !textP.isNull() )
424 TQDomElement subText = textP.firstChild().toElement();
425 if ( !subText.isNull() )
428 text = subText.text();
430 if ( subText.hasAttributeNS( ooNS::xlink,
"href" ) )
432 TQString link = subText.attributeNS( ooNS::xlink,
"href", TQString() );
434 link=link.remove( 0, 1 );
436 cell = table->nonDefaultCell( columns, row );
437 cell->setLink( link );
443 TQDomElement annotation = KoDom::namedItemNS( e, ooNS::office,
"annotation" );
444 if ( !annotation.isNull() )
447 TQDomNode node = annotation.firstChild();
448 while( !node.isNull() )
450 TQDomElement commentElement = node.toElement();
451 if( !commentElement.isNull() )
452 if ( commentElement.localName() ==
"p" && e.namespaceURI()==ooNS::text)
454 if( !comment.isEmpty() ) comment.append(
'\n' );
455 comment.append( commentElement.text() );
458 node = node.nextSibling();
461 if( !comment.isEmpty() )
464 cell = table->nonDefaultCell( columns, row );
465 kdDebug(30518)<<
" columns :"<<columns<<
" row :"<<row<<endl;
466 cell->format()->setComment( comment );
470 kdDebug(30518) <<
"Contains: " << text << endl;
471 bool isFormula =
false;
473 if ( e.hasAttributeNS( ooNS::table,
"style-name" ) )
476 cell = table->nonDefaultCell( columns, row );
478 TQString psName(
"Default" );
479 if ( e.hasAttributeNS( ooNS::style,
"parent-style-name" ) )
480 psName = e.attributeNS( ooNS::style,
"parent-style-name", TQString() );
482 kdDebug(30518) <<
"Default style: " << psName << endl;
483 Format * layout = m_defaultStyles[psName];
486 cell->format()->copy( *layout );
488 TQDomElement * st = 0;
489 if ( e.hasAttributeNS( ooNS::table,
"style-name" ) )
491 kdDebug(30518) <<
"Style: " << e.attributeNS( ooNS::table,
"style-name", TQString() ) << endl;
492 st = m_styles[ e.attributeNS( ooNS::table,
"style-name", TQString() ) ];
496 kdDebug(30518) <<
"Style: adapting " << endl;
497 TQDomNode node = st->firstChild();
498 bool foundValidation =
false;
499 while( !node.isNull() )
501 TQDomElement
property = node.toElement();
502 if ( !property.isNull() )
504 kdDebug(30518)<<
"property.tagName() :"<<
property.tagName()<<endl;
505 if ( property.localName()==
"map" && property.namespaceURI() == ooNS::style && !foundValidation)
507 loadCondition( cell, property );
508 foundValidation =
true;
510 if ( property.localName() ==
"properties" && property.namespaceURI() == ooNS::style )
512 loadStyleProperties( cell->format(), property );
513 if ( cell->format()->getAngle( columns, row ) != 0 )
515 TQFontMetrics fm( cell->format()->textFont( columns, row ) );
516 int tmpAngle = cell->format()->getAngle( columns, row );
517 int textHeight =
static_cast<int>( cos( tmpAngle * M_PI / 180 )
518 * ( fm.ascent() + fm.descent() )
519 + abs ( (
int )( fm.width( cell->strOutText() )
520 * sin( tmpAngle * M_PI / 180 ) ) ) );
527 kdDebug(30518) <<
"Rotation: height: " << textHeight << endl;
529 RowFormat * l = table->rowFormat( row );
530 if ( l->height() < textHeight )
532 if ( l->isDefault() )
533 l = table->nonDefaultRowFormat( row );
535 l->setHeight( textHeight + 2 );
540 node = node.nextSibling();
547 cell = table->nonDefaultCell( columns, row );
549 TQString psName(
"Default" );
550 kdDebug(30518) <<
"Default style: " << psName << endl;
551 Format * layout = m_defaultStyles[psName];
554 cell->format()->copy( *layout );
556 if ( e.hasAttributeNS( ooNS::table,
"formula" ) )
560 convertFormula( formula, e.attributeNS( ooNS::table,
"formula", TQString() ) );
563 cell = table->nonDefaultCell( columns, row );
564 cell->setCellText( formula );
566 if ( e.hasAttributeNS( ooNS::table,
"validation-name" ) )
568 kdDebug(30518)<<
" Celle has a validation :"<<e.attributeNS( ooNS::table,
"validation-name", TQString() )<<endl;
569 loadOasisValidation( cell->getValidity(), e.attributeNS( ooNS::table,
"validation-name", TQString() ) );
571 if ( e.hasAttributeNS( ooNS::table,
"value-type" ) )
574 cell = table->nonDefaultCell( columns, row );
576 cell->setCellText( text );
578 TQString value = e.attributeNS( ooNS::table,
"value", TQString() );
579 TQString type = e.attributeNS( ooNS::table,
"value-type", TQString() );
581 kdDebug(30518) <<
"Value: " << value <<
", type: " << type << endl;
586 if ( ( type ==
"float" ) || ( type ==
"currency" ) )
588 dv = value.toDouble( &ok );
592 cell->setValue( dv );
594 if ( type ==
"currency" )
596 cell->format()->setCurrency( 1, e.attributeNS( ooNS::table,
"currency", TQString() ) );
597 cell->format()->setFormatType( Money_format );
602 if ( type ==
"percentage" )
604 dv = value.toDouble( &ok );
608 cell->setValue( dv );
612 cell->format()->setFormatType( Percentage_format );
615 else if ( type ==
"boolean" )
617 if ( value.isEmpty() )
618 value = e.attributeNS( ooNS::table,
"boolean-value", TQString() );
620 kdDebug(30518) <<
"Type: boolean" << endl;
621 if ( value ==
"true" )
622 cell->setValue(
true );
624 cell->setValue(
false );
626 cell->format()->setFormatType( Custom_format );
628 else if ( type ==
"date" )
630 if ( value.isEmpty() )
631 value = e.attributeNS( ooNS::table,
"date-value", TQString() );
632 kdDebug(30518) <<
"Type: date, value: " << value << endl;
635 int year=0, month=0, day=0;
638 int p1 = value.find(
'-' );
640 year = value.left( p1 ).toInt( &ok );
642 kdDebug(30518) <<
"year: " << value.left( p1 ) << endl;
644 int p2 = value.find(
'-', ++p1 );
647 month = value.mid( p1, p2 - p1 ).toInt( &ok );
649 kdDebug(30518) <<
"month: " << value.mid( p1, p2 - p1 ) << endl;
652 day = value.right( value.length() - p2 - 1 ).toInt( &ok );
654 kdDebug(30518) <<
"day: " << value.right( value.length() - p2 ) << endl;
658 TQDateTime dt( TQDate( year, month, day ) );
661 cell->setValue( TQDate( year, month, day ) );
662 kdDebug(30518) <<
"Set TQDate: " << year <<
" - " << month <<
" - " << day << endl;
665 else if ( type ==
"time" )
667 if ( value.isEmpty() )
668 value = e.attributeNS( ooNS::table,
"time-value", TQString() );
670 kdDebug(30518) <<
"Type: time: " << value << endl;
672 int hours=0, minutes=0, seconds=0;
673 int l = value.length();
676 for (
int i = 0; i < l; ++i )
678 if ( value[i].isNumber() )
683 else if ( value[i] ==
'H' )
684 hours = num.toInt( &ok );
685 else if ( value[i] ==
'M' )
686 minutes = num.toInt( &ok );
687 else if ( value[i] ==
'S' )
688 seconds = num.toInt( &ok );
692 kdDebug(30518) <<
"Num: " << num << endl;
699 kdDebug(30518) <<
"Hours: " << hours <<
", " << minutes <<
", " << seconds << endl;
705 cell->setValue( TQTime( hours % 24, minutes, seconds ) );
706 cell->format()->setFormatType( Custom_format );
712 cell->setCellText( text );
714 else if ( !text.isEmpty() )
717 cell = table->nonDefaultCell( columns, row );
718 cell->setCellText( text );
721 if ( spanR > 1 || spanC > 1 )
724 cell = table->nonDefaultCell( columns, row );
725 cell->mergeCells( columns, row, spanC - 1, spanR - 1 );
728 cellNode = cellNode.nextSibling();
730 if ( e.hasAttributeNS( ooNS::table,
"number-columns-repeated" ) )
734 int number = e.attributeNS( ooNS::table,
"number-columns-repeated", TQString() ).toInt( &ok );
738 if ( !ok || cellNode.isNull() )
744 for (
int i = 1; i < number; ++i )
750 cellDest = table->nonDefaultCell( columns, row );
751 cellDest->copyAll( cell );
763void OpenCalcImport::loadCondition( Cell*cell,
const TQDomElement &property )
765 kdDebug(30518)<<
"void OpenCalcImport::loadCondition( Cell*cell,const TQDomElement &property )*******\n";
766 loadOasisCondition( cell, property );
769void OpenCalcImport::loadOasisCondition(Cell*cell,
const TQDomElement &property )
771 TQDomElement elementItem( property );
772 StyleManager * manager = cell->sheet()->doc()->styleManager();
774 TQValueList<Conditional> cond;
775 while ( !elementItem.isNull() )
777 kdDebug(30518)<<
"elementItem.tagName() :"<<elementItem.tagName()<<endl;
779 if ( elementItem.localName()==
"map" && property.namespaceURI() == ooNS::style )
782 kdDebug(30518)<<
"elementItem.attribute(style:condition ) :"<<elementItem.attributeNS( ooNS::style,
"condition", TQString() )<<endl;
783 Conditional newCondition;
784 loadOasisConditionValue( elementItem.attributeNS( ooNS::style,
"condition", TQString() ), newCondition );
785 if ( elementItem.hasAttributeNS( ooNS::style,
"apply-style-name" ) )
787 kdDebug(30518)<<
"elementItem.attribute( style:apply-style-name ) :"<<elementItem.attributeNS( ooNS::style,
"apply-style-name", TQString() )<<endl;
788 newCondition.styleName =
new TQString( elementItem.attributeNS( ooNS::style,
"apply-style-name", TQString() ) );
789 newCondition.style = manager->style( *newCondition.styleName );
790 if ( !newCondition.style )
797 cond.append( newCondition );
799 kdDebug(30518) <<
"Error loading condition " << elementItem.nodeName()<< endl;
801 elementItem = elementItem.nextSibling().toElement();
803 if ( !cond.isEmpty() )
804 cell->setConditionList( cond );
807void OpenCalcImport::loadOasisConditionValue(
const TQString &styleCondition, Conditional &newCondition )
809 TQString val( styleCondition );
810 if ( val.contains(
"cell-content()" ) )
812 val = val.remove(
"cell-content()" );
813 loadOasisCondition( val,newCondition );
817 if ( val.contains(
"cell-content-is-between(" ) )
819 val = val.remove(
"cell-content-is-between(" );
820 val = val.remove(
")" );
821 TQStringList listVal = TQStringList::split(
"," , val );
822 loadOasisValidationValue( listVal, newCondition );
823 newCondition.cond = Conditional::Between;
825 if ( val.contains(
"cell-content-is-not-between(" ) )
827 val = val.remove(
"cell-content-is-not-between(" );
828 val = val.remove(
")" );
829 TQStringList listVal = TQStringList::split(
",", val );
830 loadOasisValidationValue( listVal,newCondition );
831 newCondition.cond = Conditional::Different;
837void OpenCalcImport::loadOasisCondition( TQString &valExpression, Conditional &newCondition )
840 if (valExpression.find(
"<=" )==0 )
842 value = valExpression.remove( 0,2 );
843 newCondition.cond = Conditional::InferiorEqual;
845 else if (valExpression.find(
">=" )==0 )
847 value = valExpression.remove( 0,2 );
848 newCondition.cond = Conditional::SuperiorEqual;
850 else if (valExpression.find(
"!=" )==0 )
853 value = valExpression.remove( 0,2 );
854 newCondition.cond = Conditional::DifferentTo;
856 else if ( valExpression.find(
"<" )==0 )
858 value = valExpression.remove( 0,1 );
859 newCondition.cond = Conditional::Inferior;
861 else if(valExpression.find(
">" )==0 )
863 value = valExpression.remove( 0,1 );
864 newCondition.cond = Conditional::Superior;
866 else if (valExpression.find(
"=" )==0 )
868 value = valExpression.remove( 0,1 );
869 newCondition.cond = Conditional::Equal;
872 kdDebug(30518)<<
" I don't know how to parse it :"<<valExpression<<endl;
873 kdDebug(30518)<<
" value :"<<value<<endl;
875 newCondition.val1 = value.toDouble(&ok);
878 newCondition.val1 = value.toInt(&ok);
881 newCondition.strVal1 =
new TQString( value );
882 kdDebug(30518)<<
" Try to parse this value :"<<value<<endl;
889void OpenCalcImport::loadOasisValidationValue(
const TQStringList &listVal, Conditional &newCondition )
892 kdDebug(30518)<<
" listVal[0] :"<<listVal[0]<<
" listVal[1] :"<<listVal[1]<<endl;
894 newCondition.val1 = listVal[0].toDouble(&ok);
897 newCondition.val1 = listVal[0].toInt(&ok);
900 newCondition.strVal1 =
new TQString( listVal[0] );
901 kdDebug(30518)<<
" Try to parse this value :"<<listVal[0]<<endl;
905 newCondition.val2 = listVal[1].toDouble(&ok);
908 newCondition.val2 = listVal[1].toInt(&ok);
911 newCondition.strVal2 =
new TQString( listVal[1] );
912 kdDebug(30518)<<
" Try to parse this value :"<<listVal[1]<<endl;
918bool OpenCalcImport::readRowsAndCells( TQDomElement & content, Sheet * table )
920 kdDebug(30518) << endl <<
"Reading in rows " << endl;
926 TQDomElement * rowStyle = 0;
930 TQDomNode rowNode = KoDom::namedItemNS( content, ooNS::table,
"table-row" );
932 while ( !rowNode.isNull() )
934 bool collapsed =
false;
937 TQDomElement r = rowNode.toElement();
942 if ( r.hasAttributeNS( ooNS::table,
"style-name" ) )
944 TQString style = r.attributeNS( ooNS::table,
"style-name", TQString() );
945 rowStyle = m_styles[ style ];
946 kdDebug(30518) <<
"Row style: " << style << endl;
949 collapsed = ( r.attributeNS( ooNS::table,
"visibility", TQString() ) ==
"collapse" );
953 rowNode = rowNode.nextSibling();
955 if ( !readRowFormat( r, rowStyle, table, row, number, rowNode.isNull() ) )
958 if ( !readCells( r, table, backupRow, columns ) )
961 RowFormat * srcLayout = table->nonDefaultRowFormat( backupRow );
962 RowFormat * layout = 0;
965 srcLayout->setHide(
true );
967 for ( i = 1; i < number; ++i )
969 layout = table->nonDefaultRowFormat( backupRow + i );
971 layout->copy( *srcLayout );
994 kdDebug(30518) <<
"Reading in rows done" << endl << endl;
999bool OpenCalcImport::readColLayouts( TQDomElement & content, Sheet * table )
1001 kdDebug(30518) << endl <<
"Reading in columns..." << endl;
1003 TQDomNode colLayout = KoDom::namedItemNS( content, ooNS::table,
"table-column" );
1006 while ( !colLayout.isNull() )
1008 if ( colLayout.nodeName() !=
"table:table-column" )
1011 TQDomElement e = colLayout.toElement();
1016 kdDebug(30518) <<
"New column: " << column << endl;
1019 double width = -1.0;
1020 bool collapsed = ( e.attributeNS( ooNS::table,
"visibility", TQString() ) ==
"collapse" );
1021 bool insertPageBreak =
false;
1022 Format styleLayout( table, table->doc()->styleManager()->defaultStyle() );
1024 kdDebug(30518) <<
"Check table:number-columns-repeated" << endl;
1025 if ( e.hasAttributeNS( ooNS::table,
"number-columns-repeated" ) )
1028 number = e.attributeNS( ooNS::table,
"number-columns-repeated", TQString() ).toInt( &ok );
1032 kdDebug(30518) <<
"Repeated: " << number << endl;
1035 kdDebug(30518) <<
"Checking table:default-cell-style-name" << endl;
1036 if ( e.hasAttributeNS( ooNS::table,
"default-cell-style-name" ) )
1038 TQString n( e.attributeNS( ooNS::table,
"default-cell-style-name", TQString() ) );
1039 kdDebug(30518) <<
"Has attribute default-cell-style-name: " << n << endl;
1040 Format * defaultStyle = m_defaultStyles[ n ];
1041 if ( !defaultStyle )
1043 TQString name = e.attributeNS( ooNS::table,
"default-cell-style-name", TQString() );
1044 TQDomElement * st = m_styles[ name ];
1046 kdDebug(30518) <<
"Default cell style: " << name << endl;
1048 if ( st && !st->isNull() )
1050 Format * layout =
new Format( 0, m_doc->styleManager()->defaultStyle() );
1052 readInStyle( layout, *st );
1054 m_defaultStyles.insert( name, layout );
1055 kdDebug(30518) <<
"Insert default cell style: " << name << endl;
1057 defaultStyle = layout;
1064 styleLayout.copy( *defaultStyle );
1068 TQDomElement * colStyle = 0;
1069 if ( e.hasAttributeNS( ooNS::table,
"style-name" ) )
1071 TQString style = e.attributeNS( ooNS::table,
"style-name", TQString() );
1072 colStyle = m_styles[ style ];
1074 kdDebug(30518) <<
"Col Style: " << style << endl;
1080 node = colStyle->firstChild();
1082 while( !node.isNull() )
1084 TQDomElement
property = node.toElement();
1085 if ( !property.isNull() && property.localName() ==
"properties" && property.namespaceURI() == ooNS::style )
1087 if ( property.hasAttributeNS( ooNS::style,
"column-width" ) )
1089 TQString sWidth =
property.attributeNS( ooNS::style,
"column-width", TQString() );
1090 width = KoUnit::parseValue( property.attributeNS( ooNS::style,
"column-width", TQString() ), width );
1091 kdDebug(30518) <<
"Col Width: " << sWidth << endl;
1094 if ( property.hasAttributeNS( ooNS::fo,
"break-before" ) )
1096 if ( property.attributeNS( ooNS::fo,
"break-before", TQString() ) ==
"page" )
1098 insertPageBreak =
true;
1102 loadStyleProperties( &styleLayout, property );
1105 node = node.nextSibling();
1108 colLayout = colLayout.nextSibling();
1110 if ( colLayout.isNull() && ( number > 30 ) )
1113 for (
int i = 0; i < number; ++i )
1115 kdDebug(30518) <<
"Inserting colLayout: " << column << endl;
1117 ColumnFormat * col =
new ColumnFormat( table, column );
1118 col->copy( styleLayout );
1119 if ( width != -1.0 )
1120 col->setWidth(
int( width ) );
1126 col->setHide(
true );
1128 table->insertColumnFormat( col );
1136void replaceMacro( TQString & text, TQString
const & old, TQString
const & newS )
1138 int n = text.find( old );
1140 text = text.replace( n, old.length(), newS );
1143TQString getPart( TQDomNode
const & part )
1146 TQDomElement e = KoDom::namedItemNS( part, ooNS::text,
"p" );
1147 while ( !e.isNull() )
1149 TQString text = e.text();
1150 kdDebug(30518) <<
"PART: " << text << endl;
1152 TQDomElement macro = KoDom::namedItemNS( e, ooNS::text,
"time" );
1153 if ( !macro.isNull() )
1154 replaceMacro( text, macro.text(),
"<time>" );
1156 macro = KoDom::namedItemNS( e, ooNS::text,
"date" );
1157 if ( !macro.isNull() )
1158 replaceMacro( text, macro.text(),
"<date>" );
1160 macro = KoDom::namedItemNS( e, ooNS::text,
"page-number" );
1161 if ( !macro.isNull() )
1162 replaceMacro( text, macro.text(),
"<page>" );
1164 macro = KoDom::namedItemNS( e, ooNS::text,
"page-count" );
1165 if ( !macro.isNull() )
1166 replaceMacro( text, macro.text(),
"<pages>" );
1168 macro = KoDom::namedItemNS( e, ooNS::text,
"sheet-name" );
1169 if ( !macro.isNull() )
1170 replaceMacro( text, macro.text(),
"<sheet>" );
1172 macro = KoDom::namedItemNS( e, ooNS::text,
"title" );
1173 if ( !macro.isNull() )
1174 replaceMacro( text, macro.text(),
"<name>" );
1176 macro = KoDom::namedItemNS( e, ooNS::text,
"file-name" );
1177 if ( !macro.isNull() )
1178 replaceMacro( text, macro.text(),
"<file>" );
1180 if ( !result.isEmpty() )
1183 e = e.nextSibling().toElement();
1189void OpenCalcImport::loadTableMasterStyle( Sheet * table,
1190 TQString
const & stylename )
1192 kdDebug(30518) <<
"Loading table master style: " << stylename << endl;
1194 TQDomElement * style = m_styles[ stylename ];
1198 kdDebug(30518) <<
"Master style not found! " << endl;
1202 TQDomNode header = KoDom::namedItemNS( *style, ooNS::style,
"header" );
1203 kdDebug(30518) <<
"Style header " << endl;
1205 TQString hleft, hmiddle, hright;
1206 TQString fleft, fmiddle, fright;
1208 if ( !header.isNull() )
1210 kdDebug(30518) <<
"Header exists" << endl;
1211 TQDomNode part = KoDom::namedItemNS( header, ooNS::style,
"region-left" );
1212 if ( !part.isNull() )
1214 hleft = getPart( part );
1215 kdDebug(30518) <<
"Header left: " << hleft << endl;
1218 kdDebug(30518) <<
"Style:region:left doesn't exist!" << endl;
1219 part = KoDom::namedItemNS( header, ooNS::style,
"region-center" );
1220 if ( !part.isNull() )
1222 hmiddle = getPart( part );
1223 kdDebug(30518) <<
"Header middle: " << hmiddle << endl;
1225 part = KoDom::namedItemNS( header, ooNS::style,
"region-right" );
1226 if ( !part.isNull() )
1228 hright = getPart( part );
1229 kdDebug(30518) <<
"Header right: " << hright << endl;
1233 TQDomNode footer = KoDom::namedItemNS( *style, ooNS::style,
"footer" );
1235 if ( !footer.isNull() )
1237 TQDomNode part = KoDom::namedItemNS( footer, ooNS::style,
"region-left" );
1238 if ( !part.isNull() )
1240 fleft = getPart( part );
1241 kdDebug(30518) <<
"Footer left: " << fleft << endl;
1243 part = KoDom::namedItemNS( footer, ooNS::style,
"region-center" );
1244 if ( !part.isNull() )
1246 fmiddle = getPart( part );
1247 kdDebug(30518) <<
"Footer middle: " << fmiddle << endl;
1249 part = KoDom::namedItemNS( footer, ooNS::style,
"region-right" );
1250 if ( !part.isNull() )
1252 fright = getPart( part );
1253 kdDebug(30518) <<
"Footer right: " << fright << endl;
1257 table->print()->setHeadFootLine( hleft, hmiddle, hright,
1258 fleft, fmiddle, fright );
1259 if ( style->hasAttributeNS( ooNS::style,
"page-master-name" ) )
1261 TQString masterPageLayoutStyleName=style->attributeNS( ooNS::style,
"page-master-name", TQString() );
1262 kdDebug(30518)<<
"masterPageLayoutStyleName :"<<masterPageLayoutStyleName<<endl;
1263 TQDomElement *masterLayoutStyle = m_styles[masterPageLayoutStyleName];
1264 kdDebug(30518)<<
"masterLayoutStyle :"<<masterLayoutStyle<<endl;
1265 if ( !masterLayoutStyle )
1267 KoStyleStack styleStack( ooNS::style, ooNS::fo );
1268 styleStack.push( *masterLayoutStyle );
1269 loadOasisMasterLayoutPage( table, styleStack );
1273void OpenCalcImport::loadOasisMasterLayoutPage( Sheet * table,KoStyleStack &styleStack )
1281 TQString orientation =
"Portrait";
1287 if ( styleStack.hasAttributeNS( ooNS::fo,
"page-width" ) )
1289 width = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( ooNS::fo,
"page-width" ) ) );
1291 if ( styleStack.hasAttributeNS( ooNS::fo,
"page-height" ) )
1293 height = KoUnit::toMM( KoUnit::parseValue( styleStack.attributeNS( ooNS::fo,
"page-height" ) ) );
1295 if ( styleStack.hasAttributeNS( ooNS::fo,
"margin-top" ) )
1297 top = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( ooNS::fo,
"margin-top" ) ) );
1299 if ( styleStack.hasAttributeNS( ooNS::fo,
"margin-bottom" ) )
1301 bottom = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( ooNS::fo,
"margin-bottom" ) ) );
1303 if ( styleStack.hasAttributeNS( ooNS::fo,
"margin-left" ) )
1305 left = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( ooNS::fo,
"margin-left" ) ) );
1307 if ( styleStack.hasAttributeNS( ooNS::fo,
"margin-right" ) )
1309 right = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( ooNS::fo,
"margin-right" ) ) );
1311 if ( styleStack.hasAttributeNS( ooNS::style,
"writing-mode" ) )
1313 kdDebug(30518)<<
"styleStack.hasAttribute( style:writing-mode ) :"<<styleStack.hasAttributeNS( ooNS::style,
"writing-mode" )<<endl;
1315 if ( styleStack.hasAttributeNS( ooNS::style,
"print-orientation" ) )
1317 orientation = ( styleStack.attributeNS( ooNS::style,
"print-orientation" )==
"landscape" ) ?
"Landscape" :
"Portrait" ;
1319 if ( styleStack.hasAttributeNS( ooNS::style,
"num-format" ) )
1321 kdDebug(30518)<<
" num-format :"<<styleStack.attributeNS( ooNS::style,
"num-format" )<<endl;
1324 if ( styleStack.hasAttributeNS( ooNS::fo,
"background-color" ) )
1327 kdDebug(30518)<<
" fo:background-color :"<<styleStack.attributeNS( ooNS::fo,
"background-color" )<<endl;
1329 if ( styleStack.hasAttributeNS( ooNS::style,
"print" ) )
1332 TQString str = styleStack.attributeNS( ooNS::style,
"print" );
1333 kdDebug(30518)<<
" style:print :"<<str<<endl;
1335 if (str.contains(
"headers" ) )
1339 if ( str.contains(
"grid" ) )
1341 table->print()->setPrintGrid(
true );
1343 if ( str.contains(
"annotations" ) )
1347 if ( str.contains(
"objects" ) )
1351 if ( str.contains(
"charts" ) )
1355 if ( str.contains(
"drawings" ) )
1359 if ( str.contains(
"formulas" ) )
1361 table->setShowFormula(
true);
1363 if ( str.contains(
"zero-values" ) )
1368 if ( styleStack.hasAttributeNS( ooNS::style,
"table-centering" ) )
1370 TQString str = styleStack.attributeNS( ooNS::style,
"table-centering" );
1372 kdDebug(30518)<<
" styleStack.attribute( style:table-centering ) :"<<str<<endl;
1374 if ( str ==
"horizontal" )
1377 else if ( str ==
"vertical" )
1380 else if ( str ==
"both" )
1383 else if ( str ==
"none" )
1387 kdDebug(30518)<<
" table-centering unknown :"<<str<<endl;
1390 format = TQString(
"%1x%2" ).arg( width ).arg( height );
1391 kdDebug(30518)<<
" format : "<<format<<endl;
1392 table->print()->setPaperLayout( left, top, right, bottom, format, orientation );
1394 kdDebug(30518)<<
" left margin :"<<left<<
" right :"<<right<<
" top :"<<top<<
" bottom :"<<bottom<<endl;
1403bool OpenCalcImport::parseBody(
int numOfTables )
1405 TQDomElement content = m_content.documentElement();
1406 TQDomNode body = KoDom::namedItemNS( content, ooNS::office,
"body" );
1408 if ( body.isNull() )
1411 loadOasisAreaName( body.toElement() );
1412 loadOasisCellValidation( body.toElement() );
1415 TQDomNode sheet = KoDom::namedItemNS( body, ooNS::table,
"table" );
1417 kdDebug()<<
" sheet :"<<sheet.isNull()<<endl;
1418 if ( sheet.isNull() )
1421 while ( !sheet.isNull() )
1423 TQDomElement t = sheet.toElement();
1426 sheet = sheet.nextSibling();
1429 if ( t.nodeName() !=
"table:table" )
1431 sheet = sheet.nextSibling();
1435 table = m_doc->map()->addNewSheet();
1437 table->setSheetName( t.attributeNS( ooNS::table,
"name", TQString() ),
true,
false );
1438 kdDebug()<<
" table->name()"<<table->name()<<endl;
1439 sheet = sheet.nextSibling();
1442 sheet = body.firstChild();
1444 int step = (int) ( 80 / numOfTables );
1447 Format::setGlobalColWidth( MM_TO_POINT( 22.7 ) );
1448 Format::setGlobalRowHeight( MM_TO_POINT( 4.3 ) );
1449 kdDebug(30518) <<
"Global Height: " << MM_TO_POINT( 4.3 ) <<
", Global width: " << MM_TO_POINT( 22.7) << endl;
1451 while ( !sheet.isNull() )
1453 TQDomElement t = sheet.toElement();
1456 KMessageBox::sorry( 0, i18n(
"The file seems to be corrupt. Skipping a table." ) );
1457 sheet = sheet.nextSibling();
1460 if ( t.nodeName() !=
"table:table" )
1462 sheet = sheet.nextSibling();
1466 table = m_doc->map()->findSheet( t.attributeNS( ooNS::table,
"name", TQString() ) );
1469 KMessageBox::sorry( 0, i18n(
"Skipping a table." ) );
1470 sheet = sheet.nextSibling();
1474 Format * defaultStyle = m_defaultStyles[
"Default" ];
1477 Cell* defaultCell = table->defaultCell();
1478 kdDebug(30518) <<
"Copy default style to default cell" << endl;
1479 defaultCell->format()->copy( *defaultStyle );
1481 table->setDefaultHeight( MM_TO_POINT( 4.3 ) );
1482 table->setDefaultWidth( MM_TO_POINT( 22.7 ) );
1484 kdDebug(30518) <<
"Added table: " << t.attributeNS( ooNS::table,
"name", TQString() ) << endl;
1486 if ( t.hasAttributeNS( ooNS::table,
"style-name" ) )
1488 TQString style = t.attributeNS( ooNS::table,
"style-name", TQString() );
1489 TQDomElement * tableStyle = m_styles[ style ];
1494 node = tableStyle->firstChild();
1496 while( !node.isNull() )
1498 TQDomElement
property = node.toElement();
1499 if ( property.localName() ==
"properties" && property.namespaceURI() == ooNS::style )
1501 if ( property.hasAttributeNS( ooNS::table,
"display" ) )
1503 bool visible = (
property.attributeNS( ooNS::table,
"display", TQString() ) ==
"true" ?
true :
false );
1504 table->hideSheet( !visible );
1505 kdDebug(30518) <<
"Table: " << table->tableName() <<
", hidden: " << !visible << endl;
1509 node = node.nextSibling();
1512 if ( tableStyle && tableStyle->hasAttributeNS( ooNS::style,
"master-page-name" ) )
1514 TQString stylename =
"pm" + tableStyle->attributeNS( ooNS::style,
"master-page-name", TQString() );
1516 loadTableMasterStyle( table, stylename );
1520 if ( t.hasAttributeNS( ooNS::table,
"print-ranges" ) )
1523 TQString range = t.attributeNS( ooNS::table,
"print-ranges", TQString() );
1524 OpenCalcPoint point( range );
1526 kdDebug(30518) <<
"Print range: " << point.translation << endl;
1527 KSpread::Range p( point.translation );
1529 kdDebug(30518) <<
"Print table: " << p.sheetName() << endl;
1531 if ( table->sheetName() == p.sheetName() )
1532 table->print()->setPrintRange( p.range() );
1535 if ( !readColLayouts( t, table ) )
1538 if ( !readRowsAndCells( t, table ) )
1541 if ( t.hasAttributeNS( ooNS::table,
"protected" ) )
1543 TQCString passwd(
"" );
1544 if ( t.hasAttributeNS( ooNS::table,
"protection-key" ) )
1546 TQString p = t.attributeNS( ooNS::table,
"protection-key", TQString() );
1547 TQCString str( p.latin1() );
1548 kdDebug(30518) <<
"Decoding password: " << str << endl;
1549 passwd = KCodecs::base64Decode( str );
1551 kdDebug(30518) <<
"Password hash: '" << passwd <<
"'" << endl;
1552 table->setProtected( passwd );
1556 emit sigProgress( progress );
1557 sheet = sheet.nextSibling();
1560 TQDomElement b = body.toElement();
1561 if ( b.hasAttributeNS( ooNS::table,
"structure-protected" ) )
1563 TQCString passwd(
"" );
1564 if ( b.hasAttributeNS( ooNS::table,
"protection-key" ) )
1566 TQString p = b.attributeNS( ooNS::table,
"protection-key", TQString() );
1567 TQCString str( p.latin1() );
1568 kdDebug(30518) <<
"Decoding password: " << str << endl;
1569 passwd = KCodecs::base64Decode( str );
1571 kdDebug(30518) <<
"Password hash: '" << passwd <<
"'" << endl;
1573 m_doc->map()->setProtected( passwd );
1576 emit sigProgress( 98 );
1581void OpenCalcImport::insertStyles( TQDomElement
const & element )
1583 if ( element.isNull() )
1587 forEachElement( e, element )
1589 if ( e.isNull() || !e.hasAttributeNS( ooNS::style,
"name" ) )
1594 TQString name = e.attributeNS( ooNS::style,
"name", TQString() );
1595 kdDebug(30518) <<
"Style: '" << name <<
"' loaded " << endl;
1596 m_styles.insert( name,
new TQDomElement( e ) );
1601void OpenCalcImport::loadOasisAreaName(
const TQDomElement&body )
1603 TQDomNode namedAreas = KoDom::namedItemNS( body, ooNS::table,
"named-expressions" );
1604 if ( !namedAreas.isNull() )
1607 forEachElement( e, namedAreas )
1609 if ( e.isNull() || !e.hasAttributeNS( ooNS::table,
"name" ) || !e.hasAttributeNS( ooNS::table,
"cell-range-address" ) )
1611 kdDebug(30518) <<
"Reading in named area failed" << endl;
1616 TQString name = e.attributeNS( ooNS::table,
"name", TQString() );
1617 TQString areaPoint = e.attributeNS( ooNS::table,
"cell-range-address", TQString() );
1619 m_namedAreas.append( name );
1620 kdDebug(30518) <<
"Reading in named area, name: " << name <<
", area: " << areaPoint << endl;
1622 OpenCalcPoint point( areaPoint );
1623 kdDebug(30518) <<
"Area: " << point.translation << endl;
1625 TQString range( point.translation );
1627 if ( point.translation.find(
':' ) == -1 )
1629 Point p( point.translation );
1631 int n = range.find(
'!' );
1633 range = range +
":" + range.right( range.length() - n - 1);
1635 kdDebug(30518) <<
"=> Area: " << range << endl;
1638 KSpread::Range p( range );
1640 m_doc->addAreaName( p.range(), name, p.sheetName() );
1641 kdDebug(30518) <<
"Area range: " << p.sheetName() << endl;
1646void OpenCalcImport::loadOasisCellValidation(
const TQDomElement&body )
1648 TQDomNode validation = KoDom::namedItemNS( body, ooNS::table,
"content-validations" );
1649 if ( !validation.isNull() )
1651 TQDomElement element;
1652 forEachElement( element, validation )
1654 if ( element.localName() ==
"content-validation" ) {
1655 m_validationList.insert( element.attributeNS( ooNS::table,
"name", TQString() ), element);
1656 kdDebug(30518)<<
" validation found :"<<element.attributeNS( ooNS::table,
"name", TQString() )<<endl;
1659 kdDebug(30518)<<
" Tag not recognize :"<<element.tagName()<<endl;
1666TQString * OpenCalcImport::loadFormat( TQDomElement * element,
1667 FormatType & formatType,
1676 TQString * format = 0;
1677 TQDomElement e = element->firstChild( ).toElement();
1680 bool thousandsSep =
false;
1681 bool negRed =
false;
1683 if ( element->localName() ==
"time-style" )
1684 formatType = Custom_format;
1685 else if ( element->localName() ==
"date-style" )
1686 formatType = Custom_format;
1687 else if ( element->localName() ==
"percentage-style" )
1688 formatType = Custom_format;
1689 else if ( element->localName() ==
"number-style" )
1690 formatType = Custom_format;
1691 else if ( element->localName() ==
"currency-style" )
1692 formatType = Custom_format;
1693 else if ( element->localName() ==
"boolean-style" )
1694 formatType = Custom_format;
1697 format =
new TQString();
1704 while ( !e.isNull() )
1706 if ( e.localName() ==
"properties" && e.namespaceURI() == ooNS::style )
1708 if ( e.hasAttributeNS( ooNS::fo,
"color" ) )
1711 else if ( e.localName() ==
"text" && e.namespaceURI()==ooNS::number)
1713 if ( negRed && ( e.text() ==
"-" ) )
1716 format->append( e.text() );
1718 else if ( e.localName() ==
"currency-symbol" && e.namespaceURI()==ooNS::number)
1720 TQString sym( e.text() );
1721 kdDebug(30518) <<
"Currency: " << sym << endl;
1722 format->append( sym );
1725 else if ( e.localName() ==
"day-of-week" && e.namespaceURI()==ooNS::number)
1727 if ( e.hasAttributeNS( ooNS::number,
"style" ) )
1729 if ( e.attributeNS( ooNS::number,
"style", TQString() ) ==
"long" )
1730 format->append(
"dddd" );
1732 format->append(
"ddd" );
1735 format->append(
"ddd" );
1737 else if ( e.localName() ==
"day" && e.namespaceURI()==ooNS::number)
1739 if ( e.hasAttributeNS( ooNS::number,
"style" ) )
1741 if ( e.attributeNS( ooNS::number,
"style", TQString() ) ==
"long" )
1742 format->append(
"dd" );
1744 format->append(
"d" );
1747 format->append(
"d" );
1749 else if ( e.localName() ==
"month" && e.namespaceURI()==ooNS::number)
1751 if ( e.hasAttributeNS( ooNS::number,
"textual" ) )
1753 if ( e.attributeNS( ooNS::number,
"textual", TQString() ) ==
"true" )
1754 format->append(
"mm" );
1757 if ( e.hasAttributeNS( ooNS::number,
"style" ) )
1759 if ( e.attributeNS( ooNS::number,
"style", TQString() ) ==
"long" )
1760 format->append(
"mm" );
1762 format->append(
"m" );
1765 format->append(
"m" );
1767 else if ( e.localName() ==
"year" && e.namespaceURI()==ooNS::number)
1769 if ( e.hasAttributeNS( ooNS::number,
"style" ) )
1771 if ( e.attributeNS( ooNS::number,
"style", TQString() ) ==
"long" )
1772 format->append(
"yyyy" );
1774 format->append(
"yy" );
1777 format->append(
"yy" );
1779 else if ( e.localName() ==
"hours" && e.namespaceURI()==ooNS::number)
1781 if ( e.hasAttributeNS( ooNS::number,
"style" ) )
1783 if ( e.attributeNS( ooNS::number,
"style", TQString() ) ==
"long" )
1784 format->append(
"hh" );
1786 format->append(
"h" );
1789 format->append(
"h" );
1791 else if ( e.localName() ==
"minutes" && e.namespaceURI()==ooNS::number)
1793 if ( e.hasAttributeNS( ooNS::number,
"style" ) )
1795 if ( e.attributeNS( ooNS::number,
"style", TQString() ) ==
"long" )
1796 format->append(
"mm" );
1798 format->append(
"m" );
1801 format->append(
"m" );
1803 else if ( e.localName() ==
"seconds" && e.namespaceURI()==ooNS::number)
1805 if ( e.hasAttributeNS( ooNS::number,
"style" ) )
1807 if ( e.attributeNS( ooNS::number,
"style", TQString() ) ==
"long" )
1808 format->append(
"ss" );
1810 format->append(
"s" );
1813 format->append(
"s" );
1815 else if ( e.localName() ==
"am-pm" && e.namespaceURI()==ooNS::number)
1817 format->append(
"AM/PM" );
1819 else if ( e.localName() ==
"number" && e.namespaceURI()==ooNS::number)
1823 if ( e.hasAttributeNS( ooNS::number,
"decimal-places" ) )
1825 int d = e.attributeNS( ooNS::number,
"decimal-places", TQString() ).toInt( &ok );
1830 if ( e.hasAttributeNS( ooNS::number,
"min-integer-digits" ) )
1832 int d = e.attributeNS( ooNS::number,
"min-integer-digits", TQString() ).toInt( &ok );
1837 if ( thousandsSep && leadingZ <= 3 )
1839 format->append(
"#," );
1840 for ( i = leadingZ; i <= 3; ++i )
1841 format->append(
'#' );
1844 for ( i = 1; i <= leadingZ; ++i )
1846 format->append(
'0' );
1847 if ( ( i % 3 == 0 ) && thousandsSep )
1848 format->append(
',' );
1851 format->append(
'.' );
1852 for ( i = 0; i < precision; ++i )
1853 format->append(
'0' );
1855 else if ( e.localName() ==
"scientific-number" && e.namespaceURI()==ooNS::number)
1859 if ( e.hasAttributeNS( ooNS::number,
"decimal-places" ) )
1861 int d = e.attributeNS( ooNS::number,
"decimal-places", TQString() ).toInt( &ok );
1866 if ( e.hasAttributeNS( ooNS::number,
"min-integer-digits" ) )
1868 int d = e.attributeNS( ooNS::number,
"min-integer-digits", TQString() ).toInt( &ok );
1873 if ( e.hasAttributeNS( ooNS::number,
"min-exponent-digits" ) )
1875 int d = e.attributeNS( ooNS::number,
"min-exponent-digits", TQString() ).toInt( &ok );
1882 if ( thousandsSep && leadingZ <= 3 )
1884 format->append(
"#," );
1885 for ( i = leadingZ; i <= 3; ++i )
1886 format->append(
'#' );
1889 for ( i = 1; i <= leadingZ; ++i )
1891 format->append(
'0' );
1892 if ( ( i % 3 == 0 ) && thousandsSep )
1893 format->append(
',' );
1896 format->append(
'.' );
1897 for ( i = 0; i < precision; ++i )
1898 format->append(
'0' );
1900 format->append(
"E+" );
1901 for ( i = 0; i < exp; ++i )
1902 format->append(
'0' );
1904 formatType = Custom_format;
1906 else if ( e.localName() ==
"fraction" && e.namespaceURI()==ooNS::number)
1910 int denominator = 1;
1912 if ( e.hasAttributeNS( ooNS::number,
"min-integer-digits" ) )
1914 int d = e.attributeNS( ooNS::number,
"min-integer-digits", TQString() ).toInt( &ok );
1918 if ( e.hasAttributeNS( ooNS::number,
"min-numerator-digits" ) )
1920 int d = e.attributeNS( ooNS::number,
"min-numerator-digits", TQString() ).toInt( &ok );
1924 if ( e.hasAttributeNS( ooNS::number,
"min-denominator-digits" ) )
1926 int d = e.attributeNS( ooNS::number,
"min-denominator-digits", TQString() ).toInt( &ok );
1931 for ( i = 0; i <= integer; ++i )
1932 format->append(
'#' );
1934 format->append(
' ' );
1936 for ( i = 0; i <= numerator; ++i )
1937 format->append(
'?' );
1939 format->append(
'/' );
1941 for ( i = 0; i <= denominator; ++i )
1942 format->append(
'?' );
1948 e = e.nextSibling().toElement();
1953 TQString f( *format );
1954 format->append(
";[Red]" );
1955 format->append( f );
1958 kdDebug(30518) <<
"*** New FormatString: " << *format << endl << endl;
1960 m_formats.insert( name, format );
1965void OpenCalcImport::loadFontStyle(
Format * layout, TQDomElement
const * font )
const
1967 if ( !font || !layout )
1970 kdDebug(30518) <<
"Copy font style from the layout " << font->tagName() <<
", " << font->nodeName() << endl;
1972 if ( font->hasAttributeNS( ooNS::fo,
"font-family" ) )
1973 layout->setTextFontFamily( font->attributeNS( ooNS::fo,
"font-family", TQString() ) );
1974 if ( font->hasAttributeNS( ooNS::fo,
"color" ) )
1975 layout->setTextColor( TQColor( font->attributeNS( ooNS::fo,
"color", TQString() ) ) );
1976 if ( font->hasAttributeNS( ooNS::fo,
"font-size" ) )
1977 layout->setTextFontSize(
int( KoUnit::parseValue( font->attributeNS( ooNS::fo,
"font-size", TQString() ), 10 ) ) );
1979 layout->setTextFontSize( 10 );
1980 if ( font->hasAttributeNS( ooNS::fo,
"font-style" ) )
1982 kdDebug(30518) <<
"italic" << endl;
1983 layout->setTextFontItalic(
true );
1985 if ( font->hasAttributeNS( ooNS::fo,
"font-weight" ) )
1986 layout->setTextFontBold(
true );
1987 if ( font->hasAttributeNS( ooNS::fo,
"text-underline" ) || font->hasAttributeNS( ooNS::style,
"text-underline" ) )
1988 layout->setTextFontUnderline(
true );
1989 if ( font->hasAttributeNS( ooNS::style,
"text-crossing-out" ) )
1990 layout->setTextFontStrike(
true );
1991 if ( font->hasAttributeNS( ooNS::style,
"font-pitch" ) )
1999void OpenCalcImport::loadBorder(
Format * layout, TQString
const & borderDef, bPos pos )
const
2001 if ( borderDef ==
"none" )
2004 int p = borderDef.find(
' ' );
2009 TQString w = borderDef.left( p );
2010 pen.setWidth( (
int) KoUnit::parseValue( w ) );
2014 int p2 = borderDef.find(
' ', p );
2015 TQString s = borderDef.mid( p, p2 - p );
2017 kdDebug(30518) <<
"Borderstyle: " << s << endl;
2019 if ( s ==
"solid" || s ==
"double" )
2020 pen.setStyle( TQt::SolidLine );
2025 pen.setStyle( TQt::DashLine );
2026 pen.setStyle( TQt::DotLine );
2027 pen.setStyle( TQt::DashDotLine );
2028 pen.setStyle( TQt::DashDotDotLine );
2030 pen.setStyle( TQt::SolidLine );
2034 p = borderDef.find(
' ', p2 );
2036 p = borderDef.length();
2038 pen.setColor( TQColor( borderDef.right( p - p2 ) ) );
2041 layout->setLeftBorderPen( pen );
2042 else if ( pos == Top )
2043 layout->setTopBorderPen( pen );
2044 else if ( pos == Right )
2045 layout->setRightBorderPen( pen );
2046 else if ( pos == Bottom )
2047 layout->setBottomBorderPen( pen );
2048 else if ( pos == Border )
2050 layout->setLeftBorderPen( pen );
2051 layout->setTopBorderPen( pen );
2052 layout->setRightBorderPen( pen );
2053 layout->setBottomBorderPen( pen );
2058void OpenCalcImport::loadStyleProperties(
Format * layout, TQDomElement
const & property )
const
2060 kdDebug(30518) <<
"*** Loading style properties *****" << endl;
2062 if ( property.hasAttributeNS( ooNS::style,
"decimal-places" ) )
2065 int p =
property.attributeNS( ooNS::style,
"decimal-places", TQString() ).toInt( &ok );
2067 layout->setPrecision( p );
2070 if ( property.hasAttributeNS( ooNS::style,
"font-name" ) )
2072 TQDomElement * font = m_styles[
property.attributeNS( ooNS::style,
"font-name", TQString() ) ];
2073 loadFontStyle( layout, font );
2076 loadFontStyle( layout, &property );
2088 if ( property.hasAttributeNS( ooNS::style,
"rotation-angle" ) )
2091 int a =
property.attributeNS( ooNS::style,
"rotation-angle", TQString() ).toInt( &ok );
2093 layout->setAngle( -a + 1 );
2096 if ( property.hasAttributeNS( ooNS::fo,
"direction" ) )
2098 layout->setVerticalText(
true );
2100 if ( property.hasAttributeNS( ooNS::fo,
"text-align" ) )
2102 TQString s =
property.attributeNS( ooNS::fo,
"text-align", TQString() );
2103 if ( s ==
"center" )
2104 layout->
setAlign( Format::Center );
2105 else if ( s ==
"end" )
2107 else if ( s ==
"start" )
2109 else if ( s ==
"justify" )
2110 layout->
setAlign( Format::Center );
2112 if ( property.hasAttributeNS( ooNS::fo,
"margin-left" ) )
2114 kdDebug(30518)<<
"margin-left :"<<KoUnit::parseValue( property.attributeNS( ooNS::fo,
"margin-left", TQString() ),0.0 )<<endl;
2115 layout->setIndent( KoUnit::parseValue( property.attributeNS( ooNS::fo,
"margin-left", TQString() ),0.0 ) );
2117 if ( property.hasAttributeNS( ooNS::fo,
"background-color" ) )
2118 layout->setBgColor( TQColor( property.attributeNS( ooNS::fo,
"background-color", TQString() ) ) );
2120 if ( property.hasAttributeNS( ooNS::style,
"print-content" ) )
2122 if ( property.attributeNS( ooNS::style,
"print-content", TQString() ) ==
"false" )
2123 layout->setDontPrintText(
false );
2125 if ( property.hasAttributeNS( ooNS::style,
"cell-protect" ) )
2127 TQString prot( property.attributeNS( ooNS::style,
"cell-protect", TQString() ) );
2128 if ( prot ==
"none" )
2130 layout->setNotProtected(
true );
2131 layout->setHideFormula(
false );
2132 layout->setHideAll(
false );
2134 else if ( prot ==
"formula-hidden" )
2136 layout->setNotProtected(
true );
2137 layout->setHideFormula(
true );
2138 layout->setHideAll(
false );
2140 else if ( prot ==
"protected formula-hidden" )
2142 layout->setNotProtected(
false );
2143 layout->setHideFormula(
true );
2144 layout->setHideAll(
false );
2146 else if ( prot ==
"hidden-and-protected" )
2148 layout->setNotProtected(
false );
2149 layout->setHideFormula(
false );
2150 layout->setHideAll(
true );
2152 else if ( prot ==
"protected" )
2154 layout->setNotProtected(
false );
2155 layout->setHideFormula(
false );
2156 layout->setHideAll(
false );
2158 kdDebug(30518) <<
"Cell " << prot << endl;
2161 if ( property.hasAttributeNS( ooNS::fo,
"padding-left" ) )
2162 layout->setIndent( KoUnit::parseValue(property.attributeNS( ooNS::fo,
"padding-left", TQString() ) ) );
2164 if ( property.hasAttributeNS( ooNS::fo,
"vertical-align" ) )
2166 TQString s =
property.attributeNS( ooNS::fo,
"vertical-align", TQString() );
2167 if ( s ==
"middle" )
2168 layout->setAlignY( Format::Middle );
2169 else if ( s ==
"bottom" )
2170 layout->setAlignY( Format::Bottom );
2172 layout->setAlignY( Format::Top );
2175 layout->setAlignY( Format::Bottom );
2177 if ( property.hasAttributeNS( ooNS::fo,
"wrap-option" ) )
2179 layout->setMultiRow(
true );
2188 if ( property.hasAttributeNS( ooNS::fo,
"border-bottom" ) )
2190 loadBorder( layout, property.attributeNS( ooNS::fo,
"border-bottom", TQString() ), Bottom );
2194 if ( property.hasAttributeNS( ooNS::fo,
"border-right" ) )
2196 loadBorder( layout, property.attributeNS( ooNS::fo,
"border-right", TQString() ), Right );
2200 if ( property.hasAttributeNS( ooNS::fo,
"border-top" ) )
2202 loadBorder( layout, property.attributeNS( ooNS::fo,
"border-top", TQString() ), Top );
2206 if ( property.hasAttributeNS( ooNS::fo,
"border-left" ) )
2208 loadBorder( layout, property.attributeNS( ooNS::fo,
"border-left", TQString() ), Left );
2212 if ( property.hasAttributeNS( ooNS::fo,
"border" ) )
2214 loadBorder( layout, property.attributeNS( ooNS::fo,
"border", TQString() ), Border );
2219void OpenCalcImport::readInStyle(
Format * layout, TQDomElement
const & style )
2221 kdDebug(30518) <<
"** Reading Style: " << style.tagName() <<
"; " << style.attributeNS( ooNS::style,
"name", TQString()) << endl;
2222 if ( style.localName() ==
"style" && style.namespaceURI()==ooNS::style)
2224 if ( style.hasAttributeNS( ooNS::style,
"parent-style-name" ) )
2227 = m_defaultStyles.find( style.attributeNS( ooNS::style,
"parent-style-name", TQString() ) );
2228 kdDebug(30518) <<
"Copying layout from " << style.attributeNS( ooNS::style,
"parent-style-name", TQString() ) << endl;
2231 layout->copy( *cp );
2233 else if ( style.hasAttributeNS( ooNS::style,
"family") )
2235 TQString name = style.attribute(
"style-family" ) +
"default";
2236 Format * cp = m_defaultStyles.find( name );
2238 kdDebug(30518) <<
"Copying layout from " << name <<
", " << !cp << endl;
2241 layout->copy( *cp );
2244 if ( style.hasAttributeNS( ooNS::style,
"data-style-name" ) )
2246 TQString * format = m_formats[ style.attributeNS( ooNS::style,
"data-style-name", TQString() ) ];
2247 FormatType formatType;
2252 TQString name( style.attributeNS( ooNS::style,
"data-style-name", TQString() ) );
2253 format = loadFormat( m_styles[ name ], formatType, name );
2258 layout->setFormatString( *format );
2259 layout->setFormatType( formatType );
2266 TQDomElement property;
2267 forEachElement( property, style )
2269 if ( property.localName() ==
"properties" && property.namespaceURI() == ooNS::style )
2270 loadStyleProperties( layout, property );
2272 kdDebug(30518) << layout->textFontFamily( 0, 0 ) << endl;
2276bool OpenCalcImport::createStyleMap( TQDomDocument
const & styles )
2278 TQDomElement content = styles.documentElement();
2279 TQDomNode docStyles = KoDom::namedItemNS( content, ooNS::office,
"document-styles" );
2281 if ( content.hasAttributeNS( ooNS::office,
"version" ) )
2284 double d = content.attributeNS( ooNS::office,
"version", TQString() ).toDouble( &ok );
2288 kdDebug(30518) <<
"OpenCalc version: " << d << endl;
2291 TQString message( i18n(
"This document was created with OpenOffice.org version '%1'. This filter was written for version 1.0. Reading this file could cause strange behavior, crashes or incorrect display of the data. Do you want to continue converting the document?") );
2292 message.arg( content.attributeNS( ooNS::office,
"version", TQString() ) );
2293 if ( KMessageBox::warningYesNo( 0, message, i18n(
"Unsupported document version" ) ) == KMessageBox::No )
2299 TQDomNode fontStyles = KoDom::namedItemNS( content, ooNS::office,
"font-decls" );
2301 if ( !fontStyles.isNull() )
2303 kdDebug(30518) <<
"Starting reading in font-decl..." << endl;
2305 insertStyles( fontStyles.toElement() );
2308 kdDebug(30518) <<
"No items found" << endl;
2310 kdDebug(30518) <<
"Starting reading in auto:styles" << endl;
2312 TQDomNode autoStyles = KoDom::namedItemNS( content, ooNS::office,
"automatic-styles" );
2313 if ( !autoStyles.isNull() )
2314 insertStyles( autoStyles.toElement() );
2316 kdDebug(30518) <<
"No items found" << endl;
2319 kdDebug(30518) <<
"Reading in master styles" << endl;
2321 TQDomNode masterStyles = KoDom::namedItemNS( content, ooNS::office,
"master-styles" );
2323 if ( masterStyles.isNull() )
2325 kdDebug(30518) <<
"Nothing found " << endl;
2328 TQDomElement master = KoDom::namedItemNS( masterStyles, ooNS::style,
"master-page");
2329 if ( !master.isNull() )
2331 TQString name(
"pm" );
2332 name += master.attributeNS( ooNS::style,
"name", TQString() );
2333 kdDebug(30518) <<
"Master style: '" << name <<
"' loaded " << endl;
2334 m_styles.insert( name,
new TQDomElement( master ) );
2336 master = master.nextSibling().toElement();
2340 kdDebug(30518) <<
"Starting reading in office:styles" << endl;
2342 TQDomNode fixedStyles = KoDom::namedItemNS( content, ooNS::office,
"styles" );
2344 kdDebug(30518) <<
"Reading in default styles" << endl;
2346 TQDomNode def = KoDom::namedItemNS( fixedStyles, ooNS::style,
"default-style" );
2347 kdDebug()<<
" def !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :"<<def.isNull()<<endl;
2348 while ( !def.isNull() )
2350 TQDomElement e = def.toElement();
2351 kdDebug(30518) <<
"Style found " << e.nodeName() <<
", tag: " << e.tagName() << endl;
2353 if ( e.nodeName() !=
"style:default-style" )
2355 def = def.nextSibling();
2361 Format * layout =
new Format( 0, m_doc->styleManager()->defaultStyle() );
2363 readInStyle( layout, e );
2364 kdDebug(30518) <<
"Default style " << e.attributeNS( ooNS::style,
"family", TQString() ) <<
"default" <<
" loaded " << endl;
2366 m_defaultStyles.insert( e.attributeNS( ooNS::style,
"family", TQString() ) +
"default", layout );
2371 def = def.nextSibling();
2374 TQDomElement defs = KoDom::namedItemNS( fixedStyles, ooNS::style,
"style" );
2375 while ( !defs.isNull() )
2377 if ( defs.nodeName() !=
"style:style" )
2380 if ( !defs.hasAttributeNS( ooNS::style,
"name" ) )
2383 defs = defs.nextSibling().toElement();
2387 Format * layout =
new Format( 0, m_doc->styleManager()->defaultStyle() );
2388 readInStyle( layout, defs );
2389 kdDebug(30518) <<
"Default style " << defs.attributeNS( ooNS::style,
"name", TQString() ) <<
" loaded " << endl;
2391 m_defaultStyles.insert( defs.attributeNS( ooNS::style,
"name", TQString() ), layout );
2394 defs = defs.nextSibling().toElement();
2397 if ( !fixedStyles.isNull() )
2398 insertStyles( fixedStyles.toElement() );
2400 kdDebug(30518) <<
"Starting reading in automatic styles" << endl;
2402 content = m_content.documentElement();
2403 autoStyles = KoDom::namedItemNS( content, ooNS::office,
"automatic-styles" );
2405 if ( !autoStyles.isNull() )
2406 insertStyles( autoStyles.toElement() );
2408 fontStyles = KoDom::namedItemNS( content, ooNS::office,
"font-decls" );
2410 if ( !fontStyles.isNull() )
2412 kdDebug(30518) <<
"Starting reading in special font decl" << endl;
2414 insertStyles( fontStyles.toElement() );
2417 kdDebug(30518) <<
"Styles read in." << endl;
2422void OpenCalcImport::loadOasisValidation( Validity* val,
const TQString& validationName )
2424 kdDebug(30518)<<
"validationName:"<<validationName<<endl;
2425 TQDomElement element = m_validationList[validationName];
2426 if ( element.hasAttributeNS( ooNS::table,
"condition" ) )
2428 TQString valExpression = element.attributeNS( ooNS::table,
"condition", TQString() );
2429 kdDebug(30518)<<
" element.attribute( table:condition ) "<<valExpression<<endl;
2443 if ( valExpression.contains(
"cell-content-text-length()" ) )
2446 valExpression = valExpression.remove(
"cell-content-text-length()" );
2447 kdDebug(30518)<<
" valExpression = :"<<valExpression<<endl;
2448 val->m_restriction = Restriction::TextLength;
2450 loadOasisValidationCondition( val, valExpression );
2453 else if ( valExpression.contains(
"cell-content-text-length-is-between" ) )
2455 val->m_restriction = Restriction::TextLength;
2456 val->m_cond = Conditional::Between;
2457 valExpression = valExpression.remove(
"cell-content-text-length-is-between(" );
2458 kdDebug(30518)<<
" valExpression :"<<valExpression<<endl;
2459 valExpression = valExpression.remove(
")" );
2460 TQStringList listVal = TQStringList::split(
",", valExpression );
2461 loadOasisValidationValue( val, listVal );
2463 else if ( valExpression.contains(
"cell-content-text-length-is-not-between" ) )
2465 val->m_restriction = Restriction::TextLength;
2466 val->m_cond = Conditional::Different;
2467 valExpression = valExpression.remove(
"cell-content-text-length-is-not-between(" );
2468 kdDebug(30518)<<
" valExpression :"<<valExpression<<endl;
2469 valExpression = valExpression.remove(
")" );
2470 kdDebug(30518)<<
" valExpression :"<<valExpression<<endl;
2471 TQStringList listVal = TQStringList::split(
",", valExpression );
2472 loadOasisValidationValue( val, listVal );
2478 if (valExpression.contains(
"cell-content-is-whole-number()" ) )
2480 val->m_restriction = Restriction::Number;
2481 valExpression = valExpression.remove(
"cell-content-is-whole-number() and " );
2483 else if (valExpression.contains(
"cell-content-is-decimal-number()" ) )
2485 val->m_restriction = Restriction::Integer;
2486 valExpression = valExpression.remove(
"cell-content-is-decimal-number() and " );
2488 else if (valExpression.contains(
"cell-content-is-date()" ) )
2490 val->m_restriction = Restriction::Date;
2491 valExpression = valExpression.remove(
"cell-content-is-date() and " );
2493 else if (valExpression.contains(
"cell-content-is-time()" ) )
2495 val->m_restriction = Restriction::Time;
2496 valExpression = valExpression.remove(
"cell-content-is-time() and " );
2498 kdDebug(30518)<<
"valExpression :"<<valExpression<<endl;
2500 if ( valExpression.contains(
"cell-content()" ) )
2502 valExpression = valExpression.remove(
"cell-content()" );
2503 loadOasisValidationCondition( val, valExpression );
2507 if ( valExpression.contains(
"cell-content-is-between(" ) )
2509 valExpression = valExpression.remove(
"cell-content-is-between(" );
2510 valExpression = valExpression.remove(
")" );
2511 TQStringList listVal = TQStringList::split(
"," , valExpression );
2512 loadOasisValidationValue( val, listVal );
2514 val->m_cond = Conditional::Between;
2516 if ( valExpression.contains(
"cell-content-is-not-between(" ) )
2518 valExpression = valExpression.remove(
"cell-content-is-not-between(" );
2519 valExpression = valExpression.remove(
")" );
2520 TQStringList listVal = TQStringList::split(
",", valExpression );
2521 loadOasisValidationValue( val, listVal );
2522 val->m_cond = Conditional::Different;
2526 if ( element.hasAttributeNS( ooNS::table,
"allow-empty-cell" ) )
2528 val->allowEmptyCell = ( ( element.attributeNS( ooNS::table,
"allow-empty-cell", TQString() )==
"true" ) ?
true :
false );
2531 if ( element.hasAttributeNS( ooNS::table,
"base-cell-address" ) )
2536 TQDomElement help = KoDom::namedItemNS( element, ooNS::table,
"help-message" );
2537 if ( !help.isNull() )
2539 if ( help.hasAttributeNS( ooNS::table,
"title" ) )
2540 val->titleInfo = help.attributeNS( ooNS::table,
"title", TQString() );
2541 if ( help.hasAttributeNS( ooNS::table,
"display" ) )
2542 val->displayValidationInformation = ( ( help.attributeNS( ooNS::table,
"display", TQString() )==
"true" ) ?
true :
false );
2543 TQDomElement attrText = KoDom::namedItemNS( help, ooNS::text,
"p" );
2544 if ( !attrText.isNull() )
2545 val->messageInfo = attrText.text();
2548 TQDomElement error = KoDom::namedItemNS( element, ooNS::table,
"error-message" );
2549 if ( !error.isNull() )
2551 if ( error.hasAttributeNS( ooNS::table,
"title" ) )
2552 val->title = error.attributeNS( ooNS::table,
"title", TQString() );
2553 if ( error.hasAttributeNS( ooNS::table,
"message-type" ) )
2555 TQString str = error.attributeNS( ooNS::table,
"message-type", TQString() );
2556 if ( str ==
"warning" )
2557 val->m_action = Action::Warning;
2558 else if ( str ==
"information" )
2559 val->m_action = Action::Information;
2560 else if ( str ==
"stop" )
2561 val->m_action = Action::Stop;
2563 kdDebug(30518)<<
"validation : message type unknown :"<<str<<endl;
2566 if ( error.hasAttributeNS( ooNS::table,
"display" ) )
2568 kdDebug(30518)<<
" display message :"<<error.attributeNS( ooNS::table,
"display", TQString() )<<endl;
2569 val->displayMessage = (error.attributeNS( ooNS::table,
"display", TQString() )==
"true");
2571 TQDomElement attrText = KoDom::namedItemNS( error, ooNS::text,
"p" );
2572 if ( !attrText.isNull() )
2573 val->message = attrText.text();
2577void OpenCalcImport::loadOasisValidationValue( Validity* val,
const TQStringList &listVal )
2580 kdDebug(30518)<<
" listVal[0] :"<<listVal[0]<<
" listVal[1] :"<<listVal[1]<<endl;
2582 if ( val->m_restriction == Restriction::Date )
2584 val->dateMin = TQDate::fromString( listVal[0] );
2585 val->dateMax = TQDate::fromString( listVal[1] );
2587 else if ( val->m_restriction == Restriction::Time )
2589 val->timeMin = TQTime::fromString( listVal[0] );
2590 val->timeMax = TQTime::fromString( listVal[1] );
2594 val->valMin = listVal[0].toDouble(&ok);
2597 val->valMin = listVal[0].toInt(&ok);
2599 kdDebug(30518)<<
" Try to parse this value :"<<listVal[0]<<endl;
2603 val->valMin = listVal[0];
2607 val->valMax = listVal[1].toDouble(&ok);
2610 val->valMax = listVal[1].toInt(&ok);
2612 kdDebug(30518)<<
" Try to parse this value :"<<listVal[1]<<endl;
2616 val->valMax = listVal[1];
2623void OpenCalcImport::loadOasisValidationCondition( Validity* val,TQString &valExpression )
2626 if (valExpression.contains(
"<=" ) )
2628 value = valExpression.remove(
"<=" );
2629 val->m_cond = Conditional::InferiorEqual;
2631 else if (valExpression.contains(
">=" ) )
2633 value = valExpression.remove(
">=" );
2634 val->m_cond = Conditional::SuperiorEqual;
2636 else if (valExpression.contains(
"!=" ) )
2639 value = valExpression.remove(
"!=" );
2640 val->m_cond = Conditional::DifferentTo;
2642 else if ( valExpression.contains(
"<" ) )
2644 value = valExpression.remove(
"<" );
2645 val->m_cond = Conditional::Inferior;
2647 else if(valExpression.contains(
">" ) )
2649 value = valExpression.remove(
">" );
2650 val->m_cond = Conditional::Superior;
2652 else if (valExpression.contains(
"=" ) )
2654 value = valExpression.remove(
"=" );
2655 val->m_cond = Conditional::Equal;
2658 kdDebug(30518)<<
" I don't know how to parse it :"<<valExpression<<endl;
2659 kdDebug(30518)<<
" value :"<<value<<endl;
2660 if ( val->m_restriction == Restriction::Date )
2662 val->dateMin = TQDate::fromString( value );
2664 else if ( val->m_restriction == Restriction::Date )
2666 val->timeMin = TQTime::fromString( value );
2671 val->valMin = value.toDouble(&ok);
2674 val->valMin = value.toInt(&ok);
2676 kdDebug(30518)<<
" Try to parse this value :"<<value<<endl;
2680 val->valMin = value;
2687int OpenCalcImport::readMetaData()
2690 KoDocumentInfo * docInfo = m_doc->documentInfo();
2691 KoDocumentInfoAbout * aboutPage =
static_cast<KoDocumentInfoAbout *
>(docInfo->page(
"about" ));
2692 KoDocumentInfoAuthor * authorPage =
static_cast<KoDocumentInfoAuthor*
>(docInfo->page(
"author" ));
2694 TQDomNode meta = KoDom::namedItemNS( m_meta, ooNS::office,
"document-meta" );
2695 TQDomNode office = KoDom::namedItemNS( meta, ooNS::office,
"meta" );
2697 if ( office.isNull() )
2700 TQDomElement e = KoDom::namedItemNS( office, ooNS::dc,
"creator" );
2701 if ( !e.isNull() && !e.text().isEmpty() )
2702 authorPage->setFullName( e.text() );
2704 e = KoDom::namedItemNS( office, ooNS::dc,
"title" );
2705 if ( !e.isNull() && !e.text().isEmpty() )
2706 aboutPage->setTitle( e.text() );
2708 e = KoDom::namedItemNS( office, ooNS::dc,
"description" );
2709 if ( !e.isNull() && !e.text().isEmpty() )
2710 aboutPage->setAbstract( e.text() );
2712 e = KoDom::namedItemNS( office, ooNS::dc,
"subject" );
2713 if ( !e.isNull() && !e.text().isEmpty() )
2714 aboutPage->setSubject( e.text() );
2716 e= KoDom::namedItemNS( office, ooNS::meta,
"keywords" );
2719 e = KoDom::namedItemNS( e, ooNS::meta,
"keyword" );
2720 if ( !e.isNull() && !e.text().isEmpty() )
2721 aboutPage->setKeywords( e.text() );
2724 e = KoDom::namedItemNS( office, ooNS::meta,
"document-statistic" );
2725 if ( !e.isNull() && e.hasAttributeNS( ooNS::meta,
"table-count" ) )
2728 result = e.attributeNS( ooNS::meta,
"table-count", TQString() ).toInt( &ok );
2738KoFilter::ConversionStatus OpenCalcImport::convert( TQCString
const & from, TQCString
const & to )
2740 kdDebug(30518) <<
"Entering OpenCalc Import filter: " << from <<
" - " << to << endl;
2742 KoDocument * document = m_chain->outputDocument();
2744 return KoFilter::StupidError;
2746 if ( !::tqt_cast<const KSpread::Doc *>( document ) )
2748 kdWarning(30518) <<
"document isn't a KSpread::Doc but a " << document->className() << endl;
2749 return KoFilter::NotImplemented;
2752 if ( ( from !=
"application/vnd.sun.xml.calc" && from !=
"application/vnd.sun.xml.calc.template") || to !=
"application/x-kspread" )
2754 kdWarning(30518) <<
"Invalid mimetypes " << from <<
" " << to << endl;
2755 return KoFilter::NotImplemented;
2758 m_doc = ( Doc * ) document;
2760 if ( m_doc->mimeType() !=
"application/x-kspread" )
2762 kdWarning(30518) <<
"Invalid document mimetype " << m_doc->mimeType() << endl;
2763 return KoFilter::NotImplemented;
2766 kdDebug(30518) <<
"Opening file " << endl;
2768 KoFilter::ConversionStatus preStatus = openFile();
2770 if ( preStatus != KoFilter::OK )
2773 emit sigProgress( 13 );
2774 int tables = readMetaData();
2776 emit sigProgress( 15 );
2778 if ( !parseBody( tables ) )
2779 return KoFilter::StupidError;
2781 emit sigProgress( 100 );
2782 return KoFilter::OK;
2785KoFilter::ConversionStatus OpenCalcImport::openFile()
2787 KoStore * store = KoStore::createStore( m_chain->inputFile(), KoStore::Read);
2789 kdDebug(30518) <<
"Store created" << endl;
2793 kdWarning(30518) <<
"Couldn't open the requested file." << endl;
2794 return KoFilter::FileNotFound;
2797 kdDebug(30518) <<
"Trying to open content.xml" << endl;
2798 TQString messageError;
2799 loadAndParse( m_content,
"content.xml", store);
2800 kdDebug(30518) <<
"Opened" << endl;
2802 TQDomDocument styles;
2803 kdDebug(30518) <<
"file content.xml loaded " << endl;
2805 loadAndParse( styles,
"styles.xml", store);
2807 loadAndParse( m_meta,
"meta.xml", store);
2808 loadAndParse( m_settings,
"settings.xml", store);
2812 emit sigProgress( 10 );
2814 if ( !createStyleMap( styles ) )
2815 return KoFilter::UserCancelled;
2817 return KoFilter::OK;
2820KoFilter::ConversionStatus OpenCalcImport::loadAndParse( TQDomDocument& doc,
const TQString& fileName,KoStore *m_store )
2822 return OoUtils::loadAndParse( fileName, doc, m_store);
2825#include "opencalcimport.moc"