comparison src/xlsx/xlsxcell.cpp @ 1:93d3106bb9a4

Add qt xlsx library
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 22 Mar 2016 10:38:08 +0100
parents
children
comparison
equal deleted inserted replaced
0:49cd5cc0b072 1:93d3106bb9a4
1 /****************************************************************************
2 ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
3 ** All right reserved.
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining
6 ** a copy of this software and associated documentation files (the
7 ** "Software"), to deal in the Software without restriction, including
8 ** without limitation the rights to use, copy, modify, merge, publish,
9 ** distribute, sublicense, and/or sell copies of the Software, and to
10 ** permit persons to whom the Software is furnished to do so, subject to
11 ** the following conditions:
12 **
13 ** The above copyright notice and this permission notice shall be
14 ** included in all copies or substantial portions of the Software.
15 **
16 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 **
24 ****************************************************************************/
25 #include "xlsxcell.h"
26 #include "xlsxcell_p.h"
27 #include "xlsxformat.h"
28 #include "xlsxformat_p.h"
29 #include "xlsxutility_p.h"
30 #include "xlsxworksheet.h"
31 #include "xlsxworkbook.h"
32 #include <QDateTime>
33
34 QT_BEGIN_NAMESPACE_XLSX
35
36 CellPrivate::CellPrivate(Cell *p) :
37 q_ptr(p)
38 {
39
40 }
41
42 CellPrivate::CellPrivate(const CellPrivate * const cp)
43 : value(cp->value), formula(cp->formula), cellType(cp->cellType)
44 , format(cp->format), richString(cp->richString), parent(cp->parent)
45 {
46
47 }
48
49 /*!
50 \class Cell
51 \inmodule QtXlsx
52 \brief The Cell class provides a API that is used to handle the worksheet cell.
53
54 */
55
56 /*!
57 \enum Cell::CellType
58 \value BooleanType Boolean type
59 \value NumberType Number type, can be blank or used with forumula
60 \value ErrorType Error type
61 \value SharedStringType Shared string type
62 \value StringType String type, can be used with forumula
63 \value InlineStringType Inline string type
64 */
65
66 /*!
67 * \internal
68 * Created by Worksheet only.
69 */
70 Cell::Cell(const QVariant &data, CellType type, const Format &format, Worksheet *parent) :
71 d_ptr(new CellPrivate(this))
72 {
73 d_ptr->value = data;
74 d_ptr->cellType = type;
75 d_ptr->format = format;
76 d_ptr->parent = parent;
77 }
78
79 /*!
80 * \internal
81 */
82 Cell::Cell(const Cell * const cell):
83 d_ptr(new CellPrivate(cell->d_ptr))
84 {
85 d_ptr->q_ptr = this;
86 }
87
88 /*!
89 * Destroys the Cell and cleans up.
90 */
91 Cell::~Cell()
92 {
93 delete d_ptr;
94 }
95
96 /*!
97 * Return the dataType of this Cell
98 */
99 Cell::CellType Cell::cellType() const
100 {
101 Q_D(const Cell);
102 return d->cellType;
103 }
104
105 /*!
106 * Return the data content of this Cell
107 */
108 QVariant Cell::value() const
109 {
110 Q_D(const Cell);
111 return d->value;
112 }
113
114 /*!
115 * Return the style used by this Cell. If no style used, 0 will be returned.
116 */
117 Format Cell::format() const
118 {
119 Q_D(const Cell);
120 return d->format;
121 }
122
123 /*!
124 * Returns true if the cell has one formula.
125 */
126 bool Cell::hasFormula() const
127 {
128 Q_D(const Cell);
129 return d->formula.isValid();
130 }
131
132 /*!
133 * Return the formula contents if the dataType is Formula
134 */
135 CellFormula Cell::formula() const
136 {
137 Q_D(const Cell);
138 return d->formula;
139 }
140
141 /*!
142 * Returns whether the value is probably a dateTime or not
143 */
144 bool Cell::isDateTime() const
145 {
146 Q_D(const Cell);
147 if (d->cellType == NumberType && d->value.toDouble() >=0
148 && d->format.isValid() && d->format.isDateTimeFormat()) {
149 return true;
150 }
151 return false;
152 }
153
154 /*!
155 * Return the data time value.
156 */
157 QDateTime Cell::dateTime() const
158 {
159 Q_D(const Cell);
160 if (!isDateTime())
161 return QDateTime();
162 return datetimeFromNumber(d->value.toDouble(), d->parent->workbook()->isDate1904());
163 }
164
165 /*!
166 * Returns whether the cell is probably a rich string or not
167 */
168 bool Cell::isRichString() const
169 {
170 Q_D(const Cell);
171 if (d->cellType != SharedStringType && d->cellType != InlineStringType
172 && d->cellType != StringType)
173 return false;
174
175 return d->richString.isRichString();
176 }
177
178 QT_END_NAMESPACE_XLSX
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)