diff options
author | Eike Rathke <erack@redhat.com> | 2021-10-15 11:53:17 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2021-10-15 13:18:29 +0200 |
commit | 99adfcad3517de6530c9a2f025c528001f543ae2 (patch) | |
tree | 909751aed336cc42423e502fc9edfa2c35142c3f /sc | |
parent | 6daf40e440e457d1560d7fb13ebda8a17efbfe84 (diff) |
Resolves: tdf#88359 CSV: import strict ISO date(+time) with standard settings
i.e. without having to activate "Detect special numbers".
Now that we have NF_DATETIME_ISO_YYYYMMDDTHHMMSS000 for resulting
formats this is possible without losing details.
Only strict ISO 8601 extended separated format is converted, if
date+time then the T separator must be present, a space character
is not accepted instead.
Change-Id: I6126cae743ed55fa77915c730114c3f8f5baee8e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123652
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 714066c9fafd..382b3f64b19a 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -63,6 +63,7 @@ #include <editeng/editobj.hxx> #include <svl/numformat.hxx> #include <rtl/character.hxx> +#include <sax/tools/converter.hxx> #include <memory> #include <string_view> @@ -1406,6 +1407,48 @@ static bool lcl_PutString( // Standard or date not determined -> SetString / EditCell if( rStr.indexOf( '\n' ) == -1 ) { + if (!bDetectNumFormat && nColFormat == SC_COL_STANDARD) + { + // Import a strict ISO 8601 date(+time) string even without + // "Detect special numbers" or "Date (YMD)". + do + { + // Simple pre-check before calling more expensive parser. + // ([+-])(Y)YYYY-MM-DD + if (rStr.getLength() < 10) + break; + const sal_Int32 n1 = rStr.indexOf('-', 1); + if (n1 < 4) + break; + const sal_Int32 n2 = rStr.indexOf('-', n1 + 1); + if (n2 < 7 || n1 + 3 < n2) + break; + + css::util::DateTime aDateTime; + if (!sax::Converter::parseDateTime( aDateTime, rStr)) + break; + + sal_uInt32 nFormat = 0; + double fVal = 0.0; + SvNumberFormatter* pDocFormatter = rDoc.GetFormatTable(); + if (pDocFormatter->IsNumberFormat( rStr, nFormat, fVal)) + { + if (pDocFormatter->GetType(nFormat) & SvNumFormatType::DATE) + { + ScAddress aPos(nCol,nRow,nTab); + if (bUseDocImport) + rDocImport.setNumericCell(aPos, fVal); + else + rDoc.SetValue(aPos, fVal); + rDoc.SetNumberFormat(aPos, nFormat); + + return bMultiLine; // success + } + } + } + while(false); + } + ScSetStringParam aParam; aParam.mpNumFormatter = pFormatter; aParam.mbDetectNumberFormat = bDetectNumFormat; |