34 bool datareaded=
false;
36 QString tname =
"Generated table";
39 bool bordereddata =
false;
40 bool putcolumnwidthsett =
false;
41 bool putheader =
true;
44 if(params.contains(
"bordered_data"))
46 if(params.contains(
"set_columnwidth"))
47 putcolumnwidthsett =
true;
48 if(params.contains(
"without_header"))
50 if(params.contains(
"notitle"))
55 if( !((
HTableBase *)d)->tableTitle().isEmpty() )
57 rowCount = ((
HTable *)d)->recordCount();
58 columnCount = ((
HTable *)d)->fieldCount();
63 if( !((
HTableBase *)d)->tableTitle().isEmpty() )
65 rowCount = ((
HList *)d)->recordCount();
66 columnCount = ((
HList *)d)->fieldCount();
76 if(tname.length() > 18)
77 tnameshort = tname.left(15).append(
"...");
98 xml.
putRawData(
"<?xml version=\"1.0\"?>\n<?mso-application progid=\"Excel.Sheet\"?>\n");
99 xml.
beginNode(
"Workbook",
"xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"\n"
100 " xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n"
101 " xmlns:x=\"urn:schemas-microsoft-com:office:excel\"\n"
102 " xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"\n"
103 " xmlns:html=\"http://www.w3.org/TR/REC-html40\"");
104 xml.
beginNode(
"DocumentProperties",
"xmlns=\"urn:schemas-microsoft-com:office:office\"");
112 xml.
beginNode(
"ExcelWorkbook",
"xmlns=\"urn:schemas-microsoft-com:office:excel\"");
113 xml.
putCData(
"WindowHeight",
"8775");
114 xml.
putCData(
"WindowWidth",
"14160");
117 xml.
putCData(
"ProtectStructure",
"False");
118 xml.
putCData(
"ProtectWindows",
"False");
122 xml.
beginNode(
"Style",
"ss:ID=\"Default\" ss:Name=\"Normal\"");
134 xml.
putEmptyNode(
"Font",
"x:CharSet=\"238\" x:Family=\"Swiss\" ss:Bold=\"1\"");
138 xml.
putEmptyNode(
"Font",
"x:CharSet=\"238\" x:Family=\"Swiss\" ss:Size=\"14\" ss:Bold=\"1\"");
139 xml.
putEmptyNode(
"Alignment",
"ss:Vertical=\"Top\" ss:WrapText=\"0\"");
144 xml.
putEmptyNode(
"Border",
"ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"");
145 xml.
putEmptyNode(
"Border",
"ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"");
146 xml.
putEmptyNode(
"Border",
"ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"");
147 xml.
putEmptyNode(
"Border",
"ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"");
152 xml.
putEmptyNode(
"Font",
"x:CharSet=\"238\" x:Family=\"Swiss\" ss:Bold=\"1\"");
154 xml.
putEmptyNode(
"Border",
"ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"");
155 xml.
putEmptyNode(
"Border",
"ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"");
156 xml.
putEmptyNode(
"Border",
"ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"");
157 xml.
putEmptyNode(
"Border",
"ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"");
164 xml.
beginNode(
"Worksheet",QString(
"ss:Name=\"%1\"").arg(tnameshort));
165 xml.
beginNode(
"Table",QString(
"ss:ExpandedColumnCount=\"%1\" ss:ExpandedRowCount=\"%2\""
166 " x:FullColumns=\"1\" x:FullRows=\"1\" ss:DefaultRowHeight=\"15\"")
172 if(putcolumnwidthsett)
173 for(c=0;c<columnCount;++c)
174 xml.
putEmptyNode(
"Column",QString(
"ss:Index=\"%1\" ss:AutoFitWidth=\"1\" ss:Width=\"%2\"")
183 xml.
beginNode(
"Row",
"ss:StyleID=\"s22\"");
185 xml.
putCData(
"Data",tname,
"ss:Type=\"String\"");
204 xml.
beginNode(
"Row",
"ss:StyleID=\"s24\"");
208 xml.
beginNode(
"Cell",(bordereddata ?
"ss:StyleID=\"s23\"" :
""));
227 xml.
beginNode(
"Row",
"ss:StyleID=\"s24\"");
228 for(i =0;i < (int)sl.size();++i)
231 xml.
putCData(
"Data",sl[i],
"ss:Type=\"String\"");
237 QList<QStringList *>::Iterator iv = data->
getValues()->begin();
241 xml.
beginNode(
"Row",(bordereddata ?
"ss:StyleID=\"s23\"" :
""));
243 for(i =0;i < (int)sl.size();++i)
246 xml.
putCData(
"Data",sl[i],
"ss:Type=\"String\"");
266 xml.
beginNode(
"Row",
"ss:StyleID=\"s24\"");
267 for(i=0;i < (int)sl.size();++i)
270 xml.
putCData(
"Data",sl[i],
"ss:Type=\"String\"");
282 xml.
beginNode(
"Row",(bordereddata ?
"ss:StyleID=\"s23\"" :
""));
283 for(i =0;i < (int)sl.size();++i)
286 xml.
putCData(
"Data",sl[i],
"ss:Type=\"String\"");
296 error(QString(
"HExcelXmlGenerator::generate: Cannot handle item: Not supported type (%1)!")
301 xml.
beginNode(
"WorksheetOptions",
"xmlns=\"urn:schemas-microsoft-com:office:excel\"");
305 xml.
putEmptyNode(
"PageMargins",
"x:Bottom=\"0.75\" x:Left=\"0.7\" x:Right=\"0.7\" x:Top=\"0.75\"");
311 xml.
putCData(
"ActiveRow",QString(
"%1").arg(rowCount));
312 xml.
putCData(
"ActiveCol",QString(
"%2").arg(columnCount));
316 xml.
putCData(
"ProtectObjects",
"False");
317 xml.
putCData(
"ProtectScenarios",
"False");
326 QTextStream *s =
new QTextStream(&xml);
334 QFile xmlfile(filename);
335 if (!xmlfile.open(QIODevice::WriteOnly))
337 error(QString(GSAFETEXT_CANNOT_CREATE_FILE).arg(filename));
341 QTextStream *s =
new QTextStream(&xmlfile);
349 static const char*
const image_browse_data[] = {
364 "....................",
365 "..#..a#.............",
366 "..a#.ab..a..........",
367 "...a#a#.a#..........",
368 "....a#ba#...........",
369 "..aaab##aaaaaaaaaa..",
370 "....#abbbbbbbbbbbc..",
371 "..abda#bbbefbbghbc..",
372 "..#.aac#bbijbbfjbc..",
373 "....abddbbddbbddbc..",
374 "....abbbbbbbbbbbbc..",
375 "....abfjbbikbbfibc..",
376 "....abghbbafbbaebc..",
377 "....abddbbddbbddbc..",
378 "....abbbbbbbbbbbbc..",
379 "....accccccccccccc..",
380 "....................",
381 "....................",
382 "....................",
383 "...................."};
391 setWindowTitle(GSAFETEXT_XMLO_WINTITLE);
393 QVBoxLayout *mainlayout =
new QVBoxLayout(
this);
394 QHBoxLayout *toplayout =
new QHBoxLayout(0);
395 QHBoxLayout *midlayout =
new QHBoxLayout(0);
396 QHBoxLayout *buttlayout =
new QHBoxLayout(0);
398 QLabel *label1 =
new QLabel(GSAFETEXT_XMLO_GETLABEL,
this);
399 QPushButton *savePushButton =
new QPushButton(
this);
400 savePushButton->setText(GSAFETEXT_SAVE);
401 QPushButton *closePushButton =
new QPushButton(
this);
402 closePushButton->setText(GSAFETEXT_CLOSE);
403 fnedit =
new QLineEdit(
this);
404 fnedit->setText(
"output.xml");
405 QToolButton *fcToolButton =
new QToolButton(
this);
406 fcToolButton->setIcon(QIcon( QPixmap( (
const char **) image_browse_data ) ));
408 toplayout->addStretch();
409 toplayout->addWidget(label1);
410 toplayout->addStretch();
412 midlayout->addStretch();
413 midlayout->addWidget(fnedit);
414 midlayout->addSpacing(10);
415 midlayout->addWidget(fcToolButton);
416 midlayout->addStretch();
418 buttlayout->addStretch();
419 buttlayout->addWidget(savePushButton);
420 buttlayout->addSpacing(10);
421 buttlayout->addWidget(closePushButton);
422 buttlayout->addStretch();
424 mainlayout->addSpacing(15);
425 mainlayout->addLayout(toplayout);
426 mainlayout->addSpacing(10);
427 mainlayout->addLayout(midlayout);
428 mainlayout->addStretch();
429 mainlayout->addLayout(buttlayout);
430 mainlayout->addSpacing(20);
432 setSizeGripEnabled(
true);
434 connect(fcToolButton,SIGNAL(clicked()),
this,SLOT(cf()));
435 connect(savePushButton,SIGNAL(clicked()),
this,SLOT(saveButton()));
436 connect(closePushButton,SIGNAL(clicked()),
this,SLOT(closeButton()));
444 int HXmloTable::cf(
void)
447 o = QFileDialog::getSaveFileName(
this,GSAFETEXT_XMLO_OUTFILETITLE,
"",
"*.xml");
453 int HXmloTable::saveButton(
void)
460 if(fnedit->text().isEmpty())
463 QFile f(fnedit->text());
464 if (f.open(QIODevice::WriteOnly))
466 QTextStream *s =
new QTextStream(&f);
467 s->setCodec(QTextCodec::codecForName(
"UTF-8"));
468 xmlgen.
generate(data,s,
"bordered_data set_columnwidth");
473 error(QString(GSAFETEXT_CANNOT_CREATE_FILE).arg(fnedit->text()));
480 int HXmloTable::closeButton(
void)
HDataField * nextFieldAll(void)
void generate(HBase *d, QTextStream *s, QString params="")
QStringList getShortTitleHeads(void)
void beginNode(QString n, QString parameters="")
QString generateToString(HBase *d, QString params="")
HXmloTable(QWidget *parent, HBase *d)
void putRawData(QString data)
virtual QList< QStringList * > * getValues(void)
void putCData(QString n, QString data, QString parameters="")
void setStream(QTextStream *oo)
void putEmptyNode(QString n, QString parameters="")
QList< QString > currentRowStr(void)
virtual QVariant dbValueToDispValue(QVariant v)
~HExcelXmlGenerator(void)
QString getExplainText(void)
virtual QVariant getValue(void)
void generateToFile(HBase *d, QString filename, QString params="")
QList< QString > getHeader(void)