24#include <gnumericexport.h>
26#include <kfilterdev.h>
27#include <tdemessagebox.h>
28#include <kgenericfactory.h>
29#include <KoFilterChain.h>
30#include <tqapplication.h>
32#include <tqsortedlist.h>
34#include <tqtextstream.h>
36#include <kspread_map.h>
37#include <kspread_sheet.h>
38#include <kspread_doc.h>
39#include <kspread_view.h>
40#include <kspread_canvas.h>
41#include <kspread_sheetprint.h>
42#include <KoDocumentInfo.h>
44using namespace KSpread;
46typedef KGenericFactory<GNUMERICExport, KoFilter> GNUMERICExportFactory;
47K_EXPORT_COMPONENT_FACTORY( libgnumericexport, GNUMERICExportFactory(
"kofficefilters" ) )
49GNUMERICExport::GNUMERICExport(KoFilter *, const
char *, const TQStringList&) :
60bool GNUMERICExport::hasBorder(Cell *cell,
int currentcolumn,
int currentrow)
62 if ( ( (cell->format()->leftBorderWidth(currentcolumn, currentrow) != 0) &&
63 (cell->format()->leftBorderStyle(currentcolumn, currentrow) != TQt::NoPen ) ) ||
64 ( (cell->format()->rightBorderWidth(currentcolumn, currentrow) != 0) &&
65 (cell->format()->rightBorderStyle(currentcolumn, currentrow) != TQt::NoPen ) ) ||
66 ( (cell->format()->topBorderWidth(currentcolumn, currentrow) != 0) &&
67 (cell->format()->topBorderStyle(currentcolumn, currentrow) != TQt::NoPen ) ) ||
68 ( (cell->format()->bottomBorderWidth(currentcolumn, currentrow) != 0) &&
69 (cell->format()->bottomBorderStyle(currentcolumn, currentrow) != TQt::NoPen ) ) ||
70 ( (cell->format()->fallDiagonalWidth(currentcolumn, currentrow) != 0) &&
71 (cell->format()->fallDiagonalStyle(currentcolumn, currentrow) != TQt::NoPen ) ) ||
72 ( (cell->format()->goUpDiagonalWidth(currentcolumn, currentrow) != 0) &&
73 (cell->format()->goUpDiagonalStyle(currentcolumn, currentrow) != TQt::NoPen ) ) )
79const TQString GNUMERICExport::ColorToString(
int red,
int green,
int blue)
81 return TQString::number(red,16)+
":"+TQString::number(green,16)+
":"+TQString::number(blue,16);
84TQDomElement GNUMERICExport::GetBorderStyle(TQDomDocument gnumeric_doc,Cell * cell,
int currentcolumn,
int currentrow)
86 TQDomElement border_style;
92 border_style = gnumeric_doc.createElement(
"gmr:StyleBorder");
94 if ( (cell->format()->leftBorderWidth(currentcolumn, currentrow) != 0) &&
95 (cell->format()->leftBorderStyle(currentcolumn, currentrow) != TQt::NoPen ) )
97 border = gnumeric_doc.createElement(
"gmr:Left");
98 border.setAttribute(
"Style",
"1");
100 color = cell->format()->leftBorderColor(currentcolumn, currentrow);
101 red = color.red()<<8;
102 green = color.green()<<8;
103 blue = color.blue()<<8;
105 border.setAttribute(
"Color", TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16));
109 border = gnumeric_doc.createElement(
"gmr:Left");
110 border.setAttribute(
"Style",
"0");
113 border_style.appendChild(border);
115 if ( (cell->format()->rightBorderWidth(currentcolumn, currentrow) != 0) &&
116 (cell->format()->rightBorderStyle(currentcolumn, currentrow) != TQt::NoPen ) )
118 border = gnumeric_doc.createElement(
"gmr:Right");
119 border.setAttribute(
"Style",
"1");
121 color = cell->format()->rightBorderColor(currentcolumn, currentrow);
122 red = color.red()<<8;
123 green = color.green()<<8;
124 blue = color.blue()<<8;
126 border.setAttribute(
"Color", TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16));
130 border = gnumeric_doc.createElement(
"gmr:Right");
131 border.setAttribute(
"Style",
"0");
134 border_style.appendChild(border);
136 if ( (cell->format()->topBorderWidth(currentcolumn, currentrow) != 0) &&
137 (cell->format()->topBorderStyle(currentcolumn, currentrow) != TQt::NoPen ) )
139 border = gnumeric_doc.createElement(
"gmr:Top");
140 border.setAttribute(
"Style",
"1");
142 color = cell->format()->topBorderColor(currentcolumn, currentrow);
143 red = color.red()<<8;
144 green = color.green()<<8;
145 blue = color.blue()<<8;
147 border.setAttribute(
"Color", TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16));
151 border = gnumeric_doc.createElement(
"gmr:Top");
152 border.setAttribute(
"Style",
"0");
155 border_style.appendChild(border);
157 if ( (cell->format()->bottomBorderWidth(currentcolumn, currentrow) != 0) &&
158 (cell->format()->bottomBorderStyle(currentcolumn, currentrow) != TQt::NoPen ) )
160 border = gnumeric_doc.createElement(
"gmr:Bottom");
161 border.setAttribute(
"Style",
"1");
163 color = cell->format()->bottomBorderColor(currentcolumn, currentrow);
164 red = color.red()<<8;
165 green = color.green()<<8;
166 blue = color.blue()<<8;
168 border.setAttribute(
"Color", TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16));
172 border = gnumeric_doc.createElement(
"gmr:Bottom");
173 border.setAttribute(
"Style",
"0");
176 border_style.appendChild(border);
178 if ( (cell->format()->fallDiagonalWidth(currentcolumn, currentrow) != 0) &&
179 (cell->format()->fallDiagonalStyle(currentcolumn, currentrow) != TQt::NoPen ) )
181 border = gnumeric_doc.createElement(
"gmr:Diagonal");
182 border.setAttribute(
"Style",
"1");
184 color = cell->format()->fallDiagonalColor(currentcolumn, currentrow);
185 red = color.red()<<8;
186 green = color.green()<<8;
187 blue = color.blue()<<8;
189 border.setAttribute(
"Color", TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16));
193 border = gnumeric_doc.createElement(
"gmr:Diagonal");
194 border.setAttribute(
"Style",
"0");
197 border_style.appendChild(border);
199 if ( (cell->format()->goUpDiagonalWidth(currentcolumn, currentrow) != 0) &&
200 (cell->format()->goUpDiagonalStyle(currentcolumn, currentrow) != TQt::NoPen ) )
202 border = gnumeric_doc.createElement(
"gmr:Rev-Diagonal");
203 border.setAttribute(
"Style",
"1");
205 color = cell->format()->goUpDiagonalColor(currentcolumn, currentrow);
206 red = color.red()<<8;
207 green = color.green()<<8;
208 blue = color.blue()<<8;
210 border.setAttribute(
"Color", TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16));
214 border = gnumeric_doc.createElement(
"gmr:Rev-Diagonal");
215 border.setAttribute(
"Style",
"0");
218 border_style.appendChild(border);
223TQDomElement GNUMERICExport::GetValidity( TQDomDocument gnumeric_doc, Cell * cell )
228 Validity *kspread_validity = cell->getValidity();
229 TQDomElement val = gnumeric_doc.createElement(
"gmr:Validation" );
230 val.setAttribute(
"Title", kspread_validity->title );
231 val.setAttribute(
"Message", kspread_validity->message );
232 val.setAttribute(
"AllowBlank", kspread_validity->allowEmptyCell ?
"true":
"false" );
233 if ( !kspread_validity->displayMessage )
235 val.setAttribute(
"Style",
"0" );
239 switch( kspread_validity->m_action )
242 val.setAttribute(
"Style",
"1" );
244 case Action::Warning:
245 val.setAttribute(
"Style",
"2" );
247 case Action::Information:
248 val.setAttribute(
"Style",
"3" );
253 switch( kspread_validity->m_cond )
255 case Conditional::None:
258 case Conditional::Equal:
259 val.setAttribute(
"Operator",
"2" );
261 case Conditional::Superior:
262 val.setAttribute(
"Operator",
"4" );
264 case Conditional::Inferior:
265 val.setAttribute(
"Operator",
"5" );
267 case Conditional::SuperiorEqual:
268 val.setAttribute(
"Operator",
"6" );
270 case Conditional::InferiorEqual:
271 val.setAttribute(
"Operator",
"7" );
273 case Conditional::Between:
274 val.setAttribute(
"Operator",
"0" );
276 case Conditional::Different:
277 val.setAttribute(
"Operator",
"3" );
279 case Conditional::DifferentTo:
280 val.setAttribute(
"Operator",
"1" );
283 switch( kspread_validity->m_restriction )
285 case Restriction::None:
286 val.setAttribute(
"Type",
"0" );
288 case Restriction::Number:
290 val.setAttribute(
"Type",
"2" );
291 switch( kspread_validity->m_cond )
293 case Conditional::None:
296 case Conditional::Equal:
297 case Conditional::Superior:
298 case Conditional::Inferior:
299 case Conditional::SuperiorEqual:
300 case Conditional::InferiorEqual:
301 case Conditional::Different:
303 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
304 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number( kspread_validity->valMin ) ) );
305 val.appendChild( tmp );
308 case Conditional::Between:
309 case Conditional::DifferentTo:
311 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
312 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number(kspread_validity->valMin ) ) );
313 val.appendChild( tmp );
314 tmp = gnumeric_doc.createElement(
"gmr:Expression1" );
315 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number(kspread_validity->valMax ) ) );
316 val.appendChild( tmp );
323 case Restriction::Text:
327 case Restriction::Time:
328 val.setAttribute(
"Type",
"5" );
329 switch( kspread_validity->m_cond )
331 case Conditional::None:
334 case Conditional::Equal:
335 case Conditional::Superior:
336 case Conditional::Inferior:
337 case Conditional::SuperiorEqual:
338 case Conditional::InferiorEqual:
339 case Conditional::Different:
341 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
342 tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity->timeMin.toString() ) );
343 val.appendChild( tmp );
346 case Conditional::Between:
347 case Conditional::DifferentTo:
349 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
350 tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity->timeMin.toString() ) );
351 val.appendChild( tmp );
352 tmp = gnumeric_doc.createElement(
"gmr:Expression1" );
353 tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity->timeMax.toString() ) );
354 val.appendChild( tmp );
360 case Restriction::Date:
361 val.setAttribute(
"Type",
"4" );
362 switch( kspread_validity->m_cond )
364 case Conditional::None:
367 case Conditional::Equal:
368 case Conditional::Superior:
369 case Conditional::Inferior:
370 case Conditional::SuperiorEqual:
371 case Conditional::InferiorEqual:
372 case Conditional::Different:
374 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
375 tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity->dateMin.toString() ) );
376 val.appendChild( tmp );
379 case Conditional::Between:
380 case Conditional::DifferentTo:
382 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
383 tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity->dateMin.toString() ) );
384 val.appendChild( tmp );
385 tmp = gnumeric_doc.createElement(
"gmr:Expression1" );
386 tmp.appendChild( gnumeric_doc.createTextNode( kspread_validity->dateMax.toString() ) );
387 val.appendChild( tmp );
393 case Restriction::Integer:
394 val.setAttribute(
"Type",
"1" );
395 switch( kspread_validity->m_cond )
397 case Conditional::None:
400 case Conditional::Equal:
401 case Conditional::Superior:
402 case Conditional::Inferior:
403 case Conditional::SuperiorEqual:
404 case Conditional::InferiorEqual:
405 case Conditional::Different:
407 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
408 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number(kspread_validity->valMin ) ) );
409 val.appendChild( tmp );
412 case Conditional::Between:
413 case Conditional::DifferentTo:
415 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
416 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number(kspread_validity->valMin ) ) );
417 val.appendChild( tmp );
418 tmp = gnumeric_doc.createElement(
"gmr:Expression1" );
419 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number(kspread_validity->valMax ) ) );
420 val.appendChild( tmp );
425 case Restriction::TextLength:
426 val.setAttribute(
"Type",
"6" );
427 switch( kspread_validity->m_cond )
429 case Conditional::None:
432 case Conditional::Equal:
433 case Conditional::Superior:
434 case Conditional::Inferior:
435 case Conditional::SuperiorEqual:
436 case Conditional::InferiorEqual:
437 case Conditional::Different:
439 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
440 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number(kspread_validity->valMin ) ) );
441 val.appendChild( tmp );
444 case Conditional::Between:
445 case Conditional::DifferentTo:
447 TQDomElement tmp = gnumeric_doc.createElement(
"gmr:Expression0" );
448 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number(kspread_validity->valMin ) ) );
449 val.appendChild( tmp );
450 tmp = gnumeric_doc.createElement(
"gmr:Expression1" );
451 tmp.appendChild( gnumeric_doc.createTextNode( TQString::number(kspread_validity->valMax ) ) );
452 val.appendChild( tmp );
457 case Restriction::List:
458 val.setAttribute(
"Type",
"3" );
459 switch( kspread_validity->m_cond )
461 case Conditional::None:
464 case Conditional::Equal:
465 case Conditional::Superior:
466 case Conditional::Inferior:
467 case Conditional::SuperiorEqual:
468 case Conditional::InferiorEqual:
469 case Conditional::Different:
471 case Conditional::Between:
472 case Conditional::DifferentTo:
481TQDomElement GNUMERICExport::GetFontStyle( TQDomDocument gnumeric_doc,Cell * cell,
int currentcolumn,
int currentrow)
483 TQDomElement font_style;
484 kdDebug()<<
" currentcolumn :"<<currentcolumn<<
" currentrow :"<<currentrow<<endl;
485 font_style = gnumeric_doc.createElement(
"gmr:Font");
486 font_style.appendChild(gnumeric_doc.createTextNode(cell->format()->textFontFamily(currentcolumn, currentrow)));
488 if (cell->format()->textFontItalic(currentcolumn,currentrow) || (isLink && isLinkItalic))
490 font_style.setAttribute(
"Italic",
"1");
492 if (cell->format()->textFontBold(currentcolumn,currentrow) || (isLink && isLinkBold))
494 font_style.setAttribute(
"Bold",
"1");
496 if (cell->format()->textFontUnderline(currentcolumn,currentrow))
498 font_style.setAttribute(
"Underline",
"1");
500 if (cell->format()->textFontStrike(currentcolumn,currentrow))
502 font_style.setAttribute(
"StrikeThrough",
"1");
504 if (cell->format()->textFontSize(currentcolumn,currentrow))
506 font_style.setAttribute(
"Unit",TQString::number(cell->format()->textFontSize(currentcolumn,currentrow)));
512TQDomElement GNUMERICExport::GetLinkStyle(TQDomDocument gnumeric_doc)
514 TQDomElement link_style;
516 link_style = gnumeric_doc.createElement(
"gmr:HyperLink");
522 if (path.section(
":",0,0).lower() ==
"http")
523 link_style.setAttribute(
"type",
"GnmHLinkURL");
524 else if (path.section(
":",0,0).lower() ==
"mailto")
525 link_style.setAttribute(
"type",
"GnmHLinkEMail");
526 else if (path.section(
":",0,0).lower() ==
"file")
527 link_style.setAttribute(
"type",
"GnmHLinkExternal");
528 else if (path.left(5).lower() ==
"sheet")
529 link_style.setAttribute(
"type",
"GnmHLinkCurWB");
531 link_style.setAttribute(
"type",
"");
533 link_style.setAttribute(
"target",path);
536 link_style.setAttribute(
"tip",
"");
541TQDomElement GNUMERICExport::GetCellStyle(TQDomDocument gnumeric_doc,Cell * cell,
int currentcolumn,
int currentrow)
543 TQColorGroup defaultColorGroup = TQApplication::palette().active();
545 TQDomElement cell_style;
547 cell_style = gnumeric_doc.createElement(
"gmr:Style");
549 int red, green, blue;
551 TQColor bgColor = cell->bgColor(currentcolumn, currentrow);
552 red = bgColor.red()<<8;
553 green = bgColor.green()<<8;
554 blue = bgColor.blue()<<8;
556 switch (cell->format()->backGroundBrushStyle(currentcolumn, currentrow))
559 cell_style.setAttribute(
"Shade",
"0");
561 case TQt::SolidPattern:
563 cell_style.setAttribute(
"Shade",
"1");
565 case TQt::Dense1Pattern:
567 cell_style.setAttribute(
"Shade",
"25");
569 case TQt::Dense2Pattern:
571 cell_style.setAttribute(
"Shade",
"2");
573 case TQt::Dense3Pattern:
577 cell_style.setAttribute(
"Shade",
"3");
579 case TQt::Dense4Pattern:
581 cell_style.setAttribute(
"Shade",
"3");
583 case TQt::Dense5Pattern:
585 cell_style.setAttribute(
"Shade",
"4");
587 case TQt::Dense6Pattern:
589 cell_style.setAttribute(
"Shade",
"5");
591 case TQt::Dense7Pattern:
593 cell_style.setAttribute(
"Shade",
"6");
595 case TQt::HorPattern:
596 cell_style.setAttribute(
"Shade",
"13");
598 case TQt::VerPattern:
599 cell_style.setAttribute(
"Shade",
"14");
601 case TQt::CrossPattern:
602 cell_style.setAttribute(
"Shade",
"17");
604 case TQt::BDiagPattern:
605 cell_style.setAttribute(
"Shade",
"16");
607 case TQt::FDiagPattern:
608 cell_style.setAttribute(
"Shade",
"15");
610 case TQt::DiagCrossPattern:
611 cell_style.setAttribute(
"Shade",
"18");
613 case TQt::CustomPattern:
615 cell_style.setAttribute(
"Shade",
"0");
619 cell_style.setAttribute(
"Back",TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16) );
622 TQColor textColor = cell->format()->textColor(currentcolumn, currentrow);
623 red = textColor.red()<<8;
624 green = textColor.green()<<8;
625 blue = textColor.blue()<<8;
627 cell_style.setAttribute(
"Fore",TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16) );
629 if (cell->format()->align(currentcolumn,currentrow) == Format::Undefined)
631 cell_style.setAttribute(
"HAlign",
"1");
633 else if (cell->format()->align(currentcolumn,currentrow) == Format::Left)
635 cell_style.setAttribute(
"HAlign",
"2");
637 else if (cell->format()->align(currentcolumn,currentrow) == Format::Right)
639 cell_style.setAttribute(
"HAlign",
"4");
641 else if (cell->format()->align(currentcolumn,currentrow) == Format::Center)
643 cell_style.setAttribute(
"HAlign",
"8");
646 if (cell->format()->alignY(currentcolumn,currentrow) == Format::Top)
648 cell_style.setAttribute(
"VAlign",
"1");
650 else if (cell->format()->alignY(currentcolumn,currentrow) == Format::Bottom)
652 cell_style.setAttribute(
"VAlign",
"2");
654 else if (cell->format()->alignY(currentcolumn,currentrow) == Format::Middle)
656 cell_style.setAttribute(
"VAlign",
"4");
659 if (cell->format()->multiRow(currentcolumn,currentrow))
660 cell_style.setAttribute(
"WrapText",
"1");
662 cell_style.setAttribute(
"WrapText",
"0");
665 cell_style.setAttribute(
"ShrinkToFit",
"0");
669 cell_style.setAttribute(
"Rotation", TQString::number(-1*cell->format()->getAngle(currentcolumn,currentrow)));
674 cell_style.setAttribute(
"Indent", TQString::number(cell->format()->getIndent(currentcolumn,currentrow)));
676 cell_style.setAttribute(
"Locked", !cell->format()->notProtected(currentcolumn,currentrow));
681 cell_style.setAttribute(
"Hidden", cell->format()->isHideAll(currentcolumn,currentrow));
683 TQColor patColor = cell->format()->backGroundBrushColor(currentcolumn, currentrow);
684 red = patColor.red()<<8;
685 green = patColor.green()<<8;
686 blue = patColor.blue()<<8;
688 cell_style.setAttribute(
"PatternColor", TQString::number(red,16)+
":"+TQString::number(green,16) +
":"+TQString::number(blue,16));
691 cell_style.appendChild(GetLinkStyle(gnumeric_doc));
693 cell_style.appendChild(GetFontStyle(gnumeric_doc, cell, currentcolumn, currentrow));
695 if ( cell->getValidity() )
697 cell_style.appendChild( GetValidity( gnumeric_doc, cell ) );
700 TQString stringFormat;
705 switch( cell->format()->getFormatType(currentcolumn, currentrow))
711 stringFormat=
"general";
715 if (!cell->format()->currencyInfo(c))
717 stringFormat =
"0.00";
721 if (currency.getCurrencyCode(c.type).isEmpty())
722 stringFormat =
"0.00";
723 else if (currency.getCurrencyCode(c.type) ==
"$")
724 stringFormat =
"$0.00";
725 else if (currency.getCurrencyCode(c.type) == TQString::fromUtf8(
"€"))
726 stringFormat =
"[$€-2]0.00";
727 else if (currency.getCurrencyCode(c.type) == TQString::fromUtf8(
"£"))
728 stringFormat =
"£0.00";
729 else if (currency.getCurrencyCode(c.type) == TQString::fromUtf8(
"Â¥"))
730 stringFormat =
"Â¥0.00";
732 stringFormat=
"[$" + currency.getCurrencyCode(c.type) +
"]0.00";
735 case Percentage_format:
736 stringFormat=
"0.00%";
738 case Scientific_format:
739 stringFormat=
"0.00E+00";
741 case ShortDate_format:
742 stringFormat=cell->locale()->dateFormatShort();
744 case TextDate_format:
745 stringFormat=cell->locale()->dateFormat();
748 stringFormat=
"dd-mmm-yy";
751 stringFormat=
"dd-mmm-yyyy";
754 stringFormat=
"dd-mmm";
757 stringFormat=
"dd-mm";
760 stringFormat=
"dd/mm/yy";
763 stringFormat=
"dd/mm/yyyy";
766 stringFormat=
"mmm-yy";
769 stringFormat=
"mmmm-yy";
772 stringFormat=
"mmmm-yyyy";
778 stringFormat=
"dd/mmm";
781 stringFormat=
"dd/mm";
784 stringFormat=
"dd/mmm/yyyy";
787 stringFormat=
"yyyy/mmm/dd";
790 stringFormat=
"yyyy-mmm-dd";
793 stringFormat=
"yyyy-mm-dd";
796 stringFormat=
"d mmmm yyyy";
799 stringFormat=
"mm/dd/yyyy";
802 stringFormat=
"mm/dd/yy";
805 stringFormat=
"mmm/dd/yy";
808 stringFormat=
"mmm/dd/yyyy";
811 stringFormat=
"mmm-yyyy";
820 stringFormat=
"yyyy/mm/dd";
823 stringFormat=
"yyyy/mmm/dd";
826 case SecondeTime_format:
827 stringFormat=cell->locale()->timeFormat();
830 stringFormat =
"h:mm AM/PM";
833 stringFormat =
"h:mm:ss AM/PM";
836 stringFormat =
"h \"h\" mm \"min\" ss \"s\"";
839 stringFormat =
"h:mm";
842 stringFormat =
"h:mm:ss";
845 stringFormat =
"mm:ss";
848 stringFormat =
"[h]:mm:ss";
851 stringFormat =
"[h]:mm";
854 stringFormat=
"# ?/2";
856 case fraction_quarter:
857 stringFormat=
"# ?/4";
859 case fraction_eighth:
860 stringFormat=
"# ?/8";
862 case fraction_sixteenth:
863 stringFormat=
"# ?/16";
866 stringFormat=
"# ?/10";
868 case fraction_hundredth:
869 stringFormat=
"# ?/100";
871 case fraction_one_digit:
872 stringFormat=
"# ?/?";
874 case fraction_two_digits:
875 stringFormat=
"# ?\?/?\?";
877 case fraction_three_digits:
878 stringFormat=
"# ?\?\?/?\?\?";
881 stringFormat = cell->format()->getFormatString(currentcolumn,currentrow);
886 cell_style.setAttribute(
"Format",stringFormat);
888 if(hasBorder(cell, currentcolumn, currentrow))
889 cell_style.appendChild(GetBorderStyle(gnumeric_doc, cell, currentcolumn, currentrow));
895void GNUMERICExport::addAttributeItem(TQDomDocument gnumeric_doc, TQDomElement attributes,
const TQString& type,
const TQString& name,
bool value)
897 TQDomElement gmr_attribute, gmr_type, gmr_name, gmr_value;
899 gmr_attribute = gnumeric_doc.createElement(
"gmr:Attribute");
900 attributes.appendChild(gmr_attribute);
902 gmr_type = gnumeric_doc.createElement(
"gmr:type");
903 gmr_type.appendChild(gnumeric_doc.createTextNode(type));
904 gmr_attribute.appendChild(gmr_type);
906 gmr_name = gnumeric_doc.createElement(
"gmr:name");
907 gmr_name.appendChild(gnumeric_doc.createTextNode(name));
908 gmr_attribute.appendChild(gmr_name);
916 gmr_value = gnumeric_doc.createElement(
"gmr:value");
917 gmr_value.appendChild(gnumeric_doc.createTextNode(txtValue));
918 gmr_attribute.appendChild(gmr_value);
921void GNUMERICExport::addSummaryItem(TQDomDocument gnumeric_doc, TQDomElement summary,
const TQString& name,
const TQString& value)
923 if ( value.isEmpty() )
925 TQDomElement gmr_item, gmr_name, gmr_val_string;
927 gmr_item = gnumeric_doc.createElement(
"gmr:Item");
928 summary.appendChild(gmr_item);
930 gmr_name = gnumeric_doc.createElement(
"gmr:name");
931 gmr_name.appendChild(gnumeric_doc.createTextNode(name));
932 gmr_item.appendChild(gmr_name);
934 gmr_val_string = gnumeric_doc.createElement(
"gmr:val-string");
935 gmr_val_string.appendChild(gnumeric_doc.createTextNode(value));
936 gmr_item.appendChild(gmr_val_string);
941KoFilter::ConversionStatus GNUMERICExport::convert(
const TQCString& from,
const TQCString& to )
943 kdDebug(30521) <<
"Exporting GNUmeric" << endl;
945 TQDomDocument gnumeric_doc=TQDomDocument();
948 KoDocument* document = m_chain->inputDocument();
951 return KoFilter::StupidError;
953 if ( !::tqt_cast<const KSpread::Doc *>( document ) )
955 kdWarning(30521) <<
"document isn't a KSpread::Doc but a " << document->className() << endl;
956 return KoFilter::NotImplemented;
958 if (to !=
"application/x-gnumeric" || from !=
"application/x-kspread")
960 kdWarning(30521) <<
"Invalid mimetypes " << to <<
" " << from << endl;
961 return KoFilter::NotImplemented;
964 Doc* ksdoc = (Doc*)document;
966 if (ksdoc->mimeType() !=
"application/x-kspread")
968 kdWarning(30521) <<
"Invalid document mimetype " << ksdoc->mimeType() << endl;
969 return KoFilter::NotImplemented;
974 gnumeric_doc.appendChild( gnumeric_doc.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\"" ) );
976 TQDomElement workbook = gnumeric_doc.createElement(
"gmr:Workbook");
977 workbook.setAttribute(
"xmlns:gmr",
"http://www.gnumeric.org/v10.dtd");
978 workbook.setAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
979 workbook.setAttribute(
"xmlns:schemaLocation",
"http://www.gnumeric.org/v8.xsd");
980 gnumeric_doc.appendChild(workbook);
984 TQDomElement sheets,sheet,tmp,cells,selections, cols,rows,styles,merged, margins, top, left, bottom, right, orientation, paper, header, footer, customSize, cellComment, objects, repeatColumns, repeatRows;
986 KoDocumentInfo *DocumentInfo = document->documentInfo();
987 KoDocumentInfoAbout *aboutPage =
static_cast<KoDocumentInfoAbout *
>(DocumentInfo->page(
"about" ));
989 KoDocumentInfoAuthor *authorPage =
static_cast<KoDocumentInfoAuthor*
>(DocumentInfo->page(
"author" ));
994 TQDomElement attributes = gnumeric_doc.createElement(
"gmr:Attributes");
995 workbook.appendChild(attributes);
997 addAttributeItem(gnumeric_doc, attributes,
"4",
"WorkbookView::show_horizontal_scrollbar", ksdoc->showHorizontalScrollBar());
998 addAttributeItem(gnumeric_doc, attributes,
"4",
"WorkbookView::show_vertical_scrollbar", ksdoc->showVerticalScrollBar());
999 addAttributeItem(gnumeric_doc, attributes,
"4",
"WorkbookView::show_notebook_tabs", ksdoc->showTabBar());
1000 if (ksdoc->completionMode() == TDEGlobalSettings::CompletionAuto)
1001 addAttributeItem(gnumeric_doc, attributes,
"4",
"WorkbookView::do_auto_completion",
"true");
1003 addAttributeItem(gnumeric_doc, attributes,
"4",
"WorkbookView::do_auto_completion",
"false");
1004 addAttributeItem(gnumeric_doc, attributes,
"4",
"WorkbookView::is_protected", ksdoc->map()->isProtected());
1009 TQDomElement summary = gnumeric_doc.createElement(
"gmr:Summary");
1010 workbook.appendChild(summary);
1012 addSummaryItem(gnumeric_doc, summary,
"title", aboutPage->title());
1013 addSummaryItem(gnumeric_doc, summary,
"company", authorPage->company());
1014 addSummaryItem(gnumeric_doc, summary,
"author", authorPage->fullName());
1015 addSummaryItem(gnumeric_doc, summary,
"comments", aboutPage->abstract());
1016 addSummaryItem(gnumeric_doc, summary,
"keywords", aboutPage->keywords());
1018 addSummaryItem(gnumeric_doc, summary,
"application",
"KSpread");
1023 TQDomElement sheetNameIndex = gnumeric_doc.createElement(
"gmr:SheetNameIndex");
1024 workbook.appendChild(sheetNameIndex);
1026 for (table = ksdoc->map()->firstSheet(); table != 0L; table =ksdoc->map()->nextSheet())
1028 TQDomElement sheetName = gnumeric_doc.createElement(
"gmr:SheetName");
1029 sheetName.appendChild(gnumeric_doc.createTextNode(table->tableName()));
1030 sheetNameIndex.appendChild(sheetName);
1050 if ( ksdoc->listArea().count()>0 )
1052 TQDomElement areaNames = gnumeric_doc.createElement(
"gmr:Names");
1053 const TQValueList<Reference> &area = ksdoc->listArea();
1054 TQValueList<Reference>::ConstIterator it = area.begin();
1055 TQValueList<Reference>::ConstIterator end = area.end();
1056 for ( ; it != end; ++it )
1058 TQDomElement areaName = gnumeric_doc.createElement(
"gmr:Name");
1059 TQDomElement areaNameElement = gnumeric_doc.createElement(
"gmr:name");
1060 areaNameElement.appendChild(gnumeric_doc.createTextNode(( *it ).ref_name) );
1061 areaName.appendChild( areaNameElement );
1062 TQDomElement areaNameValue = gnumeric_doc.createElement(
"gmr:value");
1063 areaNameValue.appendChild(gnumeric_doc.createTextNode( convertRefToRange( ( *it ).sheet_name, ( *it ).rect ) ) );
1064 areaName.appendChild( areaNameValue );
1065 areaNames.appendChild( areaName );
1068 workbook.appendChild(areaNames);
1075 sheets = gnumeric_doc.createElement(
"gmr:Sheets");
1076 workbook.appendChild(sheets);
1080 View * view =
static_cast<View*
>( ksdoc->views().getFirst());
1082 TQString activeTableName;
1085 canvas = view->canvasWidget();
1086 activeTableName = canvas->activeSheet()->sheetName();
1089 int indexActiveTable=0;
1090 for (table = ksdoc->map()->firstSheet(); table != 0L; table =ksdoc->map()->nextSheet(), i++)
1092 if ( table->print()->paperFormat()==PG_CUSTOM )
1094 customSize = gnumeric_doc.createElement(
"gmr:Geometry" );
1095 customSize.setAttribute(
"Width", POINT_TO_MM ( table->print()->paperWidth() ));
1096 customSize.setAttribute(
"Height", POINT_TO_MM (table->print()->paperWidth() ));
1097 sheets.appendChild(customSize);
1101 sheet = gnumeric_doc.createElement(
"gmr:Sheet");
1102 sheets.appendChild(sheet);
1104 sheet.setAttribute(
"DisplayFormulas", table->getShowFormula() ?
"true" :
"false" );
1105 sheet.setAttribute(
"HideZero", table->getHideZero()?
"true" :
"false");
1106 sheet.setAttribute(
"HideGrid", !table->getShowGrid()?
"true" :
"false");
1107 sheet.setAttribute(
"HideColHeader", ( !ksdoc->showColumnHeader() ?
"true" :
"false" ));
1108 sheet.setAttribute(
"HideRowHeader", ( !ksdoc->showRowHeader()?
"true" :
"false" ));
1117 tmp = gnumeric_doc.createElement(
"gmr:Name");
1118 if ( table->tableName()==activeTableName )
1119 indexActiveTable = i;
1121 tmp.appendChild(gnumeric_doc.createTextNode(table->tableName()));
1123 sheet.appendChild(tmp);
1125 tmp = gnumeric_doc.createElement(
"gmr:MaxCol");
1126 tmp.appendChild(gnumeric_doc.createTextNode(TQString::number(table->maxColumn())));
1127 sheet.appendChild(tmp);
1129 tmp = gnumeric_doc.createElement(
"gmr:MaxRow");
1131 tmp.appendChild(gnumeric_doc.createTextNode(TQString::number(table->maxRow())));
1132 sheet.appendChild(tmp);
1136 tmp = gnumeric_doc.createElement(
"gmr:Zoom");
1138 tmp.appendChild(gnumeric_doc.createTextNode(TQString::number(canvas->zoom())));
1140 tmp.appendChild(gnumeric_doc.createTextNode(
"1.0"));
1141 sheet.appendChild(tmp);
1144 tmp = gnumeric_doc.createElement(
"gmr:PrintInformation" );
1145 margins = gnumeric_doc.createElement(
"gmr:Margins" );
1147 top = gnumeric_doc.createElement(
"gmr:top" );
1148 top.setAttribute(
"Points", table->print()->topBorder());
1149 top.setAttribute(
"PrefUnit",
"mm");
1150 margins.appendChild( top );
1152 bottom = gnumeric_doc.createElement(
"gmr:bottom" );
1153 bottom.setAttribute(
"Points", table->print()->bottomBorder());
1154 bottom.setAttribute(
"PrefUnit",
"mm");
1155 margins.appendChild( bottom );
1157 left = gnumeric_doc.createElement(
"gmr:left" );
1158 left.setAttribute(
"Points", table->print()->leftBorder());
1159 left.setAttribute(
"PrefUnit",
"mm");
1160 margins.appendChild( left );
1162 right = gnumeric_doc.createElement(
"gmr:right" );
1163 right.setAttribute(
"Points", table->print()->rightBorder());
1164 right.setAttribute(
"PrefUnit",
"mm");
1165 margins.appendChild( right );
1167 tmp.appendChild( margins );
1168 sheet.appendChild(tmp);
1170 orientation = gnumeric_doc.createElement(
"gmr:orientation" );
1171 TQString orientString = table->print()->orientation() == PG_LANDSCAPE ?
"landscape" :
"portrait";
1172 orientation.appendChild( gnumeric_doc.createTextNode(orientString) );
1173 tmp.appendChild( orientation );
1179 int _tmpRepeatColumnStart = table->print()->printRepeatColumns().first;
1180 int _tmpRepeatColumnEnd = table->print()->printRepeatColumns().second;
1181 if ( _tmpRepeatColumnStart!=0 )
1183 repeatColumns = gnumeric_doc.createElement(
"gmr:repeat_left" );
1184 TQString value = Cell::columnName( _tmpRepeatColumnStart )+
"1:"+Cell::columnName(_tmpRepeatColumnEnd )+
"65536";
1185 repeatColumns.setAttribute(
"value", value );
1186 tmp.appendChild( repeatColumns );
1188 int _tmpRepeatRowStart = table->print()->printRepeatRows().first;
1189 int _tmpRepeatRowEnd = table->print()->printRepeatRows().second;
1190 if ( _tmpRepeatRowStart!=0 )
1192 repeatRows = gnumeric_doc.createElement(
"gmr:repeat_top" );
1193 TQString value =
"A"+ TQString::number(_tmpRepeatRowStart ) +
":IV"+TQString::number( _tmpRepeatRowEnd );
1194 repeatRows.setAttribute(
"value", value );
1195 tmp.appendChild( repeatRows );
1198 header = gnumeric_doc.createElement(
"gmr:Header" );
1199 header.setAttribute(
"Left", convertVariable(table->print()->headLeft() ) );
1200 header.setAttribute(
"Middle", convertVariable(table->print()->headMid() ) );
1201 header.setAttribute(
"Right", convertVariable(table->print()->headRight() ) );
1202 tmp.appendChild( header );
1204 footer = gnumeric_doc.createElement(
"gmr:Footer" );
1205 footer.setAttribute(
"Left", convertVariable( table->print()->footLeft() ) );
1206 footer.setAttribute(
"Middle", convertVariable( table->print()->footMid() ) );
1207 footer.setAttribute(
"Right", convertVariable( table->print()->footRight() ));
1208 tmp.appendChild( footer );
1210 paper = gnumeric_doc.createElement(
"gmr:paper" );
1211 paper.appendChild( gnumeric_doc.createTextNode( table->print()->paperFormatString() ) );
1212 tmp.appendChild( paper );
1214 styles = gnumeric_doc.createElement(
"gmr:Styles");
1215 sheet.appendChild(styles);
1217 cells = gnumeric_doc.createElement(
"gmr:Cells");
1218 sheet.appendChild(cells);
1220 objects = gnumeric_doc.createElement(
"gmr:Objects");
1221 sheet.appendChild(objects);
1223 merged = gnumeric_doc.createElement(
"gmr:MergedRegions");
1224 bool mergedCells =
false;
1229 cols = gnumeric_doc.createElement(
"gmr:Cols");
1230 sheet.appendChild(cols);
1232 rows = gnumeric_doc.createElement(
"gmr:Rows");
1233 sheet.appendChild(rows);
1243 int iMaxColumn = table->maxColumn();
1244 int iMaxRow = table->maxRow();
1249 int step=iMaxRow > 50 ? iMaxRow/50 : 1;
1252 TQString emptyLines;
1275 ColumnFormat *cl=table->firstCol();
1278 TQDomElement colinfo = gnumeric_doc.createElement(
"gmr:ColInfo");
1279 cols.appendChild(colinfo);
1280 colinfo.setAttribute(
"No", TQString::number(cl->column()-1));
1281 colinfo.setAttribute(
"Hidden", TQString::number(cl->isHide()));
1282 colinfo.setAttribute(
"Unit", TQString::number(cl->dblWidth()));
1293 RowFormat *rl=table->firstRow();
1296 TQDomElement rowinfo = gnumeric_doc.createElement(
"gmr:RowInfo");
1297 rows.appendChild(rowinfo);
1298 rowinfo.setAttribute(
"No", TQString::number(rl->row()-1));
1299 rowinfo.setAttribute(
"Hidden", TQString::number(rl->isHide()));
1300 rowinfo.setAttribute(
"Unit", TQString::number(rl->dblHeight()));
1317 for (
int currentrow = 1; currentrow <= iMaxRow; ++currentrow, ++i)
1322 emit sigProgress(value);
1327 for (
int currentcolumn = 1; currentcolumn <= iMaxColumn; currentcolumn++)
1329 TQDomElement cell_contents;
1330 Cell * cell = table->cellAt( currentcolumn, currentrow,
false );
1332 TQString text, style;
1333 TQDomDocument domLink;
1334 TQDomElement domRoot;
1336 TQDomNodeList childNodes;
1338 if (!cell->isDefault() && !cell->isEmpty())
1340 if ( cell->isFormula() )
1342 TQString tmp = cell->text();
1343 if ( tmp.contains(
"==" ) )
1344 tmp=tmp.replace(
"==",
"=" );
1348 else if ( !cell->link().isEmpty() )
1352 isLinkItalic =
false;
1354 linkUrl = cell->link();
1355 linkText = cell->text();
1360 text = cell->text();
1364 switch (cell->content())
1367 text = cell->text();
1370 case Cell::RichText:
1375 isLinkItalic =
false;
1376 domLink.setContent(cell->text().section(
"!",1,1));
1378 domNode = domLink.firstChild();
1379 domRoot = domNode.toElement();
1380 text = domNode.toElement().text();
1382 while (!domNode.isNull())
1384 style = domNode.toElement().tagName();
1390 isLinkItalic =
true;
1392 domNode = domNode.firstChild();
1397 linkUrl = domRoot.attribute(
"href");
1401 case Cell::VisualFormula:
1403 text = cell->text();
1407 TQString tmp = cell->text();
1409 tmp=replace(
"==",
"=" );
1417 if (!cell->isDefault())
1424 if (cell->doesMergeCells())
1427 TQDomElement merge = gnumeric_doc.createElement(
"gmr:Merge");
1430 TQString fromCol, toCol, fromRow, toRow;
1431 fromCol = cell->columnName(currentcolumn);
1432 fromRow = TQString::number(currentrow);
1433 toCol = cell->columnName(currentcolumn + cell->mergedXCells());
1434 toRow = TQString::number(currentrow + cell->mergedYCells());
1436 merge.appendChild(gnumeric_doc.createTextNode(fromCol + fromRow +
":" + toCol + toRow));
1438 merged.appendChild(merge);
1441 if ( !cell->format()->comment( currentcolumn, currentrow ).isEmpty() )
1444 cellComment = gnumeric_doc.createElement(
"gmr:CellComment");
1445 cellComment.setAttribute(
"Text", cell->format()->comment( currentcolumn, currentrow ) );
1446 TQString sCell=TQString(
"%1%2" ).arg( Cell::columnName(currentcolumn ) ).arg( currentrow );
1448 cellComment.setAttribute(
"ObjectBound", sCell );
1449 objects.appendChild(cellComment);
1452 TQDomElement gnumeric_cell = gnumeric_doc.createElement(
"gmr:Cell");
1453 TQDomElement cell_style;
1455 TQDomElement style_region = gnumeric_doc.createElement(
"gmr:StyleRegion");
1457 cells.appendChild(gnumeric_cell);
1459 gnumeric_cell.setAttribute(
"Col", TQString::number(currentcolumn-1));
1460 gnumeric_cell.setAttribute(
"Row", TQString::number(currentrow-1));
1467 style_region.setAttribute(
"startCol", TQString::number(currentcolumn-1));
1468 style_region.setAttribute(
"startRow", TQString::number(currentrow-1));
1469 style_region.setAttribute(
"endCol", TQString::number(currentcolumn-1));
1470 style_region.setAttribute(
"endRow", TQString::number(currentrow-1));
1472 cell_style = GetCellStyle(gnumeric_doc,cell,currentcolumn,currentrow);
1474 style_region.appendChild(cell_style);
1476 styles.appendChild(style_region);
1479 gnumeric_cell.appendChild(gnumeric_doc.createTextNode(text));
1489 sheet.appendChild(merged);
1491 TQDomElement uidata = gnumeric_doc.createElement(
"gmr:UIData");
1492 uidata.setAttribute(
"SelectedTab", indexActiveTable );
1493 workbook.appendChild(uidata);
1495 str = gnumeric_doc.toString ();
1497 emit sigProgress(100);
1501 TQIODevice* out = KFilterDev::deviceForFile(m_chain->outputFile(),
"application/x-gzip");
1505 kdError(30521) <<
"No output file! Aborting!" << endl;
1506 return KoFilter::FileNotFound;
1509 if (!out->open(IO_WriteOnly))
1511 kdError(30521) <<
"Unable to open output file! Aborting!" << endl;
1513 return KoFilter::FileNotFound;
1516 TQTextStream streamOut(out);
1523 return KoFilter::OK;
1527TQString GNUMERICExport::convertRefToRange(
const TQString & table,
const TQRect & rect )
1529 TQPoint topLeft( rect.topLeft() );
1530 TQPoint bottomRight( rect.bottomRight() );
1531 if ( topLeft == bottomRight )
1532 return convertRefToBase( table, rect );
1536 s += Cell::columnName( topLeft.x() );
1538 s += TQString::number( topLeft.y() );
1540 s += Cell::columnName( bottomRight.x() );
1542 s += TQString::number( bottomRight.y() );
1548TQString GNUMERICExport::convertRefToBase(
const TQString & table,
const TQRect & rect )
1550 TQPoint bottomRight( rect.bottomRight() );
1555 s += Cell::columnName( bottomRight.x() );
1557 s += TQString::number( bottomRight.y() );
1562TQString GNUMERICExport::convertVariable( TQString headerFooter )
1564 headerFooter = headerFooter.replace(
"<sheet>",
"&[TAB]" );
1565 headerFooter = headerFooter.replace(
"<date>",
"&[DATE]" );
1566 headerFooter = headerFooter.replace(
"<page>",
"&[PAGE]" );
1567 headerFooter = headerFooter.replace(
"<pages>",
"&[PAGES]" );
1568 headerFooter = headerFooter.replace(
"<time>",
"&[TIME]" );
1569 headerFooter = headerFooter.replace(
"<file>",
"&[FILE]" );
1571 return headerFooter;
1574#include "gnumericexport.moc"