libodsstream
Library for mass spectrometry
Loading...
Searching...
No Matches
contentxml.cpp
Go to the documentation of this file.
1/*
2 libodsstream is a library to read and write ODS documents as streams
3 Copyright (C) 2013 Olivier Langella <Olivier.Langella@moulon.inra.fr>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18*/
19
20#include <algorithm>
21#include <QDebug>
22#include "contentxml.h"
23#include "metaxml.h"
24#include "../../odsexception.h"
25
26QString ContentXml::_xsdNamespaceURI = "http://www.w3.org/2001/XMLSchema";
28 "http://www.w3.org/2001/XMLSchema-instance";
29
30ContentXml::ContentXml(QuaZip *p_quaZip, SettingsXml *p_settings_xml)
31 : _outFile(p_quaZip)
32{
33 QuaZipNewInfo info("content.xml");
34 _outFile.open(QIODevice::WriteOnly, info);
35 _p_writer = new QXmlStreamWriter(&_outFile);
36 _p_writer->setAutoFormatting(true);
37 this->WriteHeader();
38 _p_settings_xml = p_settings_xml;
39}
40
44
45void
47{
48 _tableRowStarted = false;
49 _tableStarted = false;
50 _p_writer->writeStartDocument("1.0");
51 /*
52 * <office:document-content office:version="1.2"
53 * xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
54 * xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
55 * xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
56 * xmlns:db="urn:oasis:names:tc:opendocument:xmlns:database:1.0"
57 * xmlns:dc="http://purl.org/dc/elements/1.1/"
58 * xmlns:dom="http://www.w3.org/2001/xml-events"
59 * xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
60 * xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
61 * xmlns:fo
62 * ="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
63 * xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
64 * xmlns:grddl="http://www.w3.org/2003/g/data-view#"
65 * xmlns:math="http://www.w3.org/1998/Math/MathML"
66 * xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
67 * xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
68 * xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
69 * xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
70 * xmlns:ooo="http://openoffice.org/2004/office"
71 * xmlns:oooc="http://openoffice.org/2004/calc"
72 * xmlns:ooow="http://openoffice.org/2004/writer" xmlns:presentation=
73 * "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
74 * xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
75 * xmlns:
76 * smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
77 * xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
78 * xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
79 * xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
80 * xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
81 * xmlns:xforms="http://www.w3.org/2002/xforms"
82 * xmlns:xhtml="http://www.w3.org/1999/xhtml"
83 * xmlns:xlink="http://www.w3.org/1999/xlink"
84 * xmlns:xsd="http://www.w3.org/2001/XMLSchema"
85 * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
86 */
87
89
90 auto it = MetaXml::_hash_namespace_uri.begin();
91 while(it != MetaXml::_hash_namespace_uri.end())
92 {
93 _p_writer->writeNamespace(it->second, it->first);
94 it++;
95 }
96 // xmlns:xsd="http://www.w3.org/2001/XMLSchema"
97 _p_writer->writeNamespace(_xsdNamespaceURI, "xsd");
98
99 // xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
100 _p_writer->writeNamespace(_xsiNamespaceURI, "xsi");
101
102 _p_writer->writeStartElement(MetaXml::getNamespaceURI("office"),
103 "document-content");
104 _p_writer->writeAttribute(
105 MetaXml::getNamespaceURI("office"), "version", "1.2");
106
107
108 // <office:scripts/>
109 _p_writer->writeStartElement(MetaXml::getNamespaceURI("office"), "scripts");
110 _p_writer->writeEndElement();
111
112 // <office:font-face-decls>
114}
115
116
117void
119{
120 _p_writer->writeStartElement(MetaXml::getNamespaceURI("office"),
121 "font-face-decls");
122 /**
123 * <style:font-face style:font-family-generic="swiss"
124 * style:font-pitch="variable" style:name="Arial"
125 * svg:font-family="Arial"/>
126 * */
127 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"), "font-face");
128 _p_writer->writeAttribute(
129 MetaXml::getNamespaceURI("style"), "font-family-generic", "swiss");
130 _p_writer->writeAttribute(
131 MetaXml::getNamespaceURI("style"), "font-pitch", "variable");
132 _p_writer->writeAttribute(MetaXml::getNamespaceURI("style"), "name", "Arial");
133 _p_writer->writeAttribute(
134 MetaXml::getNamespaceURI("svg"), "font-family", "Arial");
135 _p_writer->writeEndElement();
136
137 _p_writer->writeEndElement();
138}
139
140
141void
143{
144
146 return;
148
149 // <office:body>
150 _p_writer->writeStartElement(MetaXml::getNamespaceURI("office"), "body");
151 // <office:spreadsheet>
152 _p_writer->writeStartElement(MetaXml::getNamespaceURI("office"),
153 "spreadsheet");
154}
155
156void
158{
159
161 return;
163
164 /*
165 * <office:automatic-styles>
166 *
167 *
168 *
169 *
170 *
171 *
172 *
173 *
174 *
175 *
176 *
177 *
178 * </office:automatic-styles>
179 */
180 /*
181 *
182 * <office:automatic-styles>
183 */
184 _p_writer->writeStartElement(MetaXml::getNamespaceURI("office"),
185 "automatic-styles");
186 /*
187 * <style:style style:name="ce1" style:family="table-cell"
188 * style:parent-style-name="Default" style:data-style-name="N0" />
189 */
190 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"), "style");
191 _p_writer->writeAttribute(MetaXml::getNamespaceURI("style"), "name", "ce1");
192 _p_writer->writeAttribute(
193 MetaXml::getNamespaceURI("style"), "family", "table-cell");
194 _p_writer->writeAttribute(
195 MetaXml::getNamespaceURI("style"), "parent-style-name", "Default");
196 _p_writer->writeAttribute(
197 MetaXml::getNamespaceURI("style"), "data-style-name", "N0");
198 _p_writer->writeEndElement();
199
200 /*
201 * <style:style style:name="ce2" style:family="table-cell"
202 * style:parent-style-name="Default" style:data-style-name="N36" />
203 */
204 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"), "style");
205 _p_writer->writeAttribute(MetaXml::getNamespaceURI("style"), "name", "ce2");
206 _p_writer->writeAttribute(
207 MetaXml::getNamespaceURI("style"), "family", "table-cell");
208 _p_writer->writeAttribute(
209 MetaXml::getNamespaceURI("style"), "parent-style-name", "Default");
210 _p_writer->writeAttribute(
211 MetaXml::getNamespaceURI("style"), "data-style-name", "N36");
212 _p_writer->writeEndElement();
213 // <style:style style:name="co1" style:family="table-column">
214 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"), "style");
215 _p_writer->writeAttribute(MetaXml::getNamespaceURI("style"), "name", "co1");
216 _p_writer->writeAttribute(
217 MetaXml::getNamespaceURI("style"), "family", "table-column");
218
219 /*
220 * <style:table-column-properties fo:break-before="auto"
221 * style:column-width="2.27541666666667cm" />
222 */
223 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"),
224 "table-column-properties");
225 _p_writer->writeAttribute(
226 MetaXml::getNamespaceURI("fo"), "break-before", "auto");
227 _p_writer->writeAttribute(
228 MetaXml::getNamespaceURI("style"), "column-width", "2.27541666666667cm");
229 _p_writer->writeEndElement();
230 // </style:style>
231 _p_writer->writeEndElement();
232
233 // <style:style style:name="co2" style:family="table-column">
234 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"), "style");
235 _p_writer->writeAttribute(MetaXml::getNamespaceURI("style"), "name", "co2");
236 _p_writer->writeAttribute(
237 MetaXml::getNamespaceURI("style"), "family", "table-column");
238 // <style:table-column-properties
239 // fo:break-before="auto" style:column-width="2.11666666666667cm" />
240 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"),
241 "table-column-properties");
242 _p_writer->writeAttribute(
243 MetaXml::getNamespaceURI("fo"), "break-before", "auto");
244 _p_writer->writeAttribute(
245 MetaXml::getNamespaceURI("style"), "column-width", "2.27541666666667cm");
246 _p_writer->writeEndElement();
247 // </style:style>
248 _p_writer->writeEndElement();
249 // <style:style style:name="ro1" style:family="table-row">
250 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"), "style");
251 _p_writer->writeAttribute(MetaXml::getNamespaceURI("style"), "name", "ro1");
252 _p_writer->writeAttribute(
253 MetaXml::getNamespaceURI("style"), "family", "table-row");
254
255 // <style:table-row-properties
256 // style:row-height="15pt" style:use-optimal-row-height="true"
257 // fo:break-before="auto" />
258 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"),
259 "table-row-properties");
260 _p_writer->writeAttribute(
261 MetaXml::getNamespaceURI("style"), "row-height", "15pt");
262 _p_writer->writeAttribute(
263 MetaXml::getNamespaceURI("style"), "use-optimal-row-height", "true");
264 _p_writer->writeAttribute(
265 MetaXml::getNamespaceURI("fo"), "break-before", "auto");
266 _p_writer->writeEndElement();
267 // </style:style>
268 _p_writer->writeEndElement();
269
270 // <style:style style:name="ta1" style:family="table"
271 // style:master-page-name="mp1">
272 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"), "style");
273 _p_writer->writeAttribute(MetaXml::getNamespaceURI("style"), "name", "ta1");
274 _p_writer->writeAttribute(
275 MetaXml::getNamespaceURI("style"), "family", "table");
276 _p_writer->writeAttribute(
277 MetaXml::getNamespaceURI("style"), "master-page-name", "mp1");
278 // <style:table-properties table:display="true"
279 // style:writing-mode="lr-tb" />
280 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"),
281 "table-properties");
282 _p_writer->writeAttribute(
283 MetaXml::getNamespaceURI("table"), "display", "true");
284 _p_writer->writeAttribute(
285 MetaXml::getNamespaceURI("style"), "writing-mode", "lr-tb");
286 _p_writer->writeEndElement();
287
288 // </style:style>
289 _p_writer->writeEndElement();
290
291 /*
292 *
293 <style:style style:name="ce3" style:family="table-cell"
294 style:parent-style-name="Default" style:data-style-name="N0">
295 <style:table-cell-properties fo:background-color="#ffff00"/>
296 <style:text-properties fo:color="#800000"/>
297 </style:style>
298 */
299
300 for(unsigned int i = 0; i < _style2write.size(); i++)
301 {
302 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"), "style");
303 _p_writer->writeAttribute(MetaXml::getNamespaceURI("style"),
304 "name",
305 _style_ref_list[i]->_ref_str);
306 _p_writer->writeAttribute(
307 MetaXml::getNamespaceURI("style"), "family", "table-cell");
308 _p_writer->writeAttribute(
309 MetaXml::getNamespaceURI("style"), "parent-style-name", "Default");
310 _p_writer->writeAttribute(
311 MetaXml::getNamespaceURI("style"), "data-style-name", "N0");
312
313 if(_style2write[i]._background_color.isValid())
314 {
315 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"),
316 "table-cell-properties");
317 _p_writer->writeAttribute(MetaXml::getNamespaceURI("fo"),
318 "background-color",
319 _style2write[i]._background_color.name());
320 _p_writer->writeEndElement();
321 }
322 if(_style2write[i]._text_color.isValid())
323 {
324 _p_writer->writeStartElement(MetaXml::getNamespaceURI("style"),
325 "text-properties");
326 _p_writer->writeAttribute(MetaXml::getNamespaceURI("fo"),
327 "color",
328 _style2write[i]._text_color.name());
329 _p_writer->writeEndElement();
330 }
331
332 _p_writer->writeEndElement();
333 }
334 _p_writer->writeEndElement();
335}
336
337void
339{
340
343
345 _p_writer->writeEndDocument();
346
347 this->_outFile.close();
348
349 delete _p_writer;
350}
351
352std::vector<OdsColorScale>
354{
355 std::vector<OdsColorScale> color_scale_list;
356
357 for(OdsColorScale color_scale : _color_scale_list)
358 {
359 if(color_scale.isInSheet(sheet_name))
360 {
361 color_scale_list.push_back(color_scale);
362 }
363 }
364
365 return color_scale_list;
366}
367
368void
370{
372 {
373 _p_writer->writeEndElement();
374 }
375
376 if(_tableStarted)
377 {
378 std::vector<OdsColorScale> sheet_color_scale_list =
380 if(sheet_color_scale_list.size() > 0)
381 {
382 /*
383 <calcext:conditional-formats>
384 <calcext:conditional-format
385 calcext:target-range-address="classeur.A5:classeur.E6" >
386 <calcext:color-scale>
387 <calcext:color-scale-entry calcext:value="0"
388 calcext:type="minimum" calcext:color="#0000ff"/>
389 <calcext:color-scale-entry calcext:value="50"
390 calcext:type="percentile" calcext:color="#ffffff"/>
391 <calcext:color-scale-entry calcext:value="0"
392 calcext:type="maximum" calcext:color="#ff0000"/>
393 </calcext:color-scale>
394 </calcext:conditional-format>
395 </calcext:conditional-formats>
396 </table:table>*/
397 //<calcext:conditional-formats>
398 _p_writer->writeStartElement(MetaXml::getNamespaceURI("calcext"),
399 "conditional-formats");
400
401 for(OdsColorScale color_scale : sheet_color_scale_list)
402 {
403 color_scale.writeConditionalFormat(_p_writer);
404 }
405
406 //</calcext:conditional-formats>
407 _p_writer->writeEndElement();
408 }
409
410
411 _p_writer->writeEndElement();
412 }
413
414 _tableStarted = false;
415 _tableRowStarted = false;
416 _row_pos = 0;
417 _col_pos = 0;
418}
419
420
421void
422ContentXml::writeSheet(const QString &tableName)
423{
424
425 _p_settings_xml->addSheetName(tableName);
428
430 _current_sheet_name = tableName;
431 _tableStarted = true;
432
433 /*
434 * <table:table table:name="Feuille1" table:style-name="ta1"
435 * table:print="false">
436 */
437 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table");
438 _p_writer->writeAttribute(
439 MetaXml::getNamespaceURI("table"), "name", tableName);
440 _p_writer->writeAttribute(
441 MetaXml::getNamespaceURI("table"), "style-name", "ta1");
442 _p_writer->writeAttribute(
443 MetaXml::getNamespaceURI("table"), "print", "false");
444
445 /*
446 * <table:table-column table:style-name="co1"
447 * table:default-cell-style-name="ce1" />
448 */
449 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"),
450 "table-column");
451 _p_writer->writeAttribute(
452 MetaXml::getNamespaceURI("table"), "style-name", "co1");
453 _p_writer->writeAttribute(
454 MetaXml::getNamespaceURI("table"), "default-cell-style-name", "ce1");
455 _p_writer->writeEndElement();
456
457 _row_pos = 0;
458 _col_pos = 0;
459}
460
461void
463{
464
467
468 if(_tableStarted == false)
469 {
470 writeSheet();
471 }
473 {
474 // close current row
475 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"),
476 "table-cell");
477 _p_writer->writeEndElement();
478 _p_writer->writeEndElement();
479 }
480 _row_pos++;
481 _col_pos = 0;
482 _tableRowStarted = true;
483 /*
484 * <table:table-row table:style-name="ro1">
485 */
486 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table-row");
487 _p_writer->writeAttribute(
488 MetaXml::getNamespaceURI("table"), "style-name", "ro1");
489}
490
491void
496
497void
498ContentXml::writeCell(double value, const QString &annotation)
499{
500 writeCellFloat(QString::number(value, 'e', 20),
501 QString::number(value, 'g', 20),
502 annotation);
503}
504
505void
506ContentXml::writeCell(std::size_t value, const QString &annotation)
507{
508 QString representation(QString::number(value));
509 writeCellFloat(representation, representation, annotation);
510}
511
512void
513ContentXml::writeCell(int value, const QString &annotation)
514{
515 QString representation(QString::number(value));
516 writeCellFloat(representation, representation, annotation);
517}
518
519
520void
521ContentXml::writeCellPercentage(double value, const QString &annotation)
522{
523 QString representation(QString("%1 %").arg(value * 100));
526
527 if(_tableRowStarted == false)
528 {
529 writeLine();
530 }
531 /*
532 * <table:table-cell office:value-type="percentage" office:value="0.5"
533 * calcext:value-type="percentage">
534 */
535 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table-cell");
536 _p_writer->writeAttribute(
537 MetaXml::getNamespaceURI("office"), "value-type", "percentage");
538 _p_writer->writeAttribute(MetaXml::getNamespaceURI("office"),
539 "value",
540 QString::number(value, 'f', 5));
541 _p_writer->writeAttribute(
542 MetaXml::getNamespaceURI("calcext"), "value-type", "percentage");
543 // table:style-name="ce1"
544 if(_current_style_ref != nullptr)
545 {
546 _p_writer->writeAttribute(MetaXml::getNamespaceURI("table"),
547 "style-name",
549 }
550 else
551 {
552 _p_writer->writeAttribute(
553 MetaXml::getNamespaceURI("table"), "style-name", "ce1");
554 }
555 writeAnnotation(annotation);
556 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "p");
557 //<text:p>50,00 %</text:p></table:table-cell>
558 _p_writer->writeCharacters(representation);
559 _p_writer->writeEndElement();
560
561 /*
562 * </table:table-cell>
563 */
564 _p_writer->writeEndElement();
565 /*
566 * </table:table-row> </table:table> </office:spreadsheet>
567 * </office:body>
568 */
569 _col_pos++;
570}
571
572
573void
574ContentXml::writeCellFloat(const QString &value,
575 const QString &representation,
576 const QString &annotation)
577{
578
581
582 if(_tableRowStarted == false)
583 {
584 writeLine();
585 }
586 /*
587 * <table:table-cell office:value-type="float" office:value="45">
588 */
589 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table-cell");
590 _p_writer->writeAttribute(
591 MetaXml::getNamespaceURI("office"), "value-type", "float");
592 _p_writer->writeAttribute(MetaXml::getNamespaceURI("office"), "value", value);
593 // table:style-name="ce1"
594 if(_current_style_ref != nullptr)
595 {
596 _p_writer->writeAttribute(MetaXml::getNamespaceURI("table"),
597 "style-name",
599 }
600 else
601 {
602 _p_writer->writeAttribute(
603 MetaXml::getNamespaceURI("table"), "style-name", "ce1");
604 }
605 /*
606 * <text:p>45</text:p>
607 */
608 writeAnnotation(annotation);
609 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "p");
610 _p_writer->writeCharacters(representation);
611 _p_writer->writeEndElement();
612
613 /*
614 * </table:table-cell>
615 */
616 _p_writer->writeEndElement();
617 /*
618 * </table:table-row> </table:table> </office:spreadsheet>
619 * </office:body>
620 */
621 _col_pos++;
622}
623
624
625void
626ContentXml::writeEmptyCell(const QString &annotation)
627{
628
631
632 if(_tableRowStarted == false)
633 {
634 writeLine();
635 }
636 /*
637 * <table:table-cell office:value-type="string">
638 */
639 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table-cell");
640 _p_writer->writeAttribute(
641 MetaXml::getNamespaceURI("office"), "value-type", "string");
642 // table:style-name="ce1"
643 if(_current_style_ref != nullptr)
644 {
645 _p_writer->writeAttribute(MetaXml::getNamespaceURI("table"),
646 "style-name",
648 }
649 else
650 {
651 _p_writer->writeAttribute(
652 MetaXml::getNamespaceURI("table"), "style-name", "ce1");
653 }
654 /*
655 * <text:p>45</text:p>
656 */
657 writeAnnotation(annotation);
658 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "p");
659 _p_writer->writeCharacters("");
660 _p_writer->writeEndElement();
661
662 _p_writer->writeEndElement();
663 _col_pos++;
664}
665
666
667void
668ContentXml::writeAnnotation(const QString &annotation)
669{
670 //<office:annotation draw:style-name="gr1" draw:text-style-name="P2"
671 // svg:width="28.99mm" svg:height="10.69mm" svg:x="96.48mm" svg:y="0mm"
672 // draw:caption-point-x="-6.1mm"
673 // draw:caption-point-y="10.68mm"><dc:date>2016-08-19T00:00:00</dc:date>
674 //<text:p text:style-name="P1">Ceci est un commentaire</text:p>
675 //</office:annotation>
676 if(!annotation.isEmpty())
677 {
678 _p_writer->writeStartElement(MetaXml::getNamespaceURI("office"),
679 "annotation");
680 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "p");
681 _p_writer->writeCharacters(annotation);
682 _p_writer->writeEndElement();
683
684 _p_writer->writeEndElement(); // annotation
685 }
686}
687
688void
689ContentXml::writeCell(const QString &value, const QString &annotation)
690{
691
694
695 if(_tableRowStarted == false)
696 {
697 writeLine();
698 }
699 /*
700 * <table:table-cell office:value-type="string">
701 */
702 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table-cell");
703 _p_writer->writeAttribute(
704 MetaXml::getNamespaceURI("office"), "value-type", "string");
705 // table:style-name="ce1"
706
707
708 if(_current_style_ref != nullptr)
709 {
710 _p_writer->writeAttribute(MetaXml::getNamespaceURI("table"),
711 "style-name",
713 }
714 else
715 {
716 _p_writer->writeAttribute(
717 MetaXml::getNamespaceURI("table"), "style-name", "ce1");
718 }
719 /*
720 * <text:p>45</text:p>
721 */
722 writeAnnotation(annotation);
723 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "p");
724 _p_writer->writeCharacters(value);
725 _p_writer->writeEndElement();
726
727 _p_writer->writeEndElement();
728 _col_pos++;
729}
730
731void
732ContentXml::writeCell(const QDateTime &cal, const QString &annotation)
733{
734
737
738
739 if(_tableRowStarted == false)
740 {
741 writeLine();
742 }
743 // cal..setTimezone(0);
744 /*
745 * <table:table-cell office:value-type="date"
746 * office:date-value="2011-07-16"
747 * ><text:p>16/07/11</text:p></table:table-cell>
748 */
749 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table-cell");
750 _p_writer->writeAttribute(
751 MetaXml::getNamespaceURI("office"), "value-type", "date");
752 _p_writer->writeAttribute(MetaXml::getNamespaceURI("office"),
753 "date-value",
754 cal.toString("yyyy-MM-dd'T'HH:mm:ss"));
755 // table:style-name="ce1"
756 if(_current_style_ref != nullptr)
757 {
758 _p_writer->writeAttribute(MetaXml::getNamespaceURI("table"),
759 "style-name",
761 }
762 else
763 {
764 _p_writer->writeAttribute(
765 MetaXml::getNamespaceURI("table"), "style-name", "ce2");
766 }
767 /*
768 * <text:p>45</text:p>
769 */
770 writeAnnotation(annotation);
771 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "p");
772 // writer.writeCharacters(cal.getDay()+"/"+cal.getMonth()+"/11");
773 _p_writer->writeCharacters(cal.toString("dd/MM/yyyy"));
774 _p_writer->writeEndElement();
775
776 /*
777 * </table:table-cell>
778 */
779 _p_writer->writeEndElement();
780 /*
781 * </table:table-row> </table:table> </office:spreadsheet>
782 * </office:body>
783 */
784 _col_pos++;
785}
786
787void
788ContentXml::writeCell(const QDate &date, const QString &annotation)
789{
790
791 writeCell(date.startOfDay(), annotation);
792}
793
794void
795ContentXml::writeCell(bool value, const QString &annotation)
796{
797
800
801 if(_tableRowStarted == false)
802 {
803 writeLine();
804 }
805 /*
806 * <table:table-cell office:value-type="date"
807 * office:date-value="2011-07-16"
808 * ><text:p>16/07/11</text:p></table:table-cell>
809 */
810 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table-cell");
811 _p_writer->writeAttribute(
812 MetaXml::getNamespaceURI("office"), "value-type", "boolean");
813 if(_current_style_ref != nullptr)
814 {
815 _p_writer->writeAttribute(MetaXml::getNamespaceURI("table"),
816 "style-name",
818 }
819 else
820 {
821 _p_writer->writeAttribute(
822 MetaXml::getNamespaceURI("table"), "style-name", "ce1");
823 }
824
825 QString bvalue = "false";
826 if(value)
827 {
828 bvalue = "true";
829 }
830 _p_writer->writeAttribute(
831 MetaXml::getNamespaceURI("office"), "boolean-value", bvalue);
832 writeAnnotation(annotation);
833 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "p");
834 _p_writer->writeCharacters(bvalue);
835 _p_writer->writeEndElement();
836
837 /*
838 * </table:table-cell>
839 */
840 _p_writer->writeEndElement();
841 _col_pos++;
842}
843
844// public void writeCell(Duration duration) throws XMLStreamException {
845// if (duration == null) {
846// this.writeCell("");
847// } else {
848// if (this.tableRowStarted == false) {
849// this.writeLine();
850// }
851// /*
852// * <table:table-cell office:value-type="date"
853// * office:date-value="2011-07-16"
854// * ><text:p>16/07/11</text:p></table:table-cell>
855// */
856// writer.writeStartElement("table", "table-cell",
857// hashNamespaceURI.get("table"));
858// writer.writeAttribute("office", hashNamespaceURI.get("office"),
859// "value-type", "time");
860// writer.writeAttribute("office", hashNamespaceURI.get("office"),
861// "time-value", duration.toString());
862// writer.writeAttribute("table", hashNamespaceURI.get("table"),
863// "style-name", "ce2");
864// /*
865// * <text:p>12:00:00</text:p>
866// */
867// writer.writeStartElement("text", "p", hashNamespaceURI.get("text"));
868// writer.writeCharacters(duration.getHours() + ":"
869// + duration.getMinutes() + ":" + duration.getSeconds());
870// writer.writeEndElement();
871//
872// /*
873// * </table:table-cell>
874// */
875// writer.writeEndElement();
876// /*
877// * </table:table-row> </table:table> </office:spreadsheet>
878// * </office:body>
879// */
880// }
881// }
882
883void
884ContentXml::writeCell(const QUrl &theUri,
885 const QString &description,
886 const QString &annotation)
887{
888 // <table:table-cell office:value-type="string"><text:p><text:a
889 // xlink:href="http://linuxfr.org/">linuxfr</text:a></text:p></table:table-cell>
890
891 //<table:table-cell office:value-type="string" calcext:value-type="string">
892 //<text:p>
893 //<text:a xlink:href="http://pappso.inra.fr/" xlink:type="simple">
894 // ceci est un lien</text:a></text:p>
895 //</table:table-cell>
896
897 //<table:table-cell table:style-name="ce1" office:value-type="string">
898 //<text:p>
899 //<text:a xlink:href="http://linuxfr.org/" xlink:type="simple">
900 // linux fr</text:a></text:p>
901 //</table:table-cell>
904
905 if(_tableRowStarted == false)
906 {
907 writeLine();
908 }
909 /*
910 * <table:table-cell office:value-type="string">
911 */
912 _p_writer->writeStartElement(MetaXml::getNamespaceURI("table"), "table-cell");
913
914 if(_current_style_ref != nullptr)
915 {
916 _p_writer->writeAttribute(MetaXml::getNamespaceURI("table"),
917 "style-name",
919 }
920 else
921 {
922 _p_writer->writeAttribute(
923 MetaXml::getNamespaceURI("table"), "style-name", "ce1");
924 }
925
926 //_p_writer->writeAttribute(MetaXml::getNamespaceURI("office"),"value-type",
927 //"string");
928 _p_writer->writeAttribute(
929 MetaXml::getNamespaceURI("calcext"), "value-type", "string");
930
931 writeAnnotation(annotation);
932
933 _p_writer->setAutoFormatting(false);
934 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "p");
935 _p_writer->writeStartElement(MetaXml::getNamespaceURI("text"), "a");
936 // xlink:href="http://linuxfr.org/"
937 _p_writer->writeAttribute(
938 MetaXml::getNamespaceURI("xlink"), "href", theUri.toString());
939 _p_writer->writeAttribute(
940 MetaXml::getNamespaceURI("xlink"), "type", "simple");
941 _p_writer->writeCharacters(description);
942 _p_writer->writeEndElement();
943 _p_writer->writeEndElement();
944
945 _p_writer->setAutoFormatting(true);
946
947 _p_writer->writeEndElement();
948
949 _col_pos++;
950}
951
954{
956 {
957 throw OdsException(
958 QObject::tr("unable to get style reference : styles already written"));
959 }
960
961 _style2write.push_back(style);
962
963 OdsTableCellStyleRef _p_ref =
965 _style_ref_list.push_back(_p_ref);
966 return _p_ref;
967}
968
969
970void
972{
973 if(style_ref != nullptr)
974 {
975 auto it = find(_style_ref_list.begin(), _style_ref_list.end(), style_ref);
976 if(it == _style_ref_list.end())
977 {
978 throw OdsException(QObject::tr(
979 "this style reference was not registered in this document"));
980 }
981 }
982
983 _current_style_ref = style_ref;
984}
985
986
987void
989{
990 _color_scale_list.push_back(ods_color_scale);
991}
992
993
994QString
996{
997 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
998 << _current_sheet_name << " " << _col_pos << " " << _row_pos;
999
1000 int size_col = _col_pos - 1; // supports more than 26 columns
1001 QString ods_column_coord;
1002 while(size_col >= 0)
1003 {
1004 ods_column_coord.prepend((char)(((size_col) % 26) + 65));
1005 size_col = (size_col / 26);
1006 if(size_col == 0)
1007 break;
1008 size_col--;
1009 }
1010
1011 return QString("%1.%2%3")
1013 .arg(ods_column_coord)
1014 .arg(_row_pos);
1015}
void writeLine()
static QString _xsdNamespaceURI
Definition contentxml.h:75
SettingsXml * _p_settings_xml
Definition contentxml.h:97
void WriteHeader()
QXmlStreamWriter * _p_writer
Definition contentxml.h:80
std::vector< OdsColorScale > getOdsColorScaleListBySheetName(const QString &sheet_name)
void writeCell(double value, const QString &annotation)
void writeCellPercentage(double value, const QString &annotation)
OdsTableCellStyleRef getTableCellStyleRef(const OdsTableCellStyle &style)
void writeEmptyCell(const QString &annotation)
OdsTableCellStyleRefInternal * _current_style_ref
Definition contentxml.h:89
void startSpreadsheet()
bool _automatic_styles_writed
Definition contentxml.h:85
void writeAutomaticStyles()
unsigned int _row_pos
Definition contentxml.h:95
virtual ~ContentXml()
std::vector< OdsTableCellStyle > _style2write
Definition contentxml.h:87
bool _tableStarted
Definition contentxml.h:82
ContentXml(QuaZip *p_quaZip, SettingsXml *p_settings_xml)
std::vector< OdsColorScale > _color_scale_list
Definition contentxml.h:91
std::vector< OdsTableCellStyleRef > _style_ref_list
Definition contentxml.h:88
void writeAnnotation(const QString &annotation)
void addColorScale(const OdsColorScale &ods_color_scale)
void writeCellFloat(const QString &value, const QString &representation, const QString &annotation)
static QString _xsiNamespaceURI
Definition contentxml.h:76
bool _spreadsheet_started
Definition contentxml.h:86
unsigned int _col_pos
Definition contentxml.h:96
void setTableCellStyleRef(OdsTableCellStyleRef style_ref)
bool _tableRowStarted
Definition contentxml.h:84
QString getCellCoordinate()
void writeEndTable()
QuaZipFile _outFile
Definition contentxml.h:73
void writeFontFaceDecls()
QString _current_sheet_name
Definition contentxml.h:92
void writeSheet()
static std::map< const QString, const QString > _hash_namespace_uri
Definition metaxml.h:34
static const QString & getNamespaceURI(const QString &xml_namespace)
Definition metaxml.cpp:32
const QString getDefaultSheetName() const
void addSheetName(const QString &name)