LibreOffice Module sc (master) 1
datatransformation.cxx
Go to the documentation of this file.
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
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>
18#include <utility>
19
20namespace {
21
22Date getDate(double nDateTime, const SvNumberFormatter* pFormatter)
23{
24 Date aDate = pFormatter->GetNullDate();
25 aDate.AddDays(static_cast<sal_Int32>(::rtl::math::approxFloor(nDateTime)));
26 return aDate;
27}
28}
29
30namespace sc {
32{
33}
34
36{
37 SCROW nEndRow = rDoc.MaxRow();
38
39 return rDoc.GetLastDataRow(0, nCol, nCol, nEndRow);
40}
41
43 maColumns(std::move(rColumns))
44{
45}
46
48{
49}
50
52{
53 sal_Int32 nIncrementIndex = 0;
54 for (auto& rCol : maColumns)
55 {
56 rDoc.DeleteCol(0, 0, rDoc.MaxRow(), 0, rCol - nIncrementIndex, 1);
57 nIncrementIndex++;
58 }
59}
60
62{
64}
65
66const std::set<SCCOL> & ColumnRemoveTransformation::getColumns() const
67{
68 return maColumns;
69}
70
72 mnCol(nCol),
73 mcSeparator(cSeparator)
74{
75}
76
78{
79 if (mnCol == -1)
80 return;
81
82 rDoc.InsertCol(0, 0, rDoc.MaxRow(), 0, mnCol + 1, 1);
83
84 SCROW nEndRow = getLastRow(rDoc, mnCol);
85 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
86 {
87 CellType eType = rDoc.GetCellType(mnCol, nRow, 0);
89 {
90 OUString aStr = rDoc.GetString(mnCol, nRow, 0);
91 sal_Int32 nIndex = aStr.indexOf(mcSeparator);
92 if (nIndex != -1)
93 {
94 rDoc.SetString(mnCol + 1, nRow, 0, aStr.copy(nIndex + 1));
95 rDoc.SetString(mnCol, nRow, 0, aStr.copy(0, nIndex));
96 }
97 }
98 }
99}
100
102{
104}
105
107{
108 return mnCol;
109}
110
112{
113 return mcSeparator;
114}
115
116MergeColumnTransformation::MergeColumnTransformation( std::set<SCCOL>&& rColumns, OUString aMergeString):
117 maColumns(std::move(rColumns)),
118 maMergeString(std::move(aMergeString))
119{
120}
121
123{
124 if (maColumns.empty())
125 return;
126
127 SCROW nMaxRow = 0;
128 for (auto& itr : maColumns)
129 {
130 nMaxRow = getLastRow(rDoc, itr);
131 }
132 assert(nMaxRow != -1);
133
134 SCCOL nTargetCol = *maColumns.begin();
135
136
137 for (SCROW nRow = 0; nRow <= nMaxRow; ++nRow)
138 {
139 OUStringBuffer aStr(rDoc.GetString(nTargetCol, nRow, 0));
140 for (auto& itr : maColumns)
141 {
142 if (itr != nTargetCol)
143 {
144 aStr.append(maMergeString + rDoc.GetString(itr, nRow, 0));
145 }
146 }
147 rDoc.SetString(nTargetCol, nRow, 0, aStr.makeStringAndClear());
148 }
149
150 for (auto& itr : maColumns)
151 {
152 if (itr == nTargetCol)
153 continue;
154
155 rDoc.DeleteCol(0, 0, rDoc.MaxRow(), 0, itr, 1);
156 }
157}
158
160{
162}
163
165{
166 return maMergeString;
167}
168
169const std::set<SCCOL> & MergeColumnTransformation::getColumns() const
170{
171 return maColumns;
172}
173
175 maSortParam(rSortParam)
176{
177}
178
180{
181 rDoc.Sort(0, maSortParam, false, false, nullptr, nullptr);
182}
183
185{
187}
188
190{
191 return maSortParam;
192}
193
195 mnCol(std::move(nCol)),
196 maType(rType)
197{
198}
199
201{
202 SCROW nEndRow = 0;
203 for(auto& rCol : mnCol)
204 {
205 nEndRow = getLastRow(rDoc, rCol);
206 }
207 assert(nEndRow != -1);
208
209 for(auto& rCol : mnCol)
210 {
211 switch (maType)
212 {
214 {
215 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
216 {
217 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
218 if (eType == CELLTYPE_STRING)
219 {
220 OUString aStr = rDoc.GetString(rCol, nRow, 0);
221 rDoc.SetString(rCol, nRow, 0, ScGlobal::getCharClass().lowercase(aStr));
222 }
223 }
224 }
225 break;
227 {
228 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
229 {
230 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
231 if (eType == CELLTYPE_STRING)
232 {
233 OUString aStr = rDoc.GetString(rCol, nRow, 0);
234 rDoc.SetString(rCol, nRow, 0, ScGlobal::getCharClass().uppercase(aStr));
235 }
236 }
237 }
238 break;
240 {
241 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
242 {
243 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
244 if (eType == CELLTYPE_STRING)
245 {
246 OUString aStr = rDoc.GetString(rCol, nRow, 0);
247
248 sal_Int32 length = aStr.getLength();
249
250 if(length != 0)
251 aStr = aStr.replaceAt(0, 1, ScGlobal::getCharClass().uppercase(OUString(aStr[0])));
252
253 for (sal_Int32 i = 1; i < length; i++){
254 if (aStr[i-1] == sal_Unicode(U' '))
255 {
256 aStr = aStr.replaceAt(i, 1, ScGlobal::getCharClass().uppercase(OUString(aStr[i])));
257 }
258 else
259 {
260 aStr = aStr.replaceAt(i, 1, ScGlobal::getCharClass().lowercase(OUString(aStr[i])));
261 }
262 }
263 rDoc.SetString(rCol, nRow, 0, aStr);
264 }
265 }
266 }
267 break;
269 {
270 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
271 {
272 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
273 if (eType == CELLTYPE_STRING)
274 {
275 OUString aStr = rDoc.GetString(rCol, nRow, 0);
276 rDoc.SetString(rCol, nRow, 0, aStr.trim());
277 }
278 }
279 }
280 break;
281 default:
282 break;
283 }
284 }
285}
286
288{
290}
291
293{
294 return maType;
295}
296
297const std::set<SCCOL>& TextTransformation::getColumns() const
298{
299 return mnCol;
300}
301
302AggregateFunction::AggregateFunction(std::set<SCCOL>&& rColumns, const AGGREGATE_FUNCTION rType):
303 maColumns(std::move(rColumns)),
304 maType(rType)
305{
306}
307
309{
310 SCROW nEndRow = 0;
311 for (auto& itr : maColumns)
312 {
313 nEndRow = getLastRow(rDoc, itr);
314 }
315 assert(nEndRow != -1);
316
317 for (auto& rCol : maColumns)
318 {
319 switch (maType)
320 {
322 {
323 double nSum = 0;
324 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
325 {
326 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
327 if (eType == CELLTYPE_VALUE)
328 {
329 double nVal = rDoc.GetValue(rCol, nRow, 0);
330 nSum += nVal;
331 }
332 }
333 rDoc.SetValue(rCol, nEndRow + 1, 0, nSum);
334 }
335 break;
337 {
338 double nSum = 0;
339 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
340 {
341 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
342 if (eType == CELLTYPE_VALUE)
343 {
344 double nVal = rDoc.GetValue(rCol, nRow, 0);
345 nSum += nVal;
346 }
347 }
348
349 double nAvg = nSum / (nEndRow + 1);
350 rDoc.SetValue(rCol, nEndRow + 1, 0, nAvg);
351 }
352 break;
354 {
355 double nMin = std::numeric_limits<double>::max();
356 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
357 {
358 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
359 if (eType == CELLTYPE_VALUE)
360 {
361 double nVal = rDoc.GetValue(rCol, nRow, 0);
362 if(nVal < nMin)
363 nMin = nVal;
364 }
365 }
366 rDoc.SetValue(rCol, nEndRow + 1, 0, nMin);
367 }
368 break;
370 {
371 double nMax = std::numeric_limits<double>::lowest();
372 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
373 {
374 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
375 if (eType == CELLTYPE_VALUE)
376 {
377 double nVal = rDoc.GetValue(rCol, nRow, 0);
378 if(nMax < nVal)
379 nMax = nVal;
380 }
381 }
382 rDoc.SetValue(rCol, nEndRow + 1, 0, nMax);
383 }
384 break;
385 default:
386 break;
387 }
388 }
389}
390
392{
394}
395
397{
398 return maType;
399}
400
401const std::set<SCCOL>& AggregateFunction::getColumns() const
402{
403 return maColumns;
404}
405
407 const NUMBER_TRANSFORM_TYPE rType)
408 : mnCol(std::move(nCol))
409 , maType(rType)
410 , maPrecision(-1)
411{
412}
413
415 const NUMBER_TRANSFORM_TYPE rType, int nPrecision)
416 : mnCol(std::move(nCol))
417 , maType(rType)
418 , maPrecision(nPrecision)
419{
420}
421
423{
424 SCROW nEndRow = 0;
425 for(auto& rCol : mnCol)
426 {
427 nEndRow = getLastRow(rDoc, rCol);
428 }
429 assert(nEndRow != -1);
430
431 for(auto& rCol : mnCol)
432 {
433 switch (maType)
434 {
436 {
437 if(maPrecision > -1)
438 {
439 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
440 {
441 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
442 if (eType == CELLTYPE_VALUE)
443 {
444 double nVal = rDoc.GetValue(rCol, nRow, 0);
445 rDoc.SetValue(rCol, nRow, 0, rtl::math::round(nVal, maPrecision));
446 }
447 }
448 }
449 }
450 break;
452 {
453 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
454 {
455 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
456 if (eType == CELLTYPE_VALUE)
457 {
458 double nVal = rDoc.GetValue(rCol, nRow, 0);
459 rDoc.SetValue(rCol, nRow, 0, rtl::math::approxCeil(nVal));
460 }
461 }
462 }
463 break;
465 {
466 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
467 {
468 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
469 if (eType == CELLTYPE_VALUE)
470 {
471 double nVal = rDoc.GetValue(rCol, nRow, 0);
472 rDoc.SetValue(rCol, nRow, 0, rtl::math::approxFloor(nVal));
473 }
474 }
475 }
476 break;
478 {
479 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
480 {
481 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
482 if (eType == CELLTYPE_VALUE)
483 {
484 double nVal = rDoc.GetValue(rCol, nRow, 0);
485 if(std::signbit(nVal))
486 rDoc.SetValue(rCol, nRow, 0, -1 * nVal);
487 }
488 }
489 }
490 break;
492 {
493 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
494 {
495 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
496 if (eType == CELLTYPE_VALUE)
497 {
498 double nVal = rDoc.GetValue(rCol, nRow, 0);
499 if (nVal > 0)
500 {
501 rDoc.SetValue(rCol, nRow, 0, std::log1p(nVal-1));
502 }
503 else
504 {
505 rDoc.SetString(rCol, nRow, 0, OUString());
506 }
507 }
508 }
509 }
510 break;
512 {
513 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
514 {
515 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
516 if (eType == CELLTYPE_VALUE)
517 {
518 double nVal = rDoc.GetValue(rCol, nRow, 0);
519 if (nVal > 0)
520 {
521 rDoc.SetValue(rCol, nRow, 0, log10(nVal));
522 }
523 else
524 {
525 rDoc.SetString(rCol, nRow, 0, OUString());
526 }
527 }
528 }
529 }
530 break;
532 {
533 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
534 {
535 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
536 if (eType == CELLTYPE_VALUE)
537 {
538 double nVal = rDoc.GetValue(rCol, nRow, 0);
539 rDoc.SetValue(rCol, nRow, 0, nVal * nVal * nVal);
540 }
541 }
542 }
543 break;
545 {
546 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
547 {
548 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
549 if (eType == CELLTYPE_VALUE)
550 {
551 double nVal = rDoc.GetValue(rCol, nRow, 0);
552 rDoc.SetValue(rCol, nRow, 0, nVal * nVal);
553 }
554 }
555 }
556 break;
558 {
559 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
560 {
561 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
562 if (eType == CELLTYPE_VALUE)
563 {
564 double nVal = rDoc.GetValue(rCol, nRow, 0);
565 if (!std::signbit(nVal))
566 {
567 rDoc.SetValue(rCol, nRow, 0, sqrt(nVal));
568 }
569 else
570 {
571 rDoc.SetString(rCol, nRow, 0, OUString());
572 }
573 }
574 }
575 }
576 break;
578 {
579 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
580 {
581 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
582 if (eType == CELLTYPE_VALUE)
583 {
584 double nVal = rDoc.GetValue(rCol, nRow, 0);
585 if (fmod(nVal, 1) == 0 && fmod(nVal, 2) == 0)
586 rDoc.SetValue(rCol, nRow, 0, 1);
587 else
588 rDoc.SetValue(rCol, nRow, 0, 0);
589 }
590 }
591 }
592 break;
594 {
595 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
596 {
597 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
598 if (eType == CELLTYPE_VALUE)
599 {
600 double nVal = rDoc.GetValue(rCol, nRow, 0);
601 if (fmod(nVal, 1) == 0 && fmod(nVal, 2) != 0)
602 rDoc.SetValue(rCol, nRow, 0, 1);
603 else
604 rDoc.SetValue(rCol, nRow, 0, 0);
605 }
606 }
607 }
608 break;
610 {
611 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
612 {
613 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
614 if (eType == CELLTYPE_VALUE)
615 {
616 double nVal = rDoc.GetValue(rCol, nRow, 0);
617 if (nVal > 0)
618 rDoc.SetValue(rCol, nRow, 0, 1);
619 else if (nVal < 0)
620 rDoc.SetValue(rCol, nRow, 0, -1);
621 else
622 rDoc.SetValue(rCol, nRow, 0, 0);
623 }
624 }
625 }
626 break;
627 default:
628 break;
629 }
630 }
631}
632
634{
636}
637
639{
640 return maType;
641}
642
644{
645 return maPrecision;
646}
647
648const std::set<SCCOL>& NumberTransformation::getColumn() const
649{
650 return mnCol;
651}
652
654 OUString sReplaceWith)
655 : mnCol(std::move(nCol))
656 , msReplaceWith(std::move(sReplaceWith))
657{
658}
659
661{
662 if (mnCol.empty())
663 return;
664
665 for(auto& rCol : mnCol)
666 {
667 SCROW nEndRow = getLastRow(rDoc, rCol);
668 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
669 {
670 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
671 if (eType == CELLTYPE_NONE)
672 {
673 // OUString aStr = rDoc.GetString(rCol, nRow, 0);
674 // if (aStr == "" || aStr.isEmpty())
675 rDoc.SetString(rCol, nRow, 0, msReplaceWith);
676 }
677 }
678 }
679
680}
681
682const std::set<SCCOL>& ReplaceNullTransformation::getColumn() const
683{
684 return mnCol;
685}
686
688{
689 return msReplaceWith;
690}
691
693{
695}
696
699 : mnCol(std::move(nCol))
700 , maType(rType)
701{
702}
703
705{
706 SCROW nEndRow = 0;
707 for(auto& rCol : mnCol)
708 {
709 nEndRow = getLastRow(rDoc, rCol);
710 }
711 assert(nEndRow != -1);
712
713 for(auto& rCol : mnCol)
714 {
715 switch (maType)
716 {
718 {
719 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
720 LanguageType eLanguage = ScGlobal::eLnge;
721 sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage );
722 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
723 {
724 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
725 if (eType == CELLTYPE_VALUE)
726 {
727 ScAddress aAddress(rCol, nRow, 0);
728 rDoc.SetNumberFormat(aAddress, nFormat);
729 }
730 }
731 }
732 break;
734 {
735 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
736 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
737 {
738 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
739 if (eType == CELLTYPE_VALUE)
740 {
741 double nVal = rDoc.GetValue(rCol, nRow, 0);
742 Date aDate = getDate(nVal, pFormatter);
743 rDoc.SetValue(rCol, nRow, 0, aDate.GetYear());
744 }
745 }
746 }
747 break;
749 {
750 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
751 LanguageType eLanguage = ScGlobal::eLnge;
752 sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage );
753 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
754 {
755 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
756 if (eType == CELLTYPE_VALUE)
757 {
758 double nVal = rDoc.GetValue(rCol, nRow, 0);
759 Date aDate = getDate(nVal, pFormatter);
760 aDate.SetDay(1);
761 aDate.SetMonth(1);
762 nVal = aDate - pFormatter->GetNullDate();
763 ScAddress aAddress(rCol, nRow, 0);
764 rDoc.SetValue(rCol, nRow, 0, nVal);
765 rDoc.SetNumberFormat(aAddress, nFormat);
766 }
767 }
768 }
769 break;
771 {
772 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
773 LanguageType eLanguage = ScGlobal::eLnge;
774 sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage );
775
776 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
777 {
778 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
779 if (eType == CELLTYPE_VALUE)
780 {
781 double nVal = rDoc.GetValue(rCol, nRow, 0);
782 Date aDate = getDate(nVal, pFormatter);
783 aDate.SetMonth(12);
784 aDate.SetDay(31);
785 nVal = aDate - pFormatter->GetNullDate();
786 ScAddress aAddress(rCol, nRow, 0);
787 rDoc.SetValue(rCol, nRow, 0, nVal);
788 rDoc.SetNumberFormat(aAddress, nFormat);
789 }
790 }
791 }
792 break;
794 {
795 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
796 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
797 {
798 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
799 if (eType == CELLTYPE_VALUE)
800 {
801 double nVal = rDoc.GetValue(rCol, nRow, 0);
802 Date aDate = getDate(nVal, pFormatter);
803 rDoc.SetValue(rCol, nRow, 0, aDate.GetMonth());
804 }
805 }
806 }
807 break;
809 {
810 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
811 LanguageType eLanguage = ScGlobal::eLnge;
812 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
813 {
814 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
815 if (eType == CELLTYPE_VALUE)
816 {
817 double nVal = rDoc.GetValue(rCol, nRow, 0);
818 const Color* pColor = nullptr;
819 OUString aResult;
820 pFormatter->GetPreviewStringGuess("MMMM", nVal, aResult, &pColor, eLanguage);
821 rDoc.SetString(rCol, nRow, 0, aResult);
822 }
823 }
824 }
825 break;
827 {
828 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
829 LanguageType eLanguage = ScGlobal::eLnge;
830 sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage );
831 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
832 {
833 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
834 if (eType == CELLTYPE_VALUE)
835 {
836 double nVal = rDoc.GetValue(rCol, nRow, 0);
837 ScAddress aAddress(rCol, nRow, 0);
838 Date aDate = getDate(nVal, pFormatter);
839 aDate.SetDay(1);
840 nVal = aDate - pFormatter->GetNullDate();
841 rDoc.SetValue(rCol, nRow, 0, nVal);
842 rDoc.SetNumberFormat(aAddress, nFormat);
843 }
844 }
845 }
846 break;
848 {
849 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
850 LanguageType eLanguage = ScGlobal::eLnge;
851 sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage );
852 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
853 {
854 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
855 if (eType == CELLTYPE_VALUE)
856 {
857 double nVal = rDoc.GetValue(rCol, nRow, 0);
858 ScAddress aAddress(rCol, nRow, 0);
859 Date aDate = getDate(nVal, pFormatter);
860 aDate.SetDay(aDate.GetDaysInMonth());
861 nVal = aDate - pFormatter->GetNullDate();
862 rDoc.SetValue(rCol, nRow, 0, nVal);
863 rDoc.SetNumberFormat(aAddress, nFormat);
864 }
865 }
866 }
867 break;
869 {
870 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
871 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
872 {
873 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
874 if (eType == CELLTYPE_VALUE)
875 {
876 double nVal = rDoc.GetValue(rCol, nRow, 0);
877 Date aDate = getDate(nVal, pFormatter);
878 rDoc.SetValue(rCol, nRow, 0, aDate.GetDay());
879 }
880 }
881 }
882 break;
884 {
885 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
886 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
887 {
888 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
889 if (eType == CELLTYPE_VALUE)
890 {
891 double nVal = rDoc.GetValue(rCol, nRow, 0);
892 Date aDate = getDate(nVal, pFormatter);
893 rDoc.SetValue(rCol, nRow, 0, aDate.GetDayOfWeek());
894 }
895 }
896 }
897 break;
899 {
900 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
901 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
902 {
903 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
904 if (eType == CELLTYPE_VALUE)
905 {
906 double nVal = rDoc.GetValue(rCol, nRow, 0);
907 Date aDate = getDate(nVal, pFormatter);
908 rDoc.SetValue(rCol, nRow, 0, aDate.GetDayOfYear());
909 }
910 }
911 }
912 break;
914 {
915 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
916 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
917 {
918 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
919 if (eType == CELLTYPE_VALUE)
920 {
921 double nVal = rDoc.GetValue(rCol, nRow, 0);
922 Date aDate = getDate(nVal, pFormatter);
923
924 int nMonth = aDate.GetMonth();
925
926 if(nMonth >= 1 && nMonth <=3)
927 rDoc.SetValue(rCol, nRow, 0, 1);
928
929 else if(nMonth >= 4 && nMonth <=6)
930 rDoc.SetValue(rCol, nRow, 0, 2);
931
932 else if(nMonth >= 7 && nMonth <=9)
933 rDoc.SetValue(rCol, nRow, 0, 3);
934
935 else if(nMonth >= 10 && nMonth <=12)
936 rDoc.SetValue(rCol, nRow, 0, 4);
937 else
938 rDoc.SetValue(rCol, nRow, 0, -1);
939
940 }
941 }
942 }
943 break;
945 {
946 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
947 LanguageType eLanguage = ScGlobal::eLnge;
948 sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage );
949 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
950 {
951 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
952 if (eType == CELLTYPE_VALUE)
953 {
954 double nVal = rDoc.GetValue(rCol, nRow, 0);
955 ScAddress aAddress(rCol, nRow, 0);
956 Date aDate = getDate(nVal, pFormatter);
957
958 int nMonth = aDate.GetMonth();
959
960 if(nMonth >= 1 && nMonth <=3)
961 {
962 aDate.SetDay(1);
963 aDate.SetMonth(1);
964 nVal = aDate - pFormatter->GetNullDate();
965 rDoc.SetValue(rCol, nRow, 0, nVal);
966 rDoc.SetNumberFormat(aAddress, nFormat);
967 }
968 else if(nMonth >= 4 && nMonth <=6)
969 {
970 aDate.SetDay(1);
971 aDate.SetMonth(4);
972 nVal = aDate - pFormatter->GetNullDate();
973 rDoc.SetValue(rCol, nRow, 0, nVal);
974 rDoc.SetNumberFormat(aAddress, nFormat);
975 }
976 else if(nMonth >= 7 && nMonth <=9)
977 {
978 aDate.SetDay(1);
979 aDate.SetMonth(7);
980 nVal = aDate - pFormatter->GetNullDate();
981 rDoc.SetValue(rCol, nRow, 0, nVal);
982 rDoc.SetNumberFormat(aAddress, nFormat);
983 }
984 else if(nMonth >= 10 && nMonth <=12)
985 {
986 aDate.SetDay(1);
987 aDate.SetMonth(10);
988 nVal = aDate - pFormatter->GetNullDate();
989 rDoc.SetValue(rCol, nRow, 0, nVal);
990 rDoc.SetNumberFormat(aAddress, nFormat);
991 }
992 else
993 rDoc.SetValue(rCol, nRow, 0, -1);
994 }
995 }
996 }
997 break;
999 {
1000 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
1001 LanguageType eLanguage = ScGlobal::eLnge;
1002 sal_uInt32 nFormat = pFormatter->GetStandardFormat( SvNumFormatType::DATE, eLanguage );
1003 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
1004 {
1005 ScAddress aAddress(rCol, nRow, 0);
1006 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
1007 if (eType == CELLTYPE_VALUE)
1008 {
1009 double nVal = rDoc.GetValue(rCol, nRow, 0);
1010 Date aDate = getDate(nVal, pFormatter);
1011 int nMonth = aDate.GetMonth();
1012
1013 if(nMonth >= 1 && nMonth <=3)
1014 {
1015 aDate.SetDay(31);
1016 aDate.SetMonth(3);
1017 nVal = aDate - pFormatter->GetNullDate();
1018 rDoc.SetValue(rCol, nRow, 0, nVal);
1019 rDoc.SetNumberFormat(aAddress, nFormat);
1020 }
1021
1022 else if(nMonth >= 4 && nMonth <=6)
1023 {
1024 aDate.SetDay(30);
1025 aDate.SetMonth(6);
1026 nVal = aDate - pFormatter->GetNullDate();
1027 rDoc.SetValue(rCol, nRow, 0, nVal);
1028 rDoc.SetNumberFormat(aAddress, nFormat);
1029 }
1030
1031 else if(nMonth >= 7 && nMonth <=9)
1032 {
1033 aDate.SetDay(30);
1034 aDate.SetMonth(9);
1035 nVal = aDate - pFormatter->GetNullDate();
1036 rDoc.SetValue(rCol, nRow, 0, nVal);
1037 rDoc.SetNumberFormat(aAddress, nFormat);
1038 }
1039
1040 else if(nMonth >= 10 && nMonth <=12)
1041 {
1042 aDate.SetDay(31);
1043 aDate.SetMonth(12);
1044 nVal = aDate - pFormatter->GetNullDate();
1045 rDoc.SetValue(rCol, nRow, 0, nVal);
1046 rDoc.SetNumberFormat(aAddress, nFormat);
1047 }
1048 else
1049 rDoc.SetValue(rCol, nRow, 0, -1);
1050
1051 }
1052 }
1053 }
1054 break;
1056 {
1057 SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
1058 LanguageType eLanguage = ScGlobal::eLnge;
1059 sal_uInt32 nFormat = pFormatter->GetStandardFormat(SvNumFormatType::TIME, eLanguage);
1060 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
1061 {
1062 ScAddress aAddress(rCol, nRow, 0);
1063 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
1064 if (eType == CELLTYPE_VALUE)
1065 {
1066 rDoc.SetNumberFormat(aAddress, nFormat);
1067 }
1068 }
1069 }
1070 break;
1072 {
1073 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
1074 {
1075 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
1076 if (eType == CELLTYPE_VALUE)
1077 {
1078 double nVal = rDoc.GetValue(rCol, nRow, 0);
1079 sal_uInt16 nHour, nMinute, nSecond;
1080 double fFractionOfSecond;
1081 tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0);
1082 rDoc.SetValue(rCol, nRow, 0, nHour);
1083 }
1084 }
1085 }
1086 break;
1088 {
1089 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
1090 {
1091 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
1092 if (eType == CELLTYPE_VALUE)
1093 {
1094 double nVal = rDoc.GetValue(rCol, nRow, 0);
1095 sal_uInt16 nHour, nMinute, nSecond;
1096 double fFractionOfSecond;
1097 tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0);
1098 rDoc.SetValue(rCol, nRow, 0, nMinute);
1099 }
1100 }
1101 }
1102 break;
1104 {
1105 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
1106 {
1107 CellType eType = rDoc.GetCellType(rCol, nRow, 0);
1108 if (eType == CELLTYPE_VALUE)
1109 {
1110 double nVal = rDoc.GetValue(rCol, nRow, 0);
1111 sal_uInt16 nHour, nMinute, nSecond;
1112 double fFractionOfSecond;
1113 tools::Time::GetClock( nVal, nHour, nMinute, nSecond, fFractionOfSecond, 0);
1114 rDoc.SetValue(rCol, nRow, 0, nSecond);
1115 }
1116 }
1117 }
1118 break;
1119 default:
1120 break;
1121 }
1122 }
1123}
1124
1126{
1128}
1129
1131{
1132 return maType;
1133}
1134
1135const std::set<SCCOL>& DateTimeTransformation::getColumn() const
1136{
1137 return mnCol;
1138}
1139
1140FindReplaceTransformation::FindReplaceTransformation(SCCOL nCol, OUString aFindString, OUString aReplaceString)
1141 : mnCol(nCol)
1142 , maFindString(std::move(aFindString))
1143 , maReplaceString(std::move(aReplaceString))
1144{
1145}
1146
1148{
1149 if (mnCol == -1)
1150 return;
1151
1152 SCROW nEndRow = getLastRow(rDoc, mnCol);
1153 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
1154 {
1155 CellType eType = rDoc.GetCellType(mnCol, nRow, 0);
1156 if (eType != CELLTYPE_NONE)
1157 {
1158 OUString aStr = rDoc.GetString(mnCol, nRow, 0);
1159 if (aStr == maFindString)
1160 rDoc.SetString(mnCol, nRow, 0, maReplaceString);
1161 }
1162 }
1163}
1164
1166{
1168}
1169
1171{
1172 return mnCol;
1173}
1174
1176{
1177 return maFindString;
1178}
1179
1181{
1182 return maReplaceString;
1183}
1184
1186 : mnCol(nCol)
1187 , maFindString(std::move(aFindString))
1188{
1189}
1190
1192{
1193 sal_Int32 nIncrementIndex = 0;
1194 if (mnCol == -1)
1195 return;
1196
1197 SCROW nEndRow = getLastRow(rDoc, mnCol);
1198 for (SCROW nRow = 0; nRow <= nEndRow; ++nRow)
1199 {
1200 CellType eType = rDoc.GetCellType(mnCol, nRow - nIncrementIndex, 0);
1201 if (eType != CELLTYPE_NONE)
1202 {
1203 OUString aStr = rDoc.GetString(mnCol, nRow - nIncrementIndex, 0);
1204 if (aStr == maFindString)
1205 {
1206 rDoc.DeleteRow(0, 0, rDoc.MaxCol(), 0, nRow - nIncrementIndex, 1);
1207 nIncrementIndex++;
1208 }
1209 }
1210 }
1211}
1212
1214{
1216}
1217
1219{
1220 return mnCol;
1221}
1222
1224{
1225 return maFindString;
1226}
1227
1229 : mxRow(mRow)
1230 , nxRow(nRow)
1231{
1232}
1233
1235{
1236 if (mxRow == -1 || nxRow == -1)
1237 return;
1238
1239 for (SCCOL nCol = 0; nCol <= rDoc.MaxCol(); ++nCol)
1240 {
1241 CellType aType = rDoc.GetCellType(nCol, mxRow, 0);
1242 if (aType == CELLTYPE_STRING)
1243 {
1244 OUString aStr = rDoc.GetString(nCol, mxRow, 0);
1245 OUString bStr = rDoc.GetString(nCol, nxRow, 0);
1246 rDoc.SetString(nCol, mxRow, 0, bStr);
1247 rDoc.SetString(nCol, nxRow, 0, aStr);
1248 }
1249 else if (aType == CELLTYPE_VALUE)
1250 {
1251 double aVal = rDoc.GetValue(nCol, mxRow, 0);
1252 double bVal = rDoc.GetValue(nCol, nxRow, 0);
1253 rDoc.SetValue(nCol, mxRow, 0, bVal);
1254 rDoc.SetValue(nCol, nxRow, 0, aVal);
1255 }
1256 }
1257}
1258
1260{
1262}
1263
1265{
1266 return mxRow;
1267}
1268
1270{
1271 return nxRow;
1272}
1273
1274}
1275
1276/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetDayOfYear() const
void AddDays(sal_Int32 nAddDays)
sal_Int16 GetYear() const
sal_uInt16 GetDay() const
sal_uInt16 GetDaysInMonth() const
void SetMonth(sal_uInt16 nNewMonth)
DayOfWeek GetDayOfWeek() const
void SetDay(sal_uInt16 nNewDay)
sal_uInt16 GetMonth() const
SC_DLLPUBLIC SCCOL MaxCol() const
Definition: document.hxx:892
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
SC_DLLPUBLIC double GetValue(const ScAddress &rPos) const
Definition: document.cxx:3626
SC_DLLPUBLIC SCROW GetLastDataRow(SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nLastRow) const
Return the last non-empty row position in given columns that's no greater than the initial last row p...
Definition: document.cxx:1063
SC_DLLPUBLIC void SetNumberFormat(const ScAddress &rPos, sal_uInt32 nNumberFormat)
Definition: document.cxx:3682
SC_DLLPUBLIC bool SetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const OUString &rString, const ScSetStringParam *pParam=nullptr)
Definition: document.cxx:3391
void DeleteRow(SCCOL nStartCol, SCTAB nStartTab, SCCOL nEndCol, SCTAB nEndTab, SCROW nStartRow, SCSIZE nSize, ScDocument *pRefUndoDoc=nullptr, bool *pUndoOutline=nullptr, const ScMarkData *pTabMark=nullptr)
Definition: document.cxx:1345
SC_DLLPUBLIC void SetValue(SCCOL nCol, SCROW nRow, SCTAB nTab, const double &rVal)
Definition: document.cxx:3477
void DeleteCol(SCROW nStartRow, SCTAB nStartTab, SCROW nEndRow, SCTAB nEndTab, SCCOL nStartCol, SCSIZE nSize, ScDocument *pRefUndoDoc=nullptr, bool *pUndoOutline=nullptr, const ScMarkData *pTabMark=nullptr)
Definition: document.cxx:1570
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:467
SC_DLLPUBLIC OUString GetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScInterpreterContext *pContext=nullptr) const
Definition: document.cxx:3505
SC_DLLPUBLIC CellType GetCellType(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:3736
bool InsertCol(SCROW nStartRow, SCTAB nStartTab, SCROW nEndRow, SCTAB nEndTab, SCCOL nStartCol, SCSIZE nSize, ScDocument *pRefUndoDoc=nullptr, const ScMarkData *pTabMark=nullptr)
Definition: document.cxx:1477
void Sort(SCTAB nTab, const ScSortParam &rSortParam, bool bKeepQuery, bool bUpdateRefs, ScProgress *pProgress, sc::ReorderParam *pUndo)
Sort a range of data.
Definition: documen3.cxx:1433
static SC_DLLPUBLIC LanguageType eLnge
Definition: global.hxx:560
static SC_DLLPUBLIC const CharClass & getCharClass()
Definition: global.cxx:1064
sal_uInt32 GetStandardFormat(SvNumFormatType eType, LanguageType eLnge=LANGUAGE_DONTKNOW)
const Date & GetNullDate() const
bool GetPreviewStringGuess(const OUString &sFormatString, double fPreviewNumber, OUString &sOutString, const Color **ppColor, LanguageType eLnge=LANGUAGE_DONTKNOW)
std::set< SCCOL > maColumns
virtual TransformationType getTransformationType() const override
AGGREGATE_FUNCTION getAggregateType() const
virtual void Transform(ScDocument &rDoc) const override
AggregateFunction(std::set< SCCOL > &&rColumns, const AGGREGATE_FUNCTION rType)
AGGREGATE_FUNCTION maType
const std::set< SCCOL > & getColumns() const
const std::set< SCCOL > & getColumns() const
virtual TransformationType getTransformationType() const override
virtual void Transform(ScDocument &rDoc) const override
virtual ~ColumnRemoveTransformation() override
ColumnRemoveTransformation(std::set< SCCOL > &&rColumns)
static SCROW getLastRow(const ScDocument &rDoc, SCCOL nCol)
DateTimeTransformation(std::set< SCCOL > &&nCol, const DATETIME_TRANSFORMATION_TYPE rType)
DATETIME_TRANSFORMATION_TYPE maType
virtual void Transform(ScDocument &rDoc) const override
const std::set< SCCOL > & getColumn() const
DATETIME_TRANSFORMATION_TYPE getDateTimeTransformationType() const
virtual TransformationType getTransformationType() const override
DeleteRowTransformation(SCCOL nCol, OUString aFindString)
virtual TransformationType getTransformationType() const override
const OUString & getFindString() const
virtual void Transform(ScDocument &rDoc) const override
const OUString & getFindString() const
const OUString & getReplaceString() const
virtual TransformationType getTransformationType() const override
FindReplaceTransformation(SCCOL nCol, OUString aFindString, OUString aReplaceString)
virtual void Transform(ScDocument &rDoc) const override
const OUString & getMergeString() const
virtual TransformationType getTransformationType() const override
const std::set< SCCOL > & getColumns() const
virtual void Transform(ScDocument &rDoc) const override
MergeColumnTransformation(std::set< SCCOL > &&rColumns, OUString aMergeString)
NUMBER_TRANSFORM_TYPE getNumberTransformationType() const
NUMBER_TRANSFORM_TYPE maType
virtual TransformationType getTransformationType() const override
NumberTransformation(std::set< SCCOL > &&nCol, const NUMBER_TRANSFORM_TYPE rType)
virtual void Transform(ScDocument &rDoc) const override
const std::set< SCCOL > & getColumn() const
const OUString & getReplaceString() const
virtual TransformationType getTransformationType() const override
virtual void Transform(ScDocument &rDoc) const override
ReplaceNullTransformation(std::set< SCCOL > &&nCol, OUString sReplaceWith)
const std::set< SCCOL > & getColumn() const
virtual void Transform(ScDocument &rDoc) const override
const ScSortParam & getSortParam() const
virtual TransformationType getTransformationType() const override
SortTransformation(const ScSortParam &rParam)
SplitColumnTransformation(SCCOL nCol, sal_Unicode cSeparator)
virtual TransformationType getTransformationType() const override
virtual void Transform(ScDocument &rDoc) const override
virtual TransformationType getTransformationType() const override
virtual void Transform(ScDocument &rDoc) const override
SwapRowsTransformation(SCROW mRow, SCROW nRow)
const std::set< SCCOL > & getColumns() const
TEXT_TRANSFORM_TYPE maType
TextTransformation(std::set< SCCOL > &&nCol, const TEXT_TRANSFORM_TYPE rType)
virtual void Transform(ScDocument &rDoc) const override
TEXT_TRANSFORM_TYPE getTextTransformationType() const
virtual TransformationType getTransformationType() const override
static void GetClock(double fTimeInDays, sal_uInt16 &nHour, sal_uInt16 &nMinute, sal_uInt16 &nSecond, double &fFractionOfSecond, int nFractionDecimals)
sal_Int32 mnCol
DocumentType eType
CellType
Definition: global.hxx:272
@ CELLTYPE_STRING
Definition: global.hxx:275
@ CELLTYPE_NONE
Definition: global.hxx:273
@ CELLTYPE_VALUE
Definition: global.hxx:274
sal_Int32 nIndex
aStr
int i
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
DATETIME_TRANSFORMATION_TYPE
OUString maType
sal_uInt16 sal_Unicode
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17