27#include <tqstringlist.h>
29#include <gnumericimport.h>
30#include <tdemessagebox.h>
31#include <kfilterdev.h>
33#include <kgenericfactory.h>
34#include <KoFilterChain.h>
38#include <kspread_doc.h>
39#include <kspread_map.h>
40#include <kspread_sheet.h>
41#include <kspread_sheetprint.h>
42#include <kspread_cell.h>
43#include <kspread_util.h>
44#include <KoDocumentInfo.h>
48#define SECS_PER_DAY 86400
49#define HALF_SEC (0.5 / SECS_PER_DAY)
51using namespace KSpread;
54static const int g_dateSerial_19000228 = 59;
56static int g_dateOrigin = 0;
59static char const * cell_format_date [] = {
96static char const * cell_format_time [] = {
111namespace gnumeric_import_LNS
117using namespace gnumeric_import_LNS;
119void GNUMERICFilter::dateInit()
123 g_dateOrigin = GnumericDate::greg2jul( 1900, 1, 1 ) - 1;
126uint GNUMERICFilter::GnumericDate::greg2jul(
int y,
int m,
int d )
128 return TQDate::gregorianToJulian( y, m, d );
131void GNUMERICFilter::GnumericDate::jul2greg(
double num,
int & y,
int & m,
int & d )
133 int i = (int) floor( num + HALF_SEC );
134 if (i > g_dateSerial_19000228)
136 else if (i == g_dateSerial_19000228 + 1)
137 kdWarning(30521) <<
"Request for date 02/29/1900." << endl;
139 kdDebug(30521) <<
"***** Num: " << num <<
", i: " << i << endl;
141 TQDate::julianToGregorian( i + g_dateOrigin, y, m, d );
142 kdDebug(30521) <<
"y: " << y <<
", m: " << m <<
", d: " << d << endl;
145TQTime GNUMERICFilter::GnumericDate::getTime(
double num )
149 int secs = tqRound( (num - floor(num)) * SECS_PER_DAY );
151 kdDebug(30521) <<
"***** Num: " << num <<
", secs " << secs << endl;
153 const int h = secs / 3600;
155 const int m = secs / 60;
158 kdDebug(30521) <<
"****** h: " << h <<
", m: " << m <<
", secs: " << secs << endl;
159 const TQTime time( h, m, ( secs < 0 || secs > 59 ? 0 : secs ) );
164typedef KGenericFactory<GNUMERICFilter, KoFilter> GNUMERICFilterFactory;
165K_EXPORT_COMPONENT_FACTORY( libgnumericimport, GNUMERICFilterFactory(
"kofficefilters" ) )
167GNUMERICFilter::GNUMERICFilter( KoFilter *, const
char *, const TQStringList & )
173void convert_string_to_qcolor(TQString color_string, TQColor * color)
175 int red, green, blue, first_col_pos, second_col_pos;
179 first_col_pos = color_string.find(
":", 0);
180 second_col_pos = color_string.find(
":", first_col_pos + 1);
187 red = color_string.mid( 0, first_col_pos).toInt( &number_ok, 16 ) >> 8;
188 green = color_string.mid(first_col_pos + 1,
189 (second_col_pos-first_col_pos) - 1).toInt( &number_ok, 16) >> 8;
190 blue = color_string.mid(second_col_pos + 1,
191 (color_string.length() - first_col_pos) - 1).toInt( &number_ok, 16) >> 8;
192 color->setRgb(red, green, blue);
195void areaNames( Doc * ksdoc,
const TQString &_name, TQString _zone )
199 int pos = _zone.find(
'!' );
202 tableName = _zone.left( pos );
203 _zone = _zone.right( _zone.length()-pos-1 );
204 pos = _zone.find(
':' );
208 TQString left = _zone.mid( 1, pos-1 );
209 TQString right = _zone.mid( pos+2, _zone.length()-pos-2 );
210 int pos = left.find(
'$' );
212 rect.setLeft( util_decodeColumnLabelText(left.left(pos ) ) );
213 rect.setTop( left.right( left.length()-pos-1 ).toInt() );
215 pos = right.find(
'$' );
216 rect.setRight( util_decodeColumnLabelText(right.left(pos ) ) );
217 rect.setBottom( right.right( right.length()-pos-1 ).toInt() );
221 TQString left = _zone;
222 int pos = left.find(
'$' );
223 int leftPos = util_decodeColumnLabelText(left.left(pos ) );
224 rect.setLeft( leftPos );
225 rect.setRight( leftPos );
227 int top = left.right( left.length()-pos-1 ).toInt();
229 rect.setBottom( top );
231 ksdoc->addAreaName( rect, _name ,tableName);
236void set_document_area_names( Doc * ksdoc, TQDomElement * docElem )
238 TQDomNode areaNamesElement = docElem->namedItem(
"gmr:Names" );
239 if ( areaNamesElement.isNull() )
241 TQDomNode areaNameItem = areaNamesElement.namedItem(
"gmr:Name" );
242 while ( !areaNameItem.isNull() )
244 TQDomNode gmr_name = areaNameItem.namedItem(
"gmr:name");
245 TQDomNode gmr_value = areaNameItem.namedItem(
"gmr:value");
246 TQString name = gmr_name.toElement().text();
247 areaNames( ksdoc, name, gmr_value.toElement().text() );
248 areaNameItem = areaNameItem.nextSibling();
254void set_document_attributes( Doc * ksdoc, TQDomElement * docElem)
256 ksdoc->loadConfigFromFile();
257 TQDomNode attributes = docElem->namedItem(
"gmr:Attributes");
258 if ( attributes.isNull() )
261 TQDomNode attributeItem = attributes.namedItem(
"gmr:Attribute");
262 while( !attributeItem.isNull() )
264 TQDomNode gmr_name = attributeItem.namedItem(
"gmr:name");
265 TQDomNode gmr_value = attributeItem.namedItem(
"gmr:value");
266 if (gmr_name.toElement().text() ==
"WorkbookView::show_horizontal_scrollbar")
268 ksdoc->setShowHorizontalScrollBar( gmr_value.toElement().text().lower()==
"true"?
true : false );
270 else if ( gmr_name.toElement().text() ==
"WorkbookView::show_vertical_scrollbar")
272 ksdoc->setShowVerticalScrollBar( gmr_value.toElement().text().lower()==
"true"?
true : false );
274 else if ( gmr_name.toElement().text() ==
"WorkbookView::show_notebook_tabs")
276 ksdoc->setShowTabBar(gmr_value.toElement().text().lower()==
"true"?
true : false );
278 else if ( gmr_name.toElement().text() ==
"WorkbookView::do_auto_completion")
280 ksdoc->setCompletionMode( TDEGlobalSettings::CompletionAuto);
282 else if ( gmr_name.toElement().text() ==
"WorkbookView::is_protected")
288 attributeItem = attributeItem.nextSibling();
295void set_document_info(KoDocument * document, TQDomElement * docElem)
298 TQDomNode summary = docElem->namedItem(
"gmr:Summary");
299 TQDomNode gmr_item = summary.namedItem(
"gmr:Item");
301 while( !gmr_item.isNull() )
303 TQDomNode gmr_name = gmr_item.namedItem(
"gmr:name");
304 TQDomNode gmr_value = gmr_item.namedItem(
"gmr:val-string");
306 KoDocumentInfo * DocumentInfo = document->documentInfo();
307 KoDocumentInfoAbout * aboutPage =
static_cast<KoDocumentInfoAbout *
>(DocumentInfo->page(
"about" ));
308 KoDocumentInfoAuthor * authorPage =
static_cast<KoDocumentInfoAuthor*
>(DocumentInfo->page(
"author" ));
311 if (gmr_name.toElement().text() ==
"title")
313 aboutPage->setTitle(gmr_value.toElement().text());
315 else if (gmr_name.toElement().text() ==
"keywords")
317 aboutPage->setKeywords( gmr_value.toElement().text());
319 else if (gmr_name.toElement().text() ==
"comments")
321 aboutPage->setAbstract(gmr_value.toElement().text());
323 else if (gmr_name.toElement().text() ==
"category")
327 else if (gmr_name.toElement().text() ==
"manager")
331 else if (gmr_name.toElement().text() ==
"application")
335 else if (gmr_name.toElement().text() ==
"author")
337 authorPage->setFullName(gmr_value.toElement().text());
339 else if (gmr_name.toElement().text() ==
"company")
341 authorPage->setCompany(gmr_value.toElement().text());
344 gmr_item = gmr_item.nextSibling();
351void setColInfo(TQDomNode * sheet, Sheet * table)
353 TQDomNode columns = sheet->namedItem(
"gmr:Cols");
354 TQDomNode columninfo = columns.namedItem(
"gmr:ColInfo");
356 TQDomElement def = columns.toElement();
357 if ( def.hasAttribute(
"DefaultSizePts" ) )
360 double d = def.attribute(
"DefaultSizePts" ).toDouble( &ok );
363 Format::setGlobalColWidth( d );
364 table->setDefaultWidth( d );
368 while( !columninfo.isNull() )
370 TQDomElement e = columninfo.toElement();
373 column_number = e.attribute(
"No").toInt()+1;
374 ColumnFormat *cl =
new ColumnFormat(table, column_number);
375 if (e.hasAttribute(
"Hidden"))
377 if (e.attribute(
"Hidden")==
"1")
382 if (e.hasAttribute(
"Unit"))
385 cl->setDblWidth(e.attribute(
"Unit").toDouble());
388 table->insertColumnFormat(cl);
389 columninfo = columninfo.nextSibling();
393void setRowInfo(TQDomNode *sheet, Sheet *table)
395 TQDomNode rows = sheet->namedItem(
"gmr:Rows");
396 TQDomNode rowinfo = rows.namedItem(
"gmr:RowInfo");
401 TQDomElement def = rows.toElement();
402 if ( def.hasAttribute(
"DefaultSizePts" ) )
404 d = def.attribute(
"DefaultSizePts" ).toDouble( &ok );
407 Format::setGlobalRowHeight( d );
408 table->setDefaultHeight( d );
412 while( !rowinfo.isNull() )
414 TQDomElement e = rowinfo.toElement();
416 row_number = e.attribute(
"No").toInt() + 1;
417 RowFormat *rl =
new RowFormat(table, row_number);
419 if (e.hasAttribute(
"Hidden"))
421 if (e.attribute(
"Hidden") ==
"1")
426 if (e.hasAttribute(
"Unit"))
428 double dbl = e.attribute(
"Unit" ).toDouble( &ok );
430 rl->setDblHeight( dbl );
432 table->insertRowFormat(rl);
433 rowinfo = rowinfo.nextSibling();
437void setSelectionInfo( TQDomNode * sheet, Sheet * )
439 TQDomNode selections = sheet->namedItem(
"gmr:Selections");
440 TQDomNode selection = selections.namedItem(
"gmr:Selection");
445 while( !selection.isNull() )
447 TQDomElement e = selection.toElement();
448 TQRect kspread_selection;
450 kspread_selection.setLeft((e.attribute(
"startCol").toInt() + 1));
451 kspread_selection.setTop((e.attribute(
"startRow").toInt() + 1));
452 kspread_selection.setRight((e.attribute(
"endCol").toInt() + 1));
453 kspread_selection.setBottom((e.attribute(
"endRow").toInt() + 1));
458 selection = selection.nextSibling();
463void setObjectInfo(TQDomNode * sheet, Sheet * table)
465 TQDomNode gmr_objects = sheet->namedItem(
"gmr:Objects");
466 TQDomNode gmr_cellcomment = gmr_objects.namedItem(
"gmr:CellComment");
467 while( !gmr_cellcomment.isNull() )
469 TQDomElement e = gmr_cellcomment.toElement();
470 if (e.hasAttribute(
"Text"))
472 if (e.hasAttribute(
"ObjectBound"))
474 Point point(e.attribute(
"ObjectBound"));
475 Cell * cell = table->nonDefaultCell( point.pos().x(), point.pos().y() );
476 cell->format()->setComment(e.attribute(
"Text"));
480 gmr_cellcomment = gmr_cellcomment.nextSibling();
484void convertToPen( TQPen & pen,
int style )
491 pen.setStyle( TQt::SolidLine );
495 pen.setStyle( TQt::SolidLine );
499 pen.setStyle( TQt::DashLine );
504 pen.setStyle( TQt::DotLine );
508 pen.setStyle( TQt::SolidLine );
513 pen.setStyle( TQt::SolidLine );
518 pen.setStyle( TQt::DotLine );
522 pen.setStyle( TQt::DashLine );
526 pen.setStyle( TQt::DashDotLine );
530 pen.setStyle( TQt::DashDotLine );
534 pen.setStyle( TQt::DashDotDotLine );
538 pen.setStyle( TQt::DashDotDotLine );
543 pen.setStyle( TQt::DashDotLine );
547 pen.setStyle( TQt::SolidLine );
552void GNUMERICFilter::ParseBorder( TQDomElement & gmr_styleborder, Cell * kspread_cell )
554 TQDomNode gmr_diagonal = gmr_styleborder.namedItem(
"gmr:Diagonal");
555 TQDomNode gmr_rev_diagonal = gmr_styleborder.namedItem(
"gmr:Rev-Diagonal");
556 TQDomNode gmr_top = gmr_styleborder.namedItem(
"gmr:Top");
557 TQDomNode gmr_bottom = gmr_styleborder.namedItem(
"gmr:Bottom");
558 TQDomNode gmr_left = gmr_styleborder.namedItem(
"gmr:Left");
559 TQDomNode gmr_right = gmr_styleborder.namedItem(
"gmr:Right");
570 if ( !gmr_left.isNull() )
572 TQDomElement e = gmr_left.toElement();
573 importBorder( e, Left, kspread_cell);
576 if ( !gmr_right.isNull() )
578 TQDomElement e = gmr_right.toElement();
579 importBorder( e, Right, kspread_cell);
582 if ( !gmr_top.isNull() )
584 TQDomElement e = gmr_top.toElement();
585 importBorder( e, Top, kspread_cell);
588 if ( !gmr_bottom.isNull() )
590 TQDomElement e = gmr_bottom.toElement();
591 importBorder( e, Bottom, kspread_cell);
594 if ( !gmr_diagonal.isNull() )
596 TQDomElement e = gmr_diagonal.toElement();
597 importBorder( e, Diagonal, kspread_cell);
600 if ( !gmr_rev_diagonal.isNull() )
602 TQDomElement e = gmr_rev_diagonal.toElement();
603 importBorder( e, Revdiagonal, kspread_cell);
610void GNUMERICFilter::importBorder( TQDomElement border, borderStyle _style, Cell *cell)
612 if ( !border.isNull() )
614 TQDomElement e = border.toElement();
615 if ( e.hasAttribute(
"Style" ) )
617 int style = e.attribute(
"Style" ).toInt();
620 convertToPen( pen, style );
627 cell->setLeftBorderPen( pen );
630 cell->setRightBorderPen( pen );
633 cell->setTopBorderPen( pen );
636 cell->setBottomBorderPen( pen );
639 cell->format()->setFallDiagonalPen( pen );
642 cell->format()->setGoUpDiagonalPen( pen );
646 if ( e.hasAttribute(
"Color" ) )
649 TQString colorString = e.attribute(
"Color" );
650 convert_string_to_qcolor( colorString, &color );
655 cell->format()->setLeftBorderColor( color );
658 cell->format()->setRightBorderColor( color );
661 cell->format()->setTopBorderColor( color );
664 cell->format()->setBottomBorderColor( color );
667 cell->format()->setFallDiagonalColor( color );
670 cell->format()->setGoUpDiagonalPen( color );
680bool GNUMERICFilter::setType( Cell * kspread_cell,
681 TQString
const & formatString,
682 TQString & cell_content )
685 for ( i = 0; cell_format_date[i] ; ++i )
687 kdDebug(30521) <<
"Cell_format: " << cell_format_date[i] <<
", FormatString: " << formatString << endl;
688 if ( ( formatString ==
"d/m/yy" ) || ( formatString == cell_format_date[i] ) )
690 kdDebug(30521) <<
" FormatString: Date: " << formatString <<
", CellContent: " << cell_content << endl;
692 if ( !kspread_cell->isDate() )
697 int val = cell_content.toInt( &ok );
699 kdDebug(30521) <<
"!!! FormatString: Date: " << formatString <<
", CellContent: " << cell_content
700 <<
", Double: " << val << endl;
704 GnumericDate::jul2greg( val, y, m, d );
705 kdDebug(30521) <<
" num: " << val <<
", y: " << y <<
", m: " << m <<
", d: " << d << endl;
707 date.setYMD( y, m, d );
710 date = kspread_cell->value().asDate();
715 case 0: type = date_format5;
break;
716 case 1: type = date_format6;
break;
717 case 2: type = date_format1;
break;
718 case 3: type = date_format2;
break;
719 case 4: type = date_format3;
break;
720 case 5: type = date_format4;
break;
721 case 6: type = date_format11;
break;
722 case 7: type = date_format12;
break;
723 case 8: type = date_format19;
break;
724 case 9: type = date_format18;
break;
725 case 10: type = date_format20;
break;
726 case 11: type = date_format21;
break;
727 case 16: type = date_format7;
break;
728 case 17: type = date_format22;
break;
729 case 18: type = date_format8;
break;
730 case 19: type = date_format9;
break;
731 case 22: type = date_format25;
break;
732 case 23: type = date_format14;
break;
733 case 24: type = date_format25;
break;
734 case 25: type = date_format26;
break;
735 case 26: type = date_format16;
break;
736 case 27: type = date_format15;
break;
737 case 28: type = date_format16;
break;
738 case 29: type = date_format15;
break;
739 case 30: type = date_format24;
break;
740 case 31: type = date_format23;
break;
742 type = ShortDate_format;
747 kdDebug(30521) <<
"i: " << i <<
", Type: " << type <<
", Date: " << TQString(date.toString()) << endl;
749 kspread_cell->setValue( date );
750 kspread_cell->format()->setFormatType( type );
756 for ( i = 0; cell_format_time[i] ; ++i )
758 if (formatString == cell_format_time[i])
762 if ( !kspread_cell->isTime() )
765 double content = cell_content.toDouble( &ok );
767 kdDebug(30521) <<
" FormatString: Time: " << formatString <<
", CellContent: " << cell_content
768 <<
", Double: " << content << endl;
773 time = GnumericDate::getTime( content );
776 time = kspread_cell->value().asTime();
781 case 0: type = Time_format1;
break;
782 case 1: type = Time_format2;
break;
783 case 2: type = Time_format4;
break;
784 case 3: type = Time_format5;
break;
785 case 5: type = Time_format6;
break;
786 case 6: type = Time_format6;
break;
788 type = Time_format1;
break;
791 kdDebug(30521) <<
"i: " << i <<
", Type: " << type << endl;
792 kspread_cell->setValue( time );
793 kspread_cell->format()->setFormatType( type );
802TQString GNUMERICFilter::convertVars( TQString
const & str, Sheet * table )
const
804 TQString result( str );
805 uint count = list1.count();
808 list1 <<
"&[TAB]" <<
"&[DATE]" <<
"&[PAGE]"
809 <<
"&[PAGES]"<<
"&[TIME]" <<
"&[FILE]";
810 list2 <<
"<sheet>" <<
"<date>" <<
"<page>"
811 <<
"<pages>" <<
"<time>" <<
"<file>";
812 count = list1.count();
815 for ( uint i = 0; i < count; ++i )
817 int n = result.find( list1[i] );
821 kdDebug(30521) <<
"Found var: " << list1[i] << endl;
823 result = result.replace( list1[i], table->tableName() );
825 result = result.replace( list1[i], list2[i] );
832double GNUMERICFilter::parseAttribute(
const TQDomElement &_element )
834 TQString unit = _element.attribute(
"PrefUnit" );
836 double value = _element.attribute(
"Points").toFloat( &ok );
841 else if ( unit ==
"cm" )
842 return ( value/10.0 );
843 else if ( unit ==
"in" )
844 return MM_TO_INCH( value );
845 else if ( unit ==
"Pt" || unit ==
"Px" || unit ==
"points" )
846 return MM_TO_POINT( value );
851void GNUMERICFilter::ParsePrintInfo( TQDomNode
const & printInfo, Sheet * table )
853 kdDebug(30521) <<
"Parsing print info " << endl;
860 TQString paperSize(
"A4");
861 TQString orientation(
"Portrait");
862 TQString footLeft, footMiddle, footRight;
863 TQString headLeft, headMiddle, headRight;
865 TQDomNode margins( printInfo.namedItem(
"gmr:Margins") );
866 if ( !margins.isNull() )
868 TQDomElement top( margins.namedItem(
"gmr:top" ).toElement() );
870 ftop = parseAttribute( top );
872 TQDomElement bottom( margins.namedItem(
"gmr:bottom" ).toElement() );
873 if ( !bottom.isNull() )
874 fbottom= parseAttribute( bottom );
876 TQDomElement left( margins.namedItem(
"gmr:left" ).toElement() );
877 if ( !left.isNull() )
878 fleft = parseAttribute( left );
880 TQDomElement right( margins.namedItem(
"gmr:right" ).toElement() );
881 if ( !right.isNull() )
882 fright = parseAttribute( right );
885 TQDomElement foot( printInfo.namedItem(
"gmr:Footer").toElement() );
886 if ( !foot.isNull() )
888 kdDebug(30521) <<
"Parsing footer: " << foot.attribute(
"Left") <<
", " << foot.attribute(
"Middle") <<
", "
889 << foot.attribute(
"Right") <<
", " <<endl;
890 if ( foot.hasAttribute(
"Left") )
891 footLeft = convertVars( foot.attribute(
"Left"), table );
892 if ( foot.hasAttribute(
"Middle") )
893 footMiddle = convertVars( foot.attribute(
"Middle"), table );
894 if ( foot.hasAttribute(
"Right") )
895 footRight = convertVars( foot.attribute(
"Right"), table );
898 TQDomElement head( printInfo.namedItem(
"gmr:Header").toElement() );
899 if ( !head.isNull() )
901 kdDebug(30521) <<
"Parsing header: " << head.attribute(
"Left") <<
", " << head.attribute(
"Middle") <<
", " << head.attribute(
"Right") <<
", "<< endl;
902 if ( head.hasAttribute(
"Left") )
903 headLeft = convertVars( head.attribute(
"Left"), table );
904 if ( head.hasAttribute(
"Middle") )
905 headMiddle = convertVars( head.attribute(
"Middle"), table );
906 if ( head.hasAttribute(
"Right") )
907 headRight = convertVars( head.attribute(
"Right"), table );
910 TQDomElement repeateColumn( printInfo.namedItem(
"gmr:repeat_top").toElement() );
911 if ( !repeateColumn.isNull() )
913 TQString repeate = repeateColumn.attribute(
"value" );
914 if ( !repeate.isEmpty() )
916 Range range(repeate);
918 table->print()->setPrintRepeatRows( qMakePair( range.startRow (),range.endRow ()) );
922 TQDomElement repeateRow( printInfo.namedItem(
"gmr:repeat_left").toElement() );
923 if ( !repeateRow.isNull() )
925 TQString repeate = repeateRow.attribute(
"value" );
926 if ( !repeate.isEmpty() )
929 repeate = repeate.replace(
"65536",
"32500" );
930 Range range(repeate);
932 table->print()->setPrintRepeatColumns( qMakePair( range.startCol (),range.endCol ()) );
936 TQDomElement orient( printInfo.namedItem(
"gmr:orientation").toElement() );
937 if ( !orient.isNull() )
938 orientation = orient.text();
940 TQDomElement size( printInfo.namedItem(
"gmr:paper").toElement() );
941 if ( !size.isNull() )
942 paperSize = size.text();
944 table->print()->setPaperLayout( fleft, ftop, fright, fbottom,
945 paperSize, orientation );
947 table->print()->setHeadFootLine( headLeft, headMiddle, headRight,
948 footLeft, footMiddle, footRight );
951void GNUMERICFilter::ParseFormat(TQString
const & formatString, Cell * kspread_cell)
953 int l = formatString.length();
956 if (formatString[l - 1] ==
'%')
957 kspread_cell->format()->setFormatType(Percentage_format);
958 else if (formatString[0] ==
'$')
960 kspread_cell->format()->setFormatType(Money_format);
961 kspread_cell->format()->setCurrency( 1,
"$" );
964 else if (formatString[0] ==
'£')
966 kspread_cell->format()->setFormatType(Money_format);
967 kspread_cell->format()->setCurrency( 1,
"£" );
970 else if (formatString[0] ==
'¥')
972 kspread_cell->format()->setFormatType(Money_format);
973 kspread_cell->format()->setCurrency( 1,
"¥" );
976 else if (formatString[0] ==
'¤')
978 kspread_cell->format()->setFormatType(Money_format);
979 kspread_cell->format()->setCurrency( 1,
"¤" );
984 if ((formatString[0] ==
'[') && (formatString[1] ==
'$'))
986 int n = formatString.find(
']');
989 TQString currency = formatString.mid(2, n - 2);
990 kspread_cell->format()->setFormatType(Money_format);
991 kspread_cell->format()->setCurrency( 1, currency );
995 else if (formatString.find(
"E+0") != -1)
997 kspread_cell->format()->setFormatType(Scientific_format);
1002 TQString content(kspread_cell->value().asString());
1004 if ( setType(kspread_cell, formatString, content) )
1007 if (formatString.find(
"?/?") != -1)
1010 kspread_cell->format()->setFormatType( fraction_three_digits );
1018 while (formatString[lastPos] ==
' ')
1024 if (formatString[lastPos] ==
'#')
1027 if (formatString[lastPos + 1] ==
',')
1035 while (formatString[lastPos] ==
' ')
1038 int n = formatString.find(
'.', lastPos );
1042 int precision = lastPos;
1043 while (formatString[precision] ==
'0')
1047 lastPos = precision;
1050 kspread_cell->format()->setPrecision( precision );
1054 if (formatString.find(
"[RED]", lastPos) != -1)
1057 kspread_cell->format()->setFloatColor( Format::NegRed );
1059 if ( formatString.find(
'(', lastPos) != -1 )
1062 kspread_cell->format()->setFloatColor( Format::NegRedBrackets );
1064 kspread_cell->format()->setFloatColor( Format::NegBrackets );
1068void GNUMERICFilter::convertFormula( TQString & formula )
const
1070 int n = formula.find(
'=', 1 );
1074 formula = formula.replace( n, 1,
"==" );
1076 bool inQuote1 =
false;
1077 bool inQuote2 =
false;
1078 int l = formula.length();
1079 for (
int i = 0; i < l; ++i )
1081 if ( formula[i] ==
'\'' )
1082 inQuote1 = !inQuote1;
1083 else if ( formula[i] ==
'"' )
1084 inQuote2 = !inQuote2;
1085 else if ( formula[i] ==
',' && !inQuote1 && !inQuote2 )
1086 formula = formula.replace( i, 1,
";" );
1090void GNUMERICFilter::setStyleInfo(TQDomNode * sheet, Sheet * table)
1092 kdDebug(30521) <<
"SetStyleInfo entered " << endl;
1095 TQDomNode styles = sheet->namedItem(
"gmr:Styles" );
1096 if ( !styles.isNull() )
1099 TQDomNode style_region = styles.namedItem(
"gmr:StyleRegion" );
1101 while ( !style_region.isNull() )
1103 TQDomElement e = style_region.toElement();
1105 TQDomNode style = style_region.namedItem(
"gmr:Style" );
1106 TQDomNode font = style.namedItem(
"gmr:Font" );
1107 TQDomNode validation = style.namedItem(
"gmr:Validation" );
1108 TQDomNode gmr_styleborder = style.namedItem(
"gmr:StyleBorder" );
1109 TQDomNode hyperlink = style.namedItem(
"gmr:HyperLink" );
1110 int startCol = e.attribute(
"startCol" ).toInt() + 1;
1111 int endCol = e.attribute(
"endCol" ).toInt() + 1;
1112 int startRow = e.attribute(
"startRow" ).toInt() + 1;
1113 int endRow = e.attribute(
"endRow" ).toInt() + 1;
1115 kdDebug(30521) <<
"------Style: " << startCol <<
", "
1116 << startRow <<
" - " << endCol <<
", " << endRow << endl;
1118 if ( endCol - startCol > 200 || endRow - startRow > 200 )
1120 style_region = style_region.nextSibling();
1124 for ( column = startCol; column <= endCol; ++column )
1126 for ( row = startRow; row <= endRow; ++row )
1128 kdDebug(30521) <<
"Cell: " << column <<
", " << row << endl;
1129 Cell * kspread_cell = table->cellAt( column, row,
false );
1132 if ( ( kspread_cell->isDefault() || kspread_cell->isEmpty() )
1133 && ( ( endCol - startCol > 2 ) || ( endRow - startRow > 2 ) ) )
1135 kdDebug(30521) <<
"CELL EMPTY OR RANGE TOO BIG " << endl;
1139 TQDomElement style_element = style.toElement();
1141 kdDebug(30521) <<
"Style valid for kspread" << endl;
1142 kspread_cell = table->nonDefaultCell( column, row,
false );
1144 if (style_element.hasAttribute(
"Fore"))
1146 TQString color_string = style_element.attribute(
"Fore");
1148 convert_string_to_qcolor(color_string, &color);
1149 kspread_cell->format()->setTextColor(color);
1152 if (style_element.hasAttribute(
"Back"))
1154 TQString color_string = style_element.attribute(
"Back");
1156 convert_string_to_qcolor(color_string, &color);
1157 kspread_cell->format()->setBgColor(color);
1160 if (style_element.hasAttribute(
"PatternColor"))
1162 TQString color_string = style_element.attribute(
"PatternColor");
1164 convert_string_to_qcolor(color_string, &color);
1165 kspread_cell->format()->setBackGroundBrushColor( color );
1168 if (style_element.hasAttribute(
"Shade"))
1173 TQString shade = style_element.attribute(
"Shade");
1178 else if (shade ==
"1")
1186 else if (shade ==
"2")
1189 kspread_cell->format()->setBackGroundBrushStyle(TQt::Dense2Pattern);
1191 else if (shade ==
"3")
1194 kspread_cell->format()->setBackGroundBrushStyle(TQt::Dense4Pattern);
1196 else if (shade ==
"4")
1198 kspread_cell->format()->setBackGroundBrushStyle(TQt::Dense5Pattern);
1203 else if (shade ==
"5")
1205 kspread_cell->format()->setBackGroundBrushStyle(TQt::Dense6Pattern);
1208 else if (shade ==
"6")
1210 kspread_cell->format()->setBackGroundBrushStyle(TQt::Dense7Pattern);
1214 else if (shade ==
"7")
1216 kspread_cell->format()->setBackGroundBrushStyle(TQt::HorPattern);
1219 else if (shade ==
"8")
1221 kspread_cell->format()->setBackGroundBrushStyle(TQt::VerPattern);
1224 else if (shade ==
"9")
1226 kspread_cell->format()->setBackGroundBrushStyle(TQt::BDiagPattern);
1229 else if (shade ==
"10")
1232 kspread_cell->format()->setBackGroundBrushStyle(TQt::FDiagPattern);
1234 else if (shade ==
"11")
1237 kspread_cell->format()->setBackGroundBrushStyle(TQt::DiagCrossPattern);
1239 else if (shade ==
"12")
1242 kspread_cell->format()->setBackGroundBrushStyle(TQt::DiagCrossPattern);
1244 else if (shade ==
"13")
1247 kspread_cell->format()->setBackGroundBrushStyle(TQt::HorPattern);
1249 else if (shade ==
"14")
1251 kspread_cell->format()->setBackGroundBrushStyle(TQt::VerPattern);
1253 else if (shade ==
"15")
1255 kspread_cell->format()->setBackGroundBrushStyle(TQt::FDiagPattern);
1257 else if (shade ==
"16")
1260 kspread_cell->format()->setBackGroundBrushStyle(TQt::BDiagPattern);
1262 else if (shade ==
"17")
1264 kspread_cell->format()->setBackGroundBrushStyle(TQt::DiagCrossPattern);
1266 else if (shade ==
"18")
1268 kspread_cell->format()->setBackGroundBrushStyle(TQt::DiagCrossPattern);
1270 else if (shade ==
"19")
1274 else if (shade ==
"20")
1278 else if (shade ==
"21")
1282 else if (shade ==
"22")
1286 else if (shade ==
"23")
1290 else if (shade ==
"24")
1293 kspread_cell->format()->setBackGroundBrushStyle(TQt::SolidPattern);
1295 else if (shade ==
"25")
1298 kspread_cell->format()->setBackGroundBrushStyle(TQt::Dense2Pattern);
1302 if ( style_element.hasAttribute(
"Rotation" ) )
1304 int rot = style_element.attribute(
"Rotation" ).toInt();
1305 kspread_cell->format()->setAngle( -1* rot );
1307 if (style_element.hasAttribute(
"Indent"))
1309 double indent = style_element.attribute(
"Indent").toDouble();
1311 kspread_cell->format()->setIndent( indent * 10.0 );
1314 if (style_element.hasAttribute(
"HAlign"))
1316 TQString halign_string=style_element.attribute(
"HAlign");
1318 if (halign_string ==
"1")
1322 else if (halign_string ==
"2")
1324 kspread_cell->format()->setAlign(Format::Left);
1326 else if (halign_string ==
"4")
1328 kspread_cell->format()->setAlign(Format::Right);
1330 else if (halign_string ==
"8")
1332 kspread_cell->format()->setAlign(Format::Center);
1334 else if (halign_string ==
"16")
1338 else if (halign_string ==
"32")
1342 else if (halign_string ==
"64")
1349 if (style_element.hasAttribute(
"VAlign"))
1351 TQString valign_string=style_element.attribute(
"VAlign");
1353 if (valign_string ==
"1")
1356 kspread_cell->format()->setAlignY(Format::Top);
1358 else if (valign_string ==
"2")
1360 kspread_cell->format()->setAlignY(Format::Bottom);
1362 else if (valign_string ==
"4")
1364 kspread_cell->format()->setAlignY(Format::Middle);
1366 else if (valign_string ==
"8")
1372 if (style_element.hasAttribute(
"WrapText"))
1374 TQString multiRow = style_element.attribute(
"WrapText");
1376 if ( multiRow ==
"1" )
1377 kspread_cell->format()->setMultiRow(
true );
1380 if (style_element.hasAttribute(
"Format"))
1382 TQString formatString = style_element.attribute(
"Format");
1384 kdDebug(30521) <<
"Format: " << formatString << endl;
1385 ParseFormat(formatString, kspread_cell);
1389 if (!gmr_styleborder.isNull())
1391 TQDomElement style_element = gmr_styleborder.toElement();
1392 ParseBorder( style_element, kspread_cell );
1394 if ( !validation.isNull() )
1396 TQDomElement validation_element = validation.toElement();
1397 if ( !validation_element.isNull() )
1399 kdDebug(30521)<<
" Cell validation \n";
1400 Validity* kspread_validity = kspread_cell->getValidity();
1401 if ( validation_element.hasAttribute(
"AllowBlank" ) && validation_element.attribute(
"AllowBlank" )==
"true" )
1403 kspread_validity->allowEmptyCell=
true;
1405 if ( validation_element.hasAttribute(
"Title" ))
1407 kspread_validity->title=validation_element.attribute(
"Title" );
1409 if ( validation_element.hasAttribute(
"Message" ))
1411 kspread_validity->message=validation_element.attribute(
"Message" );
1413 if ( validation_element.hasAttribute(
"Style" ) )
1415 int value = validation_element.attribute(
"Style" ).toInt();
1419 kspread_validity->displayMessage=
false;
1422 kspread_validity->m_action=Action::Stop;
1425 kspread_validity->m_action=Action::Warning;
1428 kspread_validity->m_action=Action::Information;
1431 kdDebug()<<
" Error in validation style :"<<value<<endl;
1435 TQDomNode expression0 = validation_element.namedItem(
"gmr:Expression0" );
1436 TQDomNode expression1 = validation_element.namedItem(
"gmr:Expression1" );
1439 if ( validation_element.hasAttribute(
"Type" ) )
1441 int valueOp = validation_element.attribute(
"Type" ).toInt();
1445 kspread_validity->m_restriction=Restriction::None;
1449 kspread_validity->m_restriction=Restriction::Integer;
1450 if ( validation_element.hasAttribute(
"Operator" ) )
1452 int value = validation_element.attribute(
"Operator" ).toInt();
1457 kspread_validity->m_cond=Conditional::Between;
1458 if ( !expression0.isNull() )
1459 kspread_validity->valMin=expression0.toElement().text().toInt();
1460 if ( !expression1.isNull() )
1461 kspread_validity->valMax=expression1.toElement().text().toInt();
1464 kspread_validity->m_cond=Conditional::DifferentTo;
1465 if ( !expression0.isNull() )
1466 kspread_validity->valMin=expression0.toElement().text().toInt();
1467 if ( !expression1.isNull() )
1468 kspread_validity->valMax=expression1.toElement().text().toInt();
1471 kspread_validity->m_cond=Conditional::Equal;
1472 if ( !expression0.isNull() )
1473 kspread_validity->valMin=expression0.toElement().text().toInt();
1476 kspread_validity->m_cond=Conditional::Different;
1477 if ( !expression0.isNull() )
1478 kspread_validity->valMin=expression0.toElement().text().toInt();
1481 kspread_validity->m_cond=Conditional::Superior;
1482 if ( !expression0.isNull() )
1483 kspread_validity->valMin=expression0.toElement().text().toInt();
1486 kspread_validity->m_cond=Conditional::Inferior;
1487 if ( !expression0.isNull() )
1488 kspread_validity->valMin=expression0.toElement().text().toInt();
1491 kspread_validity->m_cond=Conditional::SuperiorEqual;
1492 if ( !expression0.isNull() )
1493 kspread_validity->valMin=expression0.toElement().text().toInt();
1496 kspread_validity->m_cond=Conditional::InferiorEqual;
1497 if ( !expression0.isNull() )
1498 kspread_validity->valMin=expression0.toElement().text().toInt();
1501 kdDebug()<<
" Error in validation Operator :"<<value<<endl;
1508 kspread_validity->m_restriction=Restriction::Number;
1509 if ( validation_element.hasAttribute(
"Operator" ) )
1511 int value = validation_element.attribute(
"Operator" ).toInt();
1515 kspread_validity->m_cond=Conditional::Between;
1516 if ( !expression0.isNull() )
1517 kspread_validity->valMin=expression0.toElement().text().toInt();
1518 if ( !expression1.isNull() )
1519 kspread_validity->valMax=expression1.toElement().text().toInt();
1522 kspread_validity->m_cond=Conditional::DifferentTo;
1523 if ( !expression0.isNull() )
1524 kspread_validity->valMin=expression0.toElement().text().toInt();
1525 if ( !expression1.isNull() )
1526 kspread_validity->valMax=expression1.toElement().text().toInt();
1529 kspread_validity->m_cond=Conditional::Equal;
1530 if ( !expression0.isNull() )
1531 kspread_validity->valMin=expression0.toElement().text().toInt();
1534 kspread_validity->m_cond=Conditional::Different;
1535 if ( !expression0.isNull() )
1536 kspread_validity->valMin=expression0.toElement().text().toInt();
1539 kspread_validity->m_cond=Conditional::Superior;
1540 if ( !expression0.isNull() )
1541 kspread_validity->valMin=expression0.toElement().text().toInt();
1544 if ( !expression0.isNull() )
1545 kspread_validity->valMin=expression0.toElement().text().toInt();
1546 kspread_validity->m_cond=Conditional::Inferior;
1549 kspread_validity->m_cond=Conditional::SuperiorEqual;
1550 if ( !expression0.isNull() )
1551 kspread_validity->valMin=expression0.toElement().text().toInt();
1554 kspread_validity->m_cond=Conditional::InferiorEqual;
1555 if ( !expression0.isNull() )
1556 kspread_validity->valMin=expression0.toElement().text().toInt();
1559 kdDebug()<<
" Error in validation Operator :"<<value<<endl;
1565 kspread_validity->m_restriction=Restriction::List;
1568 kspread_validity->m_restriction=Restriction::Date;
1569 if ( validation_element.hasAttribute(
"Operator" ) )
1571 int value = validation_element.attribute(
"Operator" ).toInt();
1575 kspread_validity->m_cond=Conditional::Between;
1576 if ( !expression0.isNull() )
1577 kspread_validity->dateMin=TQDate::fromString( expression0.toElement().text() );
1578 if ( !expression1.isNull() )
1579 kspread_validity->dateMax=TQDate::fromString( expression1.toElement().text() );
1583 if ( !expression0.isNull() )
1584 kspread_validity->dateMin=TQDate::fromString( expression0.toElement().text() );
1585 if ( !expression1.isNull() )
1586 kspread_validity->dateMax=TQDate::fromString( expression1.toElement().text() );
1587 kspread_validity->m_cond=Conditional::DifferentTo;
1590 if ( !expression0.isNull() )
1591 kspread_validity->dateMin=TQDate::fromString( expression0.toElement().text() );
1592 kspread_validity->m_cond=Conditional::Equal;
1595 if ( !expression0.isNull() )
1596 kspread_validity->dateMin=TQDate::fromString( expression0.toElement().text() );
1597 kspread_validity->m_cond=Conditional::Different;
1600 if ( !expression0.isNull() )
1601 kspread_validity->dateMin=TQDate::fromString( expression0.toElement().text() );
1602 kspread_validity->m_cond=Conditional::Superior;
1605 if ( !expression0.isNull() )
1606 kspread_validity->dateMin=TQDate::fromString( expression0.toElement().text() );
1607 kspread_validity->m_cond=Conditional::Inferior;
1610 if ( !expression0.isNull() )
1611 kspread_validity->dateMin=TQDate::fromString( expression0.toElement().text() );
1612 kspread_validity->m_cond=Conditional::SuperiorEqual;
1615 if ( !expression0.isNull() )
1616 kspread_validity->dateMin=TQDate::fromString( expression0.toElement().text() );
1617 kspread_validity->m_cond=Conditional::InferiorEqual;
1620 kdDebug()<<
" Error in validation Operator :"<<value<<endl;
1626 kspread_validity->m_restriction=Restriction::Time;
1627 if ( validation_element.hasAttribute(
"Operator" ) )
1629 int value = validation_element.attribute(
"Operator" ).toInt();
1633 kspread_validity->m_cond=Conditional::Between;
1634 if ( !expression0.isNull() )
1635 kspread_validity->timeMin=TQTime::fromString( expression0.toElement().text() );
1636 if ( !expression1.isNull() )
1637 kspread_validity->timeMax=TQTime::fromString( expression1.toElement().text() );
1640 if ( !expression0.isNull() )
1641 kspread_validity->timeMin=TQTime::fromString( expression0.toElement().text() );
1642 if ( !expression1.isNull() )
1643 kspread_validity->timeMax=TQTime::fromString( expression1.toElement().text() );
1644 kspread_validity->m_cond=Conditional::DifferentTo;
1647 if ( !expression0.isNull() )
1648 kspread_validity->timeMin=TQTime::fromString( expression0.toElement().text() );
1649 kspread_validity->m_cond=Conditional::Equal;
1652 kspread_validity->m_cond=Conditional::Different;
1655 if ( !expression0.isNull() )
1656 kspread_validity->timeMin=TQTime::fromString( expression0.toElement().text() );
1657 kspread_validity->m_cond=Conditional::Superior;
1660 kspread_validity->m_cond=Conditional::Inferior;
1661 if ( !expression0.isNull() )
1662 kspread_validity->timeMin=TQTime::fromString( expression0.toElement().text() );
1665 kspread_validity->m_cond=Conditional::SuperiorEqual;
1666 if ( !expression0.isNull() )
1667 kspread_validity->timeMin=TQTime::fromString( expression0.toElement().text() );
1670 if ( !expression0.isNull() )
1671 kspread_validity->timeMin=TQTime::fromString( expression0.toElement().text() );
1672 kspread_validity->m_cond=Conditional::InferiorEqual;
1675 kdDebug()<<
" Error in validation Operator :"<<value<<endl;
1681 kspread_validity->m_restriction=Restriction::TextLength;
1682 if ( validation_element.hasAttribute(
"Operator" ) )
1684 int value = validation_element.attribute(
"Operator" ).toInt();
1688 kspread_validity->m_cond=Conditional::Between;
1689 if ( !expression0.isNull() )
1690 kspread_validity->valMin=expression0.toElement().text().toInt();
1691 if ( !expression1.isNull() )
1692 kspread_validity->valMax=expression1.toElement().text().toInt();
1695 kspread_validity->m_cond=Conditional::DifferentTo;
1696 if ( !expression0.isNull() )
1697 kspread_validity->valMin=expression0.toElement().text().toInt();
1698 if ( !expression1.isNull() )
1699 kspread_validity->valMax=expression1.toElement().text().toInt();
1702 kspread_validity->m_cond=Conditional::Equal;
1703 if ( !expression0.isNull() )
1704 kspread_validity->valMin=expression0.toElement().text().toInt();
1707 kspread_validity->m_cond=Conditional::Different;
1708 if ( !expression0.isNull() )
1709 kspread_validity->valMin=expression0.toElement().text().toInt();
1712 if ( !expression0.isNull() )
1713 kspread_validity->valMin=expression0.toElement().text().toInt();
1714 kspread_validity->m_cond=Conditional::Superior;
1717 if ( !expression0.isNull() )
1718 kspread_validity->valMin=expression0.toElement().text().toInt();
1719 kspread_validity->m_cond=Conditional::Inferior;
1722 if ( !expression0.isNull() )
1723 kspread_validity->valMin=expression0.toElement().text().toInt();
1724 kspread_validity->m_cond=Conditional::SuperiorEqual;
1727 if ( !expression0.isNull() )
1728 kspread_validity->valMin=expression0.toElement().text().toInt();
1729 kspread_validity->m_cond=Conditional::InferiorEqual;
1732 kdDebug()<<
" Error in validation Operator :"<<value<<endl;
1738 kdDebug()<<
" Error in Type element : "<<valueOp<<endl;
1749 TQDomElement font_element = font.toElement();
1751 kspread_cell->format()->setTextFontFamily( font_element.text() );
1753 if (!font_element.isNull())
1755 if (font_element.attribute(
"Italic") ==
"1")
1756 { kspread_cell->format()->setTextFontItalic(
true); }
1758 if (font_element.attribute(
"Bold") ==
"1")
1759 { kspread_cell->format()->setTextFontBold(
true); }
1761 if (font_element.hasAttribute(
"Underline") && ( font_element.attribute(
"Underline") !=
"0") )
1762 { kspread_cell->format()->setTextFontUnderline(
true); }
1764 if (font_element.hasAttribute(
"StrikeThrough" ) && ( font_element.attribute(
"StrikeThrough") !=
"0") )
1765 { kspread_cell->format()->setTextFontStrike(
true); }
1767 if (font_element.hasAttribute(
"Unit"))
1768 { kspread_cell->format()->setTextFontSize(font_element.attribute(
"Unit").toInt()); }
1771 if ( !hyperlink.isNull() )
1774 if ( hyperlink.toElement().hasAttribute(
"type" ) )
1776 TQString linkType= hyperlink.toElement().attribute(
"type" );
1777 TQString target = hyperlink.toElement().attribute(
"target" );
1778 TQString tip = hyperlink.toElement().attribute(
"tip" );
1779 if ( !tip.isEmpty() )
1780 kspread_cell->setCellText( tip );
1781 if ( linkType==
"GnmHLinkURL" )
1783 if ( !target.startsWith(
"http://" ) )
1784 target=
"http://"+target;
1785 kspread_cell->setLink( target );
1787 else if ( linkType==
"GnmHLinkEMail" )
1789 if ( !target.startsWith(
"mailto:/" ) )
1790 target=
"mailto:/"+target;
1791 kspread_cell->setLink( target );
1793 else if ( linkType==
"GnmHLinkExternal" )
1795 if ( !target.startsWith(
"file://" ) )
1796 target=
"file://"+target;
1798 kspread_cell->setLink( target );
1800 else if ( linkType==
"GnmHLinkCurWB" )
1802 kspread_cell->setLink( target );
1805 kdDebug()<<
" linkType not defined : "<<linkType<<endl;
1811 style_region = style_region.nextSibling();
1825KoFilter::ConversionStatus GNUMERICFilter::convert(
const TQCString & from,
const TQCString & to )
1830 kdDebug(30521) <<
"Entering GNUmeric Import filter." << endl;
1832 KoDocument * document = m_chain->outputDocument();
1834 return KoFilter::StupidError;
1836 kdDebug(30521) <<
"here we go... " << document->className() << endl;
1838 if ( !::tqt_cast<const KSpread::Doc *>( document ) )
1840 kdWarning(30521) <<
"document isn't a KSpread::Doc but a " << document->className() << endl;
1841 return KoFilter::NotImplemented;
1843 if ( from !=
"application/x-gnumeric" || to !=
"application/x-kspread" )
1845 kdWarning(30521) <<
"Invalid mimetypes " << from <<
" " << to << endl;
1846 return KoFilter::NotImplemented;
1849 kdDebug(30521) <<
"...still here..." << endl;
1852 Doc * ksdoc = ( Doc * ) document;
1854 if ( ksdoc->mimeType() !=
"application/x-kspread" )
1856 kdWarning(30521) <<
"Invalid document mimetype " << ksdoc->mimeType() << endl;
1857 return KoFilter::NotImplemented;
1861 TQIODevice* in = KFilterDev::deviceForFile(m_chain->inputFile(),
"application/x-gzip");
1865 kdError(30521) <<
"Cannot create device for uncompressing! Aborting!" << endl;
1866 return KoFilter::FileNotFound;
1869 if (!in->open(IO_ReadOnly))
1871 kdError(30521) <<
"Cannot open file for uncompressing! Aborting!" << endl;
1873 return KoFilter::FileNotFound;
1878 int errorLine, errorColumn;
1879 if ( !doc.setContent(in, &errorMsg, &errorLine, &errorColumn) )
1881 kdError(30521) <<
"Parsing error in " << from <<
"! Aborting!" << endl
1882 <<
" In line: " << errorLine <<
", column: " << errorColumn << endl
1883 <<
" Error message: " << errorMsg << endl;
1885 return KoFilter::ParsingError;
1893 int currentTab = -1;
1894 int selectedTab = 0;
1895 Sheet * selTable = 0;
1897 TQDomElement docElem = doc.documentElement();
1898 TQDomElement uiData = docElem.namedItem(
"gmr:UIData").toElement();
1899 if ( !uiData.isNull() )
1901 if ( uiData.hasAttribute(
"SelectedTab" ) )
1904 int n = uiData.attribute(
"SelectedTab" ).toInt( &ok );
1911 TQDomNode sheets = docElem.namedItem(
"gmr:Sheets");
1912 if ( sheets.isNull() )
1916 return KoFilter::ParsingError;
1918 TQDomNode sheet = sheets.namedItem(
"gmr:Sheet");
1921 set_document_info( document, &docElem );
1924 set_document_attributes( ksdoc, &docElem );
1927 set_document_area_names( ksdoc, &docElem );
1933 TQDict<char> exprID_dict( 17, FALSE );
1936 while (!sheet.isNull())
1939 table = ksdoc->map()->addNewSheet();
1941 if ( currentTab == selectedTab )
1944 TQDomElement name = sheet.namedItem(
"gmr:Name" ).toElement();
1945 TQDomElement sheetElement = sheet.toElement();
1947 if ( !name.isNull() )
1948 table->setSheetName( name.text(),
false,
false );
1950 table->setSheetName(
"Sheet" + TQString::number( num ),
false,
false );
1951 table->enableScrollBarUpdates(
false );
1955 if ( sheetElement.hasAttribute(
"DisplayFormulas" ) )
1957 tmp=sheetElement.attribute(
"DisplayFormulas");
1958 table->setShowFormula( ( tmp==
"true" )||( tmp==
"1" ) );
1960 if ( sheetElement.hasAttribute(
"HideZero" ) )
1962 tmp = sheetElement.attribute(
"HideZero" );
1963 table->setHideZero( ( tmp==
"true" )||( tmp==
"1" ) );
1965 if ( sheetElement.hasAttribute(
"HideGrid" ) )
1967 tmp = sheetElement.attribute(
"HideGrid" );
1968 table->setShowGrid( ( tmp==
"false" )||( tmp==
"0" ) );
1970 if ( sheetElement.hasAttribute(
"HideColHeader" ) )
1972 tmp = sheetElement.attribute(
"HideColHeader" );
1973 ksdoc->setShowColumnHeader( ( tmp==
"false" )||( tmp==
"0" ) );
1975 if ( sheetElement.hasAttribute(
"HideRowHeader" ) )
1977 tmp =sheetElement.attribute(
"HideRowHeader" );
1978 ksdoc->setShowRowHeader( ( tmp==
"false" )||( tmp==
"0" ) );
1982 setObjectInfo(&sheet, table);
1983 setColInfo(&sheet, table);
1984 setRowInfo(&sheet, table);
1985 setSelectionInfo(&sheet, table);
1988 TQDomNode printInfo = sheet.namedItem(
"gmr:PrintInformation");
1989 if ( !printInfo.isNull() )
1990 ParsePrintInfo( printInfo, table );
1992 kdDebug(30521) <<
"Reading in cells" << endl;
1995 TQDomNode cells = sheet.namedItem(
"gmr:Cells" );
1996 TQDomNode cell = cells.namedItem(
"gmr:Cell" );
1997 TQDomNode mergedCells = sheet.namedItem(
"gmr:MergedRegions" );
1998 TQDomNode mergedRegion = mergedCells.namedItem(
"gmr:Merge" );
1999 if ( cell.isNull() )
2001 kdWarning(30521) <<
"No cells" << endl;
2004 while ( !cell.isNull() )
2007 emit sigProgress(value);
2009 TQDomElement e = cell.toElement();
2012 kdDebug(30521) <<
"New Cell " << endl;
2013 TQDomNode content_node = cell.namedItem(
"gmr:Content");
2015 if (!content_node.isNull())
2017 TQDomElement content = content_node.toElement();
2019 if( !content.isNull() )
2021 column = e.attribute(
"Col" ).toInt() + 1;
2022 row = e.attribute(
"Row" ).toInt() + 1;
2024 TQString cell_content( content.text() );
2026 if ( cell_content[0] ==
'=' )
2027 convertFormula( cell_content );
2029 Cell * kspread_cell = table->nonDefaultCell( column, row );
2031 if (e.hasAttribute(
"ValueType"))
2042 TQString valuetype = e.attribute(
"ValueType" );
2043 if ( valuetype ==
"40" )
2045 kspread_cell->format()->setFormatType( Percentage_format );
2046 kspread_cell->setValue( cell_content );
2048 else if ( valuetype ==
"60" )
2050 kspread_cell->format()->setFormatType( Text_format );
2051 kspread_cell->setValue( cell_content );
2055 if (e.hasAttribute(
"ValueFormat" ))
2057 TQString formatString = e.attribute(
"ValueFormat" );
2058 if ( !setType( kspread_cell, formatString, cell_content ) )
2059 table->setText(row, column, cell_content,
false);
2062 table->setText(row, column, cell_content,
false);
2064 if (e.hasAttribute(
"ExprID"))
2067 TQString encoded_string(table->cellAt( column, row,
false )->encodeFormula().latin1());
2070 char * tmp_string = (
char * ) malloc( strlen( encoded_string.latin1() ) );
2071 strcpy( tmp_string, encoded_string.latin1() );
2073 kdDebug(30521) << encoded_string.latin1() << endl;
2075 exprID_dict.insert(e.attribute(
"ExprID"), tmp_string);
2077 kdDebug(30521) << exprID_dict[e.attribute(
"ExprID")] << endl;
2078 kdDebug(30521) << exprID_dict[TQString(
"1")] << endl;
2079 kdDebug(30521) << e.attribute(
"ExprID") << endl;
2087 column = e.attribute(
"Col" ).toInt() + 1;
2088 row = e.attribute(
"Row" ).toInt() + 1;
2090 TQString cell_content( e.text() );
2092 if ( cell_content[0] ==
'=' )
2093 convertFormula( cell_content );
2095 Cell * kspread_cell = table->nonDefaultCell( column, row );
2097 if (e.hasAttribute(
"ValueType"))
2110 TQString valuetype = e.attribute(
"ValueType" );
2111 if ( valuetype ==
"40" )
2113 kspread_cell->format()->setFormatType( Percentage_format );
2114 kspread_cell->setValue( cell_content );
2116 else if ( valuetype ==
"60" )
2118 kspread_cell->format()->setFormatType( Text_format );
2119 kspread_cell->setValue( cell_content );
2124 if (e.hasAttribute(
"ValueFormat" ))
2126 TQString formatString = e.attribute(
"ValueFormat" );
2127 if ( !setType( kspread_cell, formatString, cell_content ) )
2128 table->setText(row, column, cell_content,
false);
2131 table->setText(row, column, cell_content,
false);
2134 if (e.hasAttribute(
"ExprID"))
2136 column = e.attribute(
"Col").toInt() + 1;
2137 row = e.attribute(
"Row").toInt() + 1;
2139 expr = exprID_dict[e.attribute(
"ExprID")];
2142 kdDebug(30521) <<
"FOO:" << column << row << endl;
2144 table->cellAt( column, row,
false )->decodeFormula( expr, column, row ).latin1() << endl;
2145 kdDebug(30521) << expr << endl;
2147 table->setText(row, column,
2148 table->cellAt( column, row,
false )->decodeFormula( expr, column, row ),
2153 cell = cell.nextSibling();
2156 kdDebug(30521) <<
"Reading in cells done" << endl;
2158 if ( mergedRegion.isNull() )
2160 kdWarning(30521) <<
"No cells merged !" << endl;
2162 while ( !mergedRegion.isNull() )
2164 TQDomElement e = mergedRegion.toElement();
2165 TQString cell_merge_area( e.text() );
2166 Range range(cell_merge_area);
2168 Cell * cell = table->nonDefaultCell( range.startCol (), range.startRow () );
2169 cell->mergeCells( range.startCol (), range.startRow (), range.endCol ()-range.startCol (), range.endRow ()-range.startRow ());
2170 mergedRegion = mergedRegion.nextSibling();
2188 setStyleInfo(&sheet, table);
2191 table->enableScrollBarUpdates(
true );
2193 sheet = sheet.nextSibling();
2198 ksdoc->setDisplaySheet( selTable );
2200 emit sigProgress(100);
2202 return KoFilter::OK;
2204 return KoFilter::StupidError;
2207#include <gnumericimport.moc>