/src/libreoffice/sc/source/ui/dataprovider/datatransformation.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include <datatransformation.hxx> |
11 | | #include <limits> |
12 | | #include <document.hxx> |
13 | | #include <rtl/math.hxx> |
14 | | #include <cmath> |
15 | | #include <svl/numformat.hxx> |
16 | | #include <svl/zforlist.hxx> |
17 | | #include <unotools/charclass.hxx> |
18 | | #include <utility> |
19 | | |
20 | | namespace { |
21 | | |
22 | | Date getDate(double nDateTime, const SvNumberFormatter* pFormatter) |
23 | 0 | { |
24 | 0 | Date aDate = pFormatter->GetNullDate(); |
25 | 0 | aDate.AddDays(static_cast<sal_Int32>(::rtl::math::approxFloor(nDateTime))); |
26 | 0 | return aDate; |
27 | 0 | } |
28 | | } |
29 | | |
30 | | namespace sc { |
31 | | DataTransformation::~DataTransformation() |
32 | 0 | { |
33 | 0 | } |
34 | | |
35 | | SCROW DataTransformation::getLastRow(const ScDocument& rDoc, SCCOL nCol) |
36 | 0 | { |
37 | 0 | SCROW nEndRow = rDoc.MaxRow(); |
38 | |
|
39 | 0 | return rDoc.GetLastDataRow(0, nCol, nCol, nEndRow); |
40 | 0 | } |
41 | | |
42 | | ColumnRemoveTransformation::ColumnRemoveTransformation(std::set<SCCOL>&& rColumns): |
43 | 0 | maColumns(std::move(rColumns)) |
44 | 0 | { |
45 | 0 | } |
46 | | |
47 | | ColumnRemoveTransformation::~ColumnRemoveTransformation() |
48 | 0 | { |
49 | 0 | } |
50 | | |
51 | | void ColumnRemoveTransformation::Transform(ScDocument& rDoc) const |
52 | 0 | { |
53 | 0 | sal_Int32 nIncrementIndex = 0; |
54 | 0 | for (auto& rCol : maColumns) |
55 | 0 | { |
56 | 0 | rDoc.DeleteCol(0, 0, rDoc.MaxRow(), 0, rCol - nIncrementIndex, 1); |
57 | 0 | nIncrementIndex++; |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | | TransformationType ColumnRemoveTransformation::getTransformationType() const |
62 | 0 | { |
63 | 0 | return TransformationType::DELETE_TRANSFORMATION; |
64 | 0 | } |
65 | | |
66 | | const std::set<SCCOL> & ColumnRemoveTransformation::getColumns() const |
67 | 0 | { |
68 | 0 | return maColumns; |
69 | 0 | } |
70 | | |
71 | | SplitColumnTransformation::SplitColumnTransformation(SCCOL nCol, sal_Unicode cSeparator): |
72 | 0 | mnCol(nCol), |
73 | 0 | mcSeparator(cSeparator) |
74 | 0 | { |
75 | 0 | } |
76 | | |
77 | | void SplitColumnTransformation::Transform(ScDocument& rDoc) const |
78 | 0 | { |
79 | 0 | if (mnCol == -1) |
80 | 0 | return; |
81 | | |
82 | 0 | rDoc.InsertCol(0, 0, rDoc.MaxRow(), 0, mnCol + 1, 1); |
83 | |
|
84 | 0 | SCROW nEndRow = getLastRow(rDoc, mnCol); |
85 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
86 | 0 | { |
87 | 0 | CellType eType = rDoc.GetCellType(mnCol, nRow, 0); |
88 | 0 | if (eType == CELLTYPE_STRING) |
89 | 0 | { |
90 | 0 | OUString aStr = rDoc.GetString(mnCol, nRow, 0); |
91 | 0 | sal_Int32 nIndex = aStr.indexOf(mcSeparator); |
92 | 0 | if (nIndex != -1) |
93 | 0 | { |
94 | 0 | rDoc.SetString(mnCol + 1, nRow, 0, aStr.copy(nIndex + 1)); |
95 | 0 | rDoc.SetString(mnCol, nRow, 0, aStr.copy(0, nIndex)); |
96 | 0 | } |
97 | 0 | } |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | | TransformationType SplitColumnTransformation::getTransformationType() const |
102 | 0 | { |
103 | 0 | return TransformationType::SPLIT_TRANSFORMATION; |
104 | 0 | } |
105 | | |
106 | | SCCOL SplitColumnTransformation::getColumn() const |
107 | 0 | { |
108 | 0 | return mnCol; |
109 | 0 | } |
110 | | |
111 | | sal_Unicode SplitColumnTransformation::getSeparator() const |
112 | 0 | { |
113 | 0 | return mcSeparator; |
114 | 0 | } |
115 | | |
116 | | MergeColumnTransformation::MergeColumnTransformation( std::set<SCCOL>&& rColumns, OUString aMergeString): |
117 | 0 | maColumns(std::move(rColumns)), |
118 | 0 | maMergeString(std::move(aMergeString)) |
119 | 0 | { |
120 | 0 | } |
121 | | |
122 | | void MergeColumnTransformation::Transform(ScDocument& rDoc) const |
123 | 0 | { |
124 | 0 | if (maColumns.empty()) |
125 | 0 | return; |
126 | | |
127 | 0 | SCROW nMaxRow = 0; |
128 | 0 | for (auto& itr : maColumns) |
129 | 0 | { |
130 | 0 | nMaxRow = getLastRow(rDoc, itr); |
131 | 0 | } |
132 | 0 | assert(nMaxRow != -1); |
133 | |
|
134 | 0 | SCCOL nTargetCol = *maColumns.begin(); |
135 | | |
136 | |
|
137 | 0 | for (SCROW nRow = 0; nRow <= nMaxRow; ++nRow) |
138 | 0 | { |
139 | 0 | OUStringBuffer aStr(rDoc.GetString(nTargetCol, nRow, 0)); |
140 | 0 | for (auto& itr : maColumns) |
141 | 0 | { |
142 | 0 | if (itr != nTargetCol) |
143 | 0 | { |
144 | 0 | aStr.append(maMergeString + rDoc.GetString(itr, nRow, 0)); |
145 | 0 | } |
146 | 0 | } |
147 | 0 | rDoc.SetString(nTargetCol, nRow, 0, aStr.makeStringAndClear()); |
148 | 0 | } |
149 | |
|
150 | 0 | for (auto& itr : maColumns) |
151 | 0 | { |
152 | 0 | if (itr == nTargetCol) |
153 | 0 | continue; |
154 | | |
155 | 0 | rDoc.DeleteCol(0, 0, rDoc.MaxRow(), 0, itr, 1); |
156 | 0 | } |
157 | 0 | } |
158 | | |
159 | | TransformationType MergeColumnTransformation::getTransformationType() const |
160 | 0 | { |
161 | 0 | return TransformationType::MERGE_TRANSFORMATION; |
162 | 0 | } |
163 | | |
164 | | const OUString & MergeColumnTransformation::getMergeString() const |
165 | 0 | { |
166 | 0 | return maMergeString; |
167 | 0 | } |
168 | | |
169 | | const std::set<SCCOL> & MergeColumnTransformation::getColumns() const |
170 | 0 | { |
171 | 0 | return maColumns; |
172 | 0 | } |
173 | | |
174 | | SortTransformation::SortTransformation(const ScSortParam& rSortParam): |
175 | 0 | maSortParam(rSortParam) |
176 | 0 | { |
177 | 0 | } |
178 | | |
179 | | void SortTransformation::Transform(ScDocument& rDoc) const |
180 | 0 | { |
181 | 0 | rDoc.Sort(0, maSortParam, false, false, nullptr, nullptr); |
182 | 0 | } |
183 | | |
184 | | TransformationType SortTransformation::getTransformationType() const |
185 | 0 | { |
186 | 0 | return TransformationType::SORT_TRANSFORMATION; |
187 | 0 | } |
188 | | |
189 | | const ScSortParam & SortTransformation::getSortParam() const |
190 | 0 | { |
191 | 0 | return maSortParam; |
192 | 0 | } |
193 | | |
194 | | TextTransformation::TextTransformation( std::set<SCCOL>&& nCol, const TEXT_TRANSFORM_TYPE rType): |
195 | 0 | mnCol(std::move(nCol)), |
196 | 0 | maType(rType) |
197 | 0 | { |
198 | 0 | } |
199 | | |
200 | | void TextTransformation::Transform(ScDocument& rDoc) const |
201 | 0 | { |
202 | 0 | SCROW nEndRow = 0; |
203 | 0 | for(auto& rCol : mnCol) |
204 | 0 | { |
205 | 0 | nEndRow = getLastRow(rDoc, rCol); |
206 | 0 | } |
207 | 0 | assert(nEndRow != -1); |
208 | |
|
209 | 0 | for(auto& rCol : mnCol) |
210 | 0 | { |
211 | 0 | switch (maType) |
212 | 0 | { |
213 | 0 | case TEXT_TRANSFORM_TYPE::TO_LOWER: |
214 | 0 | { |
215 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
216 | 0 | { |
217 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
218 | 0 | if (eType == CELLTYPE_STRING) |
219 | 0 | { |
220 | 0 | OUString aStr = rDoc.GetString(rCol, nRow, 0); |
221 | 0 | rDoc.SetString(rCol, nRow, 0, ScGlobal::getCharClass().lowercase(aStr)); |
222 | 0 | } |
223 | 0 | } |
224 | 0 | } |
225 | 0 | break; |
226 | 0 | case TEXT_TRANSFORM_TYPE::TO_UPPER: |
227 | 0 | { |
228 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
229 | 0 | { |
230 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
231 | 0 | if (eType == CELLTYPE_STRING) |
232 | 0 | { |
233 | 0 | OUString aStr = rDoc.GetString(rCol, nRow, 0); |
234 | 0 | rDoc.SetString(rCol, nRow, 0, ScGlobal::getCharClass().uppercase(aStr)); |
235 | 0 | } |
236 | 0 | } |
237 | 0 | } |
238 | 0 | break; |
239 | 0 | case TEXT_TRANSFORM_TYPE::CAPITALIZE: |
240 | 0 | { |
241 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
242 | 0 | { |
243 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
244 | 0 | if (eType == CELLTYPE_STRING) |
245 | 0 | { |
246 | 0 | OUString aStr = rDoc.GetString(rCol, nRow, 0); |
247 | |
|
248 | 0 | sal_Int32 length = aStr.getLength(); |
249 | |
|
250 | 0 | if(length != 0) |
251 | 0 | aStr = aStr.replaceAt(0, 1, ScGlobal::getCharClass().uppercase(OUString(aStr[0]))); |
252 | |
|
253 | 0 | for (sal_Int32 i = 1; i < length; i++){ |
254 | 0 | if (aStr[i-1] == sal_Unicode(U' ')) |
255 | 0 | { |
256 | 0 | aStr = aStr.replaceAt(i, 1, ScGlobal::getCharClass().uppercase(OUString(aStr[i]))); |
257 | 0 | } |
258 | 0 | else |
259 | 0 | { |
260 | 0 | aStr = aStr.replaceAt(i, 1, ScGlobal::getCharClass().lowercase(OUString(aStr[i]))); |
261 | 0 | } |
262 | 0 | } |
263 | 0 | rDoc.SetString(rCol, nRow, 0, aStr); |
264 | 0 | } |
265 | 0 | } |
266 | 0 | } |
267 | 0 | break; |
268 | 0 | case TEXT_TRANSFORM_TYPE::TRIM: |
269 | 0 | { |
270 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
271 | 0 | { |
272 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
273 | 0 | if (eType == CELLTYPE_STRING) |
274 | 0 | { |
275 | 0 | OUString aStr = rDoc.GetString(rCol, nRow, 0); |
276 | 0 | rDoc.SetString(rCol, nRow, 0, aStr.trim()); |
277 | 0 | } |
278 | 0 | } |
279 | 0 | } |
280 | 0 | break; |
281 | 0 | default: |
282 | 0 | break; |
283 | 0 | } |
284 | 0 | } |
285 | 0 | } |
286 | | |
287 | | TransformationType TextTransformation::getTransformationType() const |
288 | 0 | { |
289 | 0 | return TransformationType::TEXT_TRANSFORMATION; |
290 | 0 | } |
291 | | |
292 | | TEXT_TRANSFORM_TYPE TextTransformation::getTextTransformationType() const |
293 | 0 | { |
294 | 0 | return maType; |
295 | 0 | } |
296 | | |
297 | | const std::set<SCCOL>& TextTransformation::getColumns() const |
298 | 0 | { |
299 | 0 | return mnCol; |
300 | 0 | } |
301 | | |
302 | | AggregateFunction::AggregateFunction(std::set<SCCOL>&& rColumns, const AGGREGATE_FUNCTION rType): |
303 | 0 | maColumns(std::move(rColumns)), |
304 | 0 | maType(rType) |
305 | 0 | { |
306 | 0 | } |
307 | | |
308 | | void AggregateFunction::Transform(ScDocument& rDoc) const |
309 | 0 | { |
310 | 0 | SCROW nEndRow = 0; |
311 | 0 | for (auto& itr : maColumns) |
312 | 0 | { |
313 | 0 | nEndRow = getLastRow(rDoc, itr); |
314 | 0 | } |
315 | 0 | assert(nEndRow != -1); |
316 | |
|
317 | 0 | for (auto& rCol : maColumns) |
318 | 0 | { |
319 | 0 | switch (maType) |
320 | 0 | { |
321 | 0 | case AGGREGATE_FUNCTION::SUM: |
322 | 0 | { |
323 | 0 | double nSum = 0; |
324 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
325 | 0 | { |
326 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
327 | 0 | if (eType == CELLTYPE_VALUE) |
328 | 0 | { |
329 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
330 | 0 | nSum += nVal; |
331 | 0 | } |
332 | 0 | } |
333 | 0 | rDoc.SetValue(rCol, nEndRow + 1, 0, nSum); |
334 | 0 | } |
335 | 0 | break; |
336 | 0 | case AGGREGATE_FUNCTION::AVERAGE: |
337 | 0 | { |
338 | 0 | double nSum = 0; |
339 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
340 | 0 | { |
341 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
342 | 0 | if (eType == CELLTYPE_VALUE) |
343 | 0 | { |
344 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
345 | 0 | nSum += nVal; |
346 | 0 | } |
347 | 0 | } |
348 | |
|
349 | 0 | double nAvg = nSum / (nEndRow + 1); |
350 | 0 | rDoc.SetValue(rCol, nEndRow + 1, 0, nAvg); |
351 | 0 | } |
352 | 0 | break; |
353 | 0 | case AGGREGATE_FUNCTION::MIN: |
354 | 0 | { |
355 | 0 | double nMin = std::numeric_limits<double>::max(); |
356 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
357 | 0 | { |
358 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
359 | 0 | if (eType == CELLTYPE_VALUE) |
360 | 0 | { |
361 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
362 | 0 | if(nVal < nMin) |
363 | 0 | nMin = nVal; |
364 | 0 | } |
365 | 0 | } |
366 | 0 | rDoc.SetValue(rCol, nEndRow + 1, 0, nMin); |
367 | 0 | } |
368 | 0 | break; |
369 | 0 | case AGGREGATE_FUNCTION::MAX: |
370 | 0 | { |
371 | 0 | double nMax = std::numeric_limits<double>::lowest(); |
372 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
373 | 0 | { |
374 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
375 | 0 | if (eType == CELLTYPE_VALUE) |
376 | 0 | { |
377 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
378 | 0 | if(nMax < nVal) |
379 | 0 | nMax = nVal; |
380 | 0 | } |
381 | 0 | } |
382 | 0 | rDoc.SetValue(rCol, nEndRow + 1, 0, nMax); |
383 | 0 | } |
384 | 0 | break; |
385 | 0 | default: |
386 | 0 | break; |
387 | 0 | } |
388 | 0 | } |
389 | 0 | } |
390 | | |
391 | | TransformationType AggregateFunction::getTransformationType() const |
392 | 0 | { |
393 | 0 | return TransformationType::AGGREGATE_FUNCTION; |
394 | 0 | } |
395 | | |
396 | | AGGREGATE_FUNCTION AggregateFunction::getAggregateType() const |
397 | 0 | { |
398 | 0 | return maType; |
399 | 0 | } |
400 | | |
401 | | const std::set<SCCOL>& AggregateFunction::getColumns() const |
402 | 0 | { |
403 | 0 | return maColumns; |
404 | 0 | } |
405 | | |
406 | | NumberTransformation::NumberTransformation(std::set<SCCOL>&& nCol, |
407 | | const NUMBER_TRANSFORM_TYPE rType) |
408 | 0 | : mnCol(std::move(nCol)) |
409 | 0 | , maType(rType) |
410 | 0 | , maPrecision(-1) |
411 | 0 | { |
412 | 0 | } |
413 | | |
414 | | NumberTransformation::NumberTransformation(std::set<SCCOL>&& nCol, |
415 | | const NUMBER_TRANSFORM_TYPE rType, int nPrecision) |
416 | 0 | : mnCol(std::move(nCol)) |
417 | 0 | , maType(rType) |
418 | 0 | , maPrecision(nPrecision) |
419 | 0 | { |
420 | 0 | } |
421 | | |
422 | | void NumberTransformation::Transform(ScDocument& rDoc) const |
423 | 0 | { |
424 | 0 | SCROW nEndRow = 0; |
425 | 0 | for(auto& rCol : mnCol) |
426 | 0 | { |
427 | 0 | nEndRow = getLastRow(rDoc, rCol); |
428 | 0 | } |
429 | 0 | assert(nEndRow != -1); |
430 | |
|
431 | 0 | for(auto& rCol : mnCol) |
432 | 0 | { |
433 | 0 | switch (maType) |
434 | 0 | { |
435 | 0 | case NUMBER_TRANSFORM_TYPE::ROUND: |
436 | 0 | { |
437 | 0 | if(maPrecision > -1) |
438 | 0 | { |
439 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
440 | 0 | { |
441 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
442 | 0 | if (eType == CELLTYPE_VALUE) |
443 | 0 | { |
444 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
445 | 0 | rDoc.SetValue(rCol, nRow, 0, rtl::math::round(nVal, maPrecision)); |
446 | 0 | } |
447 | 0 | } |
448 | 0 | } |
449 | 0 | } |
450 | 0 | break; |
451 | 0 | case NUMBER_TRANSFORM_TYPE::ROUND_UP: |
452 | 0 | { |
453 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
454 | 0 | { |
455 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
456 | 0 | if (eType == CELLTYPE_VALUE) |
457 | 0 | { |
458 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
459 | 0 | rDoc.SetValue(rCol, nRow, 0, rtl::math::approxCeil(nVal)); |
460 | 0 | } |
461 | 0 | } |
462 | 0 | } |
463 | 0 | break; |
464 | 0 | case NUMBER_TRANSFORM_TYPE::ROUND_DOWN: |
465 | 0 | { |
466 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
467 | 0 | { |
468 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
469 | 0 | if (eType == CELLTYPE_VALUE) |
470 | 0 | { |
471 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
472 | 0 | rDoc.SetValue(rCol, nRow, 0, rtl::math::approxFloor(nVal)); |
473 | 0 | } |
474 | 0 | } |
475 | 0 | } |
476 | 0 | break; |
477 | 0 | case NUMBER_TRANSFORM_TYPE::ABSOLUTE: |
478 | 0 | { |
479 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
480 | 0 | { |
481 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
482 | 0 | if (eType == CELLTYPE_VALUE) |
483 | 0 | { |
484 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
485 | 0 | if(std::signbit(nVal)) |
486 | 0 | rDoc.SetValue(rCol, nRow, 0, -1 * nVal); |
487 | 0 | } |
488 | 0 | } |
489 | 0 | } |
490 | 0 | break; |
491 | 0 | case NUMBER_TRANSFORM_TYPE::LOG_E: |
492 | 0 | { |
493 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
494 | 0 | { |
495 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
496 | 0 | if (eType == CELLTYPE_VALUE) |
497 | 0 | { |
498 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
499 | 0 | if (nVal > 0) |
500 | 0 | { |
501 | 0 | rDoc.SetValue(rCol, nRow, 0, std::log1p(nVal-1)); |
502 | 0 | } |
503 | 0 | else |
504 | 0 | { |
505 | 0 | rDoc.SetString(rCol, nRow, 0, OUString()); |
506 | 0 | } |
507 | 0 | } |
508 | 0 | } |
509 | 0 | } |
510 | 0 | break; |
511 | 0 | case NUMBER_TRANSFORM_TYPE::LOG_10: |
512 | 0 | { |
513 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
514 | 0 | { |
515 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
516 | 0 | if (eType == CELLTYPE_VALUE) |
517 | 0 | { |
518 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
519 | 0 | if (nVal > 0) |
520 | 0 | { |
521 | 0 | rDoc.SetValue(rCol, nRow, 0, log10(nVal)); |
522 | 0 | } |
523 | 0 | else |
524 | 0 | { |
525 | 0 | rDoc.SetString(rCol, nRow, 0, OUString()); |
526 | 0 | } |
527 | 0 | } |
528 | 0 | } |
529 | 0 | } |
530 | 0 | break; |
531 | 0 | case NUMBER_TRANSFORM_TYPE::CUBE: |
532 | 0 | { |
533 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
534 | 0 | { |
535 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
536 | 0 | if (eType == CELLTYPE_VALUE) |
537 | 0 | { |
538 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
539 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal * nVal * nVal); |
540 | 0 | } |
541 | 0 | } |
542 | 0 | } |
543 | 0 | break; |
544 | 0 | case NUMBER_TRANSFORM_TYPE::SQUARE: |
545 | 0 | { |
546 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
547 | 0 | { |
548 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
549 | 0 | if (eType == CELLTYPE_VALUE) |
550 | 0 | { |
551 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
552 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal * nVal); |
553 | 0 | } |
554 | 0 | } |
555 | 0 | } |
556 | 0 | break; |
557 | 0 | case NUMBER_TRANSFORM_TYPE::SQUARE_ROOT: |
558 | 0 | { |
559 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
560 | 0 | { |
561 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
562 | 0 | if (eType == CELLTYPE_VALUE) |
563 | 0 | { |
564 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
565 | 0 | if (!std::signbit(nVal)) |
566 | 0 | { |
567 | 0 | rDoc.SetValue(rCol, nRow, 0, sqrt(nVal)); |
568 | 0 | } |
569 | 0 | else |
570 | 0 | { |
571 | 0 | rDoc.SetString(rCol, nRow, 0, OUString()); |
572 | 0 | } |
573 | 0 | } |
574 | 0 | } |
575 | 0 | } |
576 | 0 | break; |
577 | 0 | case NUMBER_TRANSFORM_TYPE::IS_EVEN: |
578 | 0 | { |
579 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
580 | 0 | { |
581 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
582 | 0 | if (eType == CELLTYPE_VALUE) |
583 | 0 | { |
584 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
585 | 0 | if (fmod(nVal, 1) == 0 && fmod(nVal, 2) == 0) |
586 | 0 | rDoc.SetValue(rCol, nRow, 0, 1); |
587 | 0 | else |
588 | 0 | rDoc.SetValue(rCol, nRow, 0, 0); |
589 | 0 | } |
590 | 0 | } |
591 | 0 | } |
592 | 0 | break; |
593 | 0 | case NUMBER_TRANSFORM_TYPE::IS_ODD: |
594 | 0 | { |
595 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
596 | 0 | { |
597 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
598 | 0 | if (eType == CELLTYPE_VALUE) |
599 | 0 | { |
600 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
601 | 0 | if (fmod(nVal, 1) == 0 && fmod(nVal, 2) != 0) |
602 | 0 | rDoc.SetValue(rCol, nRow, 0, 1); |
603 | 0 | else |
604 | 0 | rDoc.SetValue(rCol, nRow, 0, 0); |
605 | 0 | } |
606 | 0 | } |
607 | 0 | } |
608 | 0 | break; |
609 | 0 | case NUMBER_TRANSFORM_TYPE::SIGN: |
610 | 0 | { |
611 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
612 | 0 | { |
613 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
614 | 0 | if (eType == CELLTYPE_VALUE) |
615 | 0 | { |
616 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
617 | 0 | if (nVal > 0) |
618 | 0 | rDoc.SetValue(rCol, nRow, 0, 1); |
619 | 0 | else if (nVal < 0) |
620 | 0 | rDoc.SetValue(rCol, nRow, 0, -1); |
621 | 0 | else |
622 | 0 | rDoc.SetValue(rCol, nRow, 0, 0); |
623 | 0 | } |
624 | 0 | } |
625 | 0 | } |
626 | 0 | break; |
627 | 0 | default: |
628 | 0 | break; |
629 | 0 | } |
630 | 0 | } |
631 | 0 | } |
632 | | |
633 | | TransformationType NumberTransformation::getTransformationType() const |
634 | 0 | { |
635 | 0 | return TransformationType::NUMBER_TRANSFORMATION; |
636 | 0 | } |
637 | | |
638 | | NUMBER_TRANSFORM_TYPE NumberTransformation::getNumberTransformationType() const |
639 | 0 | { |
640 | 0 | return maType; |
641 | 0 | } |
642 | | |
643 | | int NumberTransformation::getPrecision() const |
644 | 0 | { |
645 | 0 | return maPrecision; |
646 | 0 | } |
647 | | |
648 | | const std::set<SCCOL>& NumberTransformation::getColumn() const |
649 | 0 | { |
650 | 0 | return mnCol; |
651 | 0 | } |
652 | | |
653 | | ReplaceNullTransformation::ReplaceNullTransformation(std::set<SCCOL>&& nCol, |
654 | | OUString sReplaceWith) |
655 | 0 | : mnCol(std::move(nCol)) |
656 | 0 | , msReplaceWith(std::move(sReplaceWith)) |
657 | 0 | { |
658 | 0 | } |
659 | | |
660 | | void ReplaceNullTransformation::Transform(ScDocument& rDoc) const |
661 | 0 | { |
662 | 0 | if (mnCol.empty()) |
663 | 0 | return; |
664 | | |
665 | 0 | for(auto& rCol : mnCol) |
666 | 0 | { |
667 | 0 | SCROW nEndRow = getLastRow(rDoc, rCol); |
668 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
669 | 0 | { |
670 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
671 | 0 | if (eType == CELLTYPE_NONE) |
672 | 0 | { |
673 | | // OUString aStr = rDoc.GetString(rCol, nRow, 0); |
674 | | // if (aStr == "" || aStr.isEmpty()) |
675 | 0 | rDoc.SetString(rCol, nRow, 0, msReplaceWith); |
676 | 0 | } |
677 | 0 | } |
678 | 0 | } |
679 | |
|
680 | 0 | } |
681 | | |
682 | | const std::set<SCCOL>& ReplaceNullTransformation::getColumn() const |
683 | 0 | { |
684 | 0 | return mnCol; |
685 | 0 | } |
686 | | |
687 | | const OUString& ReplaceNullTransformation::getReplaceString() const |
688 | 0 | { |
689 | 0 | return msReplaceWith; |
690 | 0 | } |
691 | | |
692 | | TransformationType ReplaceNullTransformation::getTransformationType() const |
693 | 0 | { |
694 | 0 | return TransformationType::REMOVE_NULL_TRANSFORMATION; |
695 | 0 | } |
696 | | |
697 | | DateTimeTransformation::DateTimeTransformation(std::set<SCCOL>&& nCol, |
698 | | const DATETIME_TRANSFORMATION_TYPE rType) |
699 | 0 | : mnCol(std::move(nCol)) |
700 | 0 | , maType(rType) |
701 | 0 | { |
702 | 0 | } |
703 | | |
704 | | void DateTimeTransformation::Transform(ScDocument& rDoc) const |
705 | 0 | { |
706 | 0 | SCROW nEndRow = 0; |
707 | 0 | for(auto& rCol : mnCol) |
708 | 0 | { |
709 | 0 | nEndRow = getLastRow(rDoc, rCol); |
710 | 0 | } |
711 | 0 | assert(nEndRow != -1); |
712 | |
|
713 | 0 | for(auto& rCol : mnCol) |
714 | 0 | { |
715 | 0 | switch (maType) |
716 | 0 | { |
717 | 0 | case DATETIME_TRANSFORMATION_TYPE::DATE_STRING: |
718 | 0 | { |
719 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
720 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
721 | 0 | sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage ); |
722 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
723 | 0 | { |
724 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
725 | 0 | if (eType == CELLTYPE_VALUE) |
726 | 0 | { |
727 | 0 | ScAddress aAddress(rCol, nRow, 0); |
728 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
729 | 0 | } |
730 | 0 | } |
731 | 0 | } |
732 | 0 | break; |
733 | 0 | case DATETIME_TRANSFORMATION_TYPE::YEAR: |
734 | 0 | { |
735 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
736 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
737 | 0 | { |
738 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
739 | 0 | if (eType == CELLTYPE_VALUE) |
740 | 0 | { |
741 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
742 | 0 | Date aDate = getDate(nVal, pFormatter); |
743 | 0 | rDoc.SetValue(rCol, nRow, 0, aDate.GetYear()); |
744 | 0 | } |
745 | 0 | } |
746 | 0 | } |
747 | 0 | break; |
748 | 0 | case DATETIME_TRANSFORMATION_TYPE::START_OF_YEAR: |
749 | 0 | { |
750 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
751 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
752 | 0 | sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage ); |
753 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
754 | 0 | { |
755 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
756 | 0 | if (eType == CELLTYPE_VALUE) |
757 | 0 | { |
758 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
759 | 0 | Date aDate = getDate(nVal, pFormatter); |
760 | 0 | aDate.SetDay(1); |
761 | 0 | aDate.SetMonth(1); |
762 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
763 | 0 | ScAddress aAddress(rCol, nRow, 0); |
764 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
765 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
766 | 0 | } |
767 | 0 | } |
768 | 0 | } |
769 | 0 | break; |
770 | 0 | case DATETIME_TRANSFORMATION_TYPE::END_OF_YEAR: |
771 | 0 | { |
772 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
773 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
774 | 0 | sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage ); |
775 | |
|
776 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
777 | 0 | { |
778 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
779 | 0 | if (eType == CELLTYPE_VALUE) |
780 | 0 | { |
781 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
782 | 0 | Date aDate = getDate(nVal, pFormatter); |
783 | 0 | aDate.SetMonth(12); |
784 | 0 | aDate.SetDay(31); |
785 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
786 | 0 | ScAddress aAddress(rCol, nRow, 0); |
787 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
788 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
789 | 0 | } |
790 | 0 | } |
791 | 0 | } |
792 | 0 | break; |
793 | 0 | case DATETIME_TRANSFORMATION_TYPE::MONTH: |
794 | 0 | { |
795 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
796 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
797 | 0 | { |
798 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
799 | 0 | if (eType == CELLTYPE_VALUE) |
800 | 0 | { |
801 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
802 | 0 | Date aDate = getDate(nVal, pFormatter); |
803 | 0 | rDoc.SetValue(rCol, nRow, 0, aDate.GetMonth()); |
804 | 0 | } |
805 | 0 | } |
806 | 0 | } |
807 | 0 | break; |
808 | 0 | case DATETIME_TRANSFORMATION_TYPE::MONTH_NAME: |
809 | 0 | { |
810 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
811 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
812 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
813 | 0 | { |
814 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
815 | 0 | if (eType == CELLTYPE_VALUE) |
816 | 0 | { |
817 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
818 | 0 | const Color* pColor = nullptr; |
819 | 0 | OUString aResult; |
820 | 0 | pFormatter->GetPreviewStringGuess(u"MMMM"_ustr, nVal, aResult, &pColor, eLanguage); |
821 | 0 | rDoc.SetString(rCol, nRow, 0, aResult); |
822 | 0 | } |
823 | 0 | } |
824 | 0 | } |
825 | 0 | break; |
826 | 0 | case DATETIME_TRANSFORMATION_TYPE::START_OF_MONTH: |
827 | 0 | { |
828 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
829 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
830 | 0 | sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage ); |
831 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
832 | 0 | { |
833 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
834 | 0 | if (eType == CELLTYPE_VALUE) |
835 | 0 | { |
836 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
837 | 0 | ScAddress aAddress(rCol, nRow, 0); |
838 | 0 | Date aDate = getDate(nVal, pFormatter); |
839 | 0 | aDate.SetDay(1); |
840 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
841 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
842 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
843 | 0 | } |
844 | 0 | } |
845 | 0 | } |
846 | 0 | break; |
847 | 0 | case DATETIME_TRANSFORMATION_TYPE::END_OF_MONTH: |
848 | 0 | { |
849 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
850 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
851 | 0 | sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage ); |
852 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
853 | 0 | { |
854 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
855 | 0 | if (eType == CELLTYPE_VALUE) |
856 | 0 | { |
857 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
858 | 0 | ScAddress aAddress(rCol, nRow, 0); |
859 | 0 | Date aDate = getDate(nVal, pFormatter); |
860 | 0 | aDate.SetDay(aDate.GetDaysInMonth()); |
861 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
862 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
863 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
864 | 0 | } |
865 | 0 | } |
866 | 0 | } |
867 | 0 | break; |
868 | 0 | case DATETIME_TRANSFORMATION_TYPE::DAY: |
869 | 0 | { |
870 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
871 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
872 | 0 | { |
873 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
874 | 0 | if (eType == CELLTYPE_VALUE) |
875 | 0 | { |
876 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
877 | 0 | Date aDate = getDate(nVal, pFormatter); |
878 | 0 | rDoc.SetValue(rCol, nRow, 0, aDate.GetDay()); |
879 | 0 | } |
880 | 0 | } |
881 | 0 | } |
882 | 0 | break; |
883 | 0 | case DATETIME_TRANSFORMATION_TYPE::DAY_OF_WEEK: |
884 | 0 | { |
885 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
886 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
887 | 0 | { |
888 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
889 | 0 | if (eType == CELLTYPE_VALUE) |
890 | 0 | { |
891 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
892 | 0 | Date aDate = getDate(nVal, pFormatter); |
893 | 0 | rDoc.SetValue(rCol, nRow, 0, aDate.GetDayOfWeek()); |
894 | 0 | } |
895 | 0 | } |
896 | 0 | } |
897 | 0 | break; |
898 | 0 | case DATETIME_TRANSFORMATION_TYPE::DAY_OF_YEAR: |
899 | 0 | { |
900 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
901 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
902 | 0 | { |
903 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
904 | 0 | if (eType == CELLTYPE_VALUE) |
905 | 0 | { |
906 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
907 | 0 | Date aDate = getDate(nVal, pFormatter); |
908 | 0 | rDoc.SetValue(rCol, nRow, 0, aDate.GetDayOfYear()); |
909 | 0 | } |
910 | 0 | } |
911 | 0 | } |
912 | 0 | break; |
913 | 0 | case DATETIME_TRANSFORMATION_TYPE::QUARTER: |
914 | 0 | { |
915 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
916 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
917 | 0 | { |
918 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
919 | 0 | if (eType == CELLTYPE_VALUE) |
920 | 0 | { |
921 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
922 | 0 | Date aDate = getDate(nVal, pFormatter); |
923 | |
|
924 | 0 | int nMonth = aDate.GetMonth(); |
925 | |
|
926 | 0 | if(nMonth >= 1 && nMonth <=3) |
927 | 0 | rDoc.SetValue(rCol, nRow, 0, 1); |
928 | | |
929 | 0 | else if(nMonth >= 4 && nMonth <=6) |
930 | 0 | rDoc.SetValue(rCol, nRow, 0, 2); |
931 | | |
932 | 0 | else if(nMonth >= 7 && nMonth <=9) |
933 | 0 | rDoc.SetValue(rCol, nRow, 0, 3); |
934 | | |
935 | 0 | else if(nMonth >= 10 && nMonth <=12) |
936 | 0 | rDoc.SetValue(rCol, nRow, 0, 4); |
937 | 0 | else |
938 | 0 | rDoc.SetValue(rCol, nRow, 0, -1); |
939 | |
|
940 | 0 | } |
941 | 0 | } |
942 | 0 | } |
943 | 0 | break; |
944 | 0 | case DATETIME_TRANSFORMATION_TYPE::START_OF_QUARTER: |
945 | 0 | { |
946 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
947 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
948 | 0 | sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage ); |
949 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
950 | 0 | { |
951 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
952 | 0 | if (eType == CELLTYPE_VALUE) |
953 | 0 | { |
954 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
955 | 0 | ScAddress aAddress(rCol, nRow, 0); |
956 | 0 | Date aDate = getDate(nVal, pFormatter); |
957 | |
|
958 | 0 | int nMonth = aDate.GetMonth(); |
959 | |
|
960 | 0 | if(nMonth >= 1 && nMonth <=3) |
961 | 0 | { |
962 | 0 | aDate.SetDay(1); |
963 | 0 | aDate.SetMonth(1); |
964 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
965 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
966 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
967 | 0 | } |
968 | 0 | else if(nMonth >= 4 && nMonth <=6) |
969 | 0 | { |
970 | 0 | aDate.SetDay(1); |
971 | 0 | aDate.SetMonth(4); |
972 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
973 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
974 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
975 | 0 | } |
976 | 0 | else if(nMonth >= 7 && nMonth <=9) |
977 | 0 | { |
978 | 0 | aDate.SetDay(1); |
979 | 0 | aDate.SetMonth(7); |
980 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
981 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
982 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
983 | 0 | } |
984 | 0 | else if(nMonth >= 10 && nMonth <=12) |
985 | 0 | { |
986 | 0 | aDate.SetDay(1); |
987 | 0 | aDate.SetMonth(10); |
988 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
989 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
990 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
991 | 0 | } |
992 | 0 | else |
993 | 0 | rDoc.SetValue(rCol, nRow, 0, -1); |
994 | 0 | } |
995 | 0 | } |
996 | 0 | } |
997 | 0 | break; |
998 | 0 | case DATETIME_TRANSFORMATION_TYPE::END_OF_QUARTER: |
999 | 0 | { |
1000 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
1001 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
1002 | 0 | sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage ); |
1003 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
1004 | 0 | { |
1005 | 0 | ScAddress aAddress(rCol, nRow, 0); |
1006 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
1007 | 0 | if (eType == CELLTYPE_VALUE) |
1008 | 0 | { |
1009 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
1010 | 0 | Date aDate = getDate(nVal, pFormatter); |
1011 | 0 | int nMonth = aDate.GetMonth(); |
1012 | |
|
1013 | 0 | if(nMonth >= 1 && nMonth <=3) |
1014 | 0 | { |
1015 | 0 | aDate.SetDay(31); |
1016 | 0 | aDate.SetMonth(3); |
1017 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
1018 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
1019 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
1020 | 0 | } |
1021 | | |
1022 | 0 | else if(nMonth >= 4 && nMonth <=6) |
1023 | 0 | { |
1024 | 0 | aDate.SetDay(30); |
1025 | 0 | aDate.SetMonth(6); |
1026 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
1027 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
1028 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
1029 | 0 | } |
1030 | | |
1031 | 0 | else if(nMonth >= 7 && nMonth <=9) |
1032 | 0 | { |
1033 | 0 | aDate.SetDay(30); |
1034 | 0 | aDate.SetMonth(9); |
1035 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
1036 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
1037 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
1038 | 0 | } |
1039 | | |
1040 | 0 | else if(nMonth >= 10 && nMonth <=12) |
1041 | 0 | { |
1042 | 0 | aDate.SetDay(31); |
1043 | 0 | aDate.SetMonth(12); |
1044 | 0 | nVal = aDate - pFormatter->GetNullDate(); |
1045 | 0 | rDoc.SetValue(rCol, nRow, 0, nVal); |
1046 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
1047 | 0 | } |
1048 | 0 | else |
1049 | 0 | rDoc.SetValue(rCol, nRow, 0, -1); |
1050 | |
|
1051 | 0 | } |
1052 | 0 | } |
1053 | 0 | } |
1054 | 0 | break; |
1055 | 0 | case DATETIME_TRANSFORMATION_TYPE::TIME: |
1056 | 0 | { |
1057 | 0 | SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); |
1058 | 0 | LanguageType eLanguage = ScGlobal::eLnge; |
1059 | 0 | sal_uInt32 nFormat = pFormatter->GetStandardFormat(SvNumFormatType::TIME, eLanguage); |
1060 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
1061 | 0 | { |
1062 | 0 | ScAddress aAddress(rCol, nRow, 0); |
1063 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
1064 | 0 | if (eType == CELLTYPE_VALUE) |
1065 | 0 | { |
1066 | 0 | rDoc.SetNumberFormat(aAddress, nFormat); |
1067 | 0 | } |
1068 | 0 | } |
1069 | 0 | } |
1070 | 0 | break; |
1071 | 0 | case DATETIME_TRANSFORMATION_TYPE::HOUR: |
1072 | 0 | { |
1073 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
1074 | 0 | { |
1075 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
1076 | 0 | if (eType == CELLTYPE_VALUE) |
1077 | 0 | { |
1078 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
1079 | 0 | sal_uInt16 nHour, nMinute, nSecond; |
1080 | 0 | double fFractionOfSecond; |
1081 | 0 | tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0); |
1082 | 0 | rDoc.SetValue(rCol, nRow, 0, nHour); |
1083 | 0 | } |
1084 | 0 | } |
1085 | 0 | } |
1086 | 0 | break; |
1087 | 0 | case DATETIME_TRANSFORMATION_TYPE::MINUTE: |
1088 | 0 | { |
1089 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
1090 | 0 | { |
1091 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
1092 | 0 | if (eType == CELLTYPE_VALUE) |
1093 | 0 | { |
1094 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
1095 | 0 | sal_uInt16 nHour, nMinute, nSecond; |
1096 | 0 | double fFractionOfSecond; |
1097 | 0 | tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0); |
1098 | 0 | rDoc.SetValue(rCol, nRow, 0, nMinute); |
1099 | 0 | } |
1100 | 0 | } |
1101 | 0 | } |
1102 | 0 | break; |
1103 | 0 | case DATETIME_TRANSFORMATION_TYPE::SECOND: |
1104 | 0 | { |
1105 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
1106 | 0 | { |
1107 | 0 | CellType eType = rDoc.GetCellType(rCol, nRow, 0); |
1108 | 0 | if (eType == CELLTYPE_VALUE) |
1109 | 0 | { |
1110 | 0 | double nVal = rDoc.GetValue(rCol, nRow, 0); |
1111 | 0 | sal_uInt16 nHour, nMinute, nSecond; |
1112 | 0 | double fFractionOfSecond; |
1113 | 0 | tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0); |
1114 | 0 | rDoc.SetValue(rCol, nRow, 0, nSecond); |
1115 | 0 | } |
1116 | 0 | } |
1117 | 0 | } |
1118 | 0 | break; |
1119 | 0 | default: |
1120 | 0 | break; |
1121 | 0 | } |
1122 | 0 | } |
1123 | 0 | } |
1124 | | |
1125 | | TransformationType DateTimeTransformation::getTransformationType() const |
1126 | 0 | { |
1127 | 0 | return TransformationType::DATETIME_TRANSFORMATION; |
1128 | 0 | } |
1129 | | |
1130 | | DATETIME_TRANSFORMATION_TYPE DateTimeTransformation::getDateTimeTransformationType() const |
1131 | 0 | { |
1132 | 0 | return maType; |
1133 | 0 | } |
1134 | | |
1135 | | const std::set<SCCOL>& DateTimeTransformation::getColumn() const |
1136 | 0 | { |
1137 | 0 | return mnCol; |
1138 | 0 | } |
1139 | | |
1140 | | FindReplaceTransformation::FindReplaceTransformation(SCCOL nCol, OUString aFindString, OUString aReplaceString) |
1141 | 0 | : mnCol(nCol) |
1142 | 0 | , maFindString(std::move(aFindString)) |
1143 | 0 | , maReplaceString(std::move(aReplaceString)) |
1144 | 0 | { |
1145 | 0 | } |
1146 | | |
1147 | | void FindReplaceTransformation::Transform(ScDocument& rDoc) const |
1148 | 0 | { |
1149 | 0 | if (mnCol == -1) |
1150 | 0 | return; |
1151 | | |
1152 | 0 | SCROW nEndRow = getLastRow(rDoc, mnCol); |
1153 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
1154 | 0 | { |
1155 | 0 | CellType eType = rDoc.GetCellType(mnCol, nRow, 0); |
1156 | 0 | if (eType != CELLTYPE_NONE) |
1157 | 0 | { |
1158 | 0 | OUString aStr = rDoc.GetString(mnCol, nRow, 0); |
1159 | 0 | if (aStr == maFindString) |
1160 | 0 | rDoc.SetString(mnCol, nRow, 0, maReplaceString); |
1161 | 0 | } |
1162 | 0 | } |
1163 | 0 | } |
1164 | | |
1165 | | TransformationType FindReplaceTransformation::getTransformationType() const |
1166 | 0 | { |
1167 | 0 | return TransformationType::FINDREPLACE_TRANSFORMATION; |
1168 | 0 | } |
1169 | | |
1170 | | DeleteRowTransformation::DeleteRowTransformation(SCCOL nCol, OUString aFindString) |
1171 | 0 | : mnCol(nCol) |
1172 | 0 | , maFindString(std::move(aFindString)) |
1173 | 0 | { |
1174 | 0 | } |
1175 | | |
1176 | | void DeleteRowTransformation::Transform(ScDocument& rDoc) const |
1177 | 0 | { |
1178 | 0 | sal_Int32 nIncrementIndex = 0; |
1179 | 0 | if (mnCol == -1) |
1180 | 0 | return; |
1181 | | |
1182 | 0 | SCROW nEndRow = getLastRow(rDoc, mnCol); |
1183 | 0 | for (SCROW nRow = 0; nRow <= nEndRow; ++nRow) |
1184 | 0 | { |
1185 | 0 | CellType eType = rDoc.GetCellType(mnCol, nRow - nIncrementIndex, 0); |
1186 | 0 | if (eType != CELLTYPE_NONE) |
1187 | 0 | { |
1188 | 0 | OUString aStr = rDoc.GetString(mnCol, nRow - nIncrementIndex, 0); |
1189 | 0 | if (aStr == maFindString) |
1190 | 0 | { |
1191 | 0 | rDoc.DeleteRow(0, 0, rDoc.MaxCol(), 0, nRow - nIncrementIndex, 1); |
1192 | 0 | nIncrementIndex++; |
1193 | 0 | } |
1194 | 0 | } |
1195 | 0 | } |
1196 | 0 | } |
1197 | | |
1198 | | TransformationType DeleteRowTransformation::getTransformationType() const |
1199 | 0 | { |
1200 | 0 | return TransformationType::DELETEROW_TRANSFORMATION; |
1201 | 0 | } |
1202 | | |
1203 | | SwapRowsTransformation::SwapRowsTransformation(SCROW mRow, SCROW nRow) |
1204 | 0 | : mxRow(mRow) |
1205 | 0 | , nxRow(nRow) |
1206 | 0 | { |
1207 | 0 | } |
1208 | | |
1209 | | void SwapRowsTransformation::Transform(ScDocument& rDoc) const |
1210 | 0 | { |
1211 | 0 | if (mxRow == -1 || nxRow == -1) |
1212 | 0 | return; |
1213 | | |
1214 | 0 | for (SCCOL nCol = 0; nCol <= rDoc.MaxCol(); ++nCol) |
1215 | 0 | { |
1216 | 0 | CellType aType = rDoc.GetCellType(nCol, mxRow, 0); |
1217 | 0 | if (aType == CELLTYPE_STRING) |
1218 | 0 | { |
1219 | 0 | OUString aStr = rDoc.GetString(nCol, mxRow, 0); |
1220 | 0 | OUString bStr = rDoc.GetString(nCol, nxRow, 0); |
1221 | 0 | rDoc.SetString(nCol, mxRow, 0, bStr); |
1222 | 0 | rDoc.SetString(nCol, nxRow, 0, aStr); |
1223 | 0 | } |
1224 | 0 | else if (aType == CELLTYPE_VALUE) |
1225 | 0 | { |
1226 | 0 | double aVal = rDoc.GetValue(nCol, mxRow, 0); |
1227 | 0 | double bVal = rDoc.GetValue(nCol, nxRow, 0); |
1228 | 0 | rDoc.SetValue(nCol, mxRow, 0, bVal); |
1229 | 0 | rDoc.SetValue(nCol, nxRow, 0, aVal); |
1230 | 0 | } |
1231 | 0 | } |
1232 | 0 | } |
1233 | | |
1234 | | TransformationType SwapRowsTransformation::getTransformationType() const |
1235 | 0 | { |
1236 | 0 | return TransformationType::SWAPROWS_TRANSFORMATION; |
1237 | 0 | } |
1238 | | |
1239 | | } |
1240 | | |
1241 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |