tdf#106678 Implement CSV filter option's 8th token

... which decides whether number cells are stored as numbers
or quoted like strings, as documented in
<https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options#Token_8.2C_csv_export>
but long unimplemented.

Note that in this implementation the false value of the above token
is superseded and ignored if either "Fixed column width" (1st token)
or "Save cell content as shown" (9th token) option is on.

Change-Id: Ib4ff02a2be81a8590e1fc249725f02cd83e91118
Reviewed-on: https://gerrit.libreoffice.org/65604
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
diff --git a/sc/source/ui/dbgui/imoptdlg.cxx b/sc/source/ui/dbgui/imoptdlg.cxx
index a71eaee..efaf07d 100644
--- a/sc/source/ui/dbgui/imoptdlg.cxx
+++ b/sc/source/ui/dbgui/imoptdlg.cxx
@@ -41,6 +41,7 @@
    eCharSet = RTL_TEXTENCODING_DONTKNOW;
    bSaveAsShown = true;    // "true" if not in string (after CSV import)
    bQuoteAllText = false;
    bSaveNumberAsSuch = true;
    bSaveFormulas = false;
    bRemoveSpace = false;
    sal_Int32 nTokenCount = comphelper::string::getTokenCount(rStr, ',');
@@ -67,6 +68,8 @@
            // look at the same positions as in ScAsciiOptions
            if ( nTokenCount >= 7 )
                bQuoteAllText = rStr.getToken(6, ',') == "true";
            if ( nTokenCount >= 8 )
                bSaveNumberAsSuch = rStr.getToken(7, ',') == "true";
            if ( nTokenCount >= 9 )
                bSaveAsShown = rStr.getToken(8, ',') == "true";
            if ( nTokenCount >= 10 )
@@ -89,7 +92,9 @@
                                                 // use the same string format as ScAsciiOptions:
            ",1,,0," +                           // first row, no column info, default language
            OUString::boolean( bQuoteAllText ) + // same as "quoted field as text" in ScAsciiOptions
            ",true," +                           // "detect special numbers"
            "," +
            OUString::boolean( bSaveNumberAsSuch ) + // "save number as such": not in ScAsciiOptions
            "," +
            OUString::boolean( bSaveAsShown ) +  // "save as shown": not in ScAsciiOptions
            "," +
            OUString::boolean( bSaveFormulas ) +  // "save formulas": not in ScAsciiOptions
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 7f45f99..7dbef7b 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1942,6 +1942,7 @@
    sal_Unicode cStrDelim = rAsciiOpt.nTextSepCode;
    rtl_TextEncoding eCharSet      = rAsciiOpt.eCharSet;
    bool bFixedWidth      = rAsciiOpt.bFixedWidth;
    bool bSaveNumberAsSuch = rAsciiOpt.bSaveNumberAsSuch;
    bool bSaveAsShown     = rAsciiOpt.bSaveAsShown;
    bool bShowFormulas    = rAsciiOpt.bSaveFormulas;

@@ -2072,6 +2073,7 @@
                      pProtAttr->GetHideFormula() ) )
                eType = CELLTYPE_NONE;  // hide
        }
        bool bForceQuotes = false;
        bool bString;
        switch ( eType )
        {
@@ -2104,7 +2106,7 @@
                        else
                        {
                            ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, &m_aDocument);
                            bString = false;
                            bString = bForceQuotes = !bSaveNumberAsSuch;
                        }
                    }
                    else
@@ -2154,7 +2156,7 @@
                    else
                    {
                        ScCellFormat::GetInputString(*pCell, nFormat, aString, rFormatter, &m_aDocument);
                        bString = false;
                        bString = bForceQuotes = !bSaveNumberAsSuch;
                    }
                }
                break;
@@ -2197,10 +2199,10 @@
                        escapeTextSep<OUString, OUStringBuffer>(
                            nPos, OUString(cStrDelim), aUniString);

                        if ( bNeedQuotes )
                        if ( bNeedQuotes || bForceQuotes )
                            rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
                        write_uInt16s_FromOUString(rStream, aUniString);
                        if ( bNeedQuotes )
                        if ( bNeedQuotes || bForceQuotes )
                            rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
                    }
                    else
@@ -2235,10 +2237,10 @@
                                nPos, aStrDelimDecoded, aStrDec);

                            // write byte re-encoded
                            if ( bNeedQuotes )
                            if ( bNeedQuotes || bForceQuotes )
                                rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
                            rStream.WriteUnicodeOrByteText( aStrDec, eCharSet );
                            if ( bNeedQuotes )
                            if ( bNeedQuotes || bForceQuotes )
                                rStream.WriteUniOrByteChar( cStrDelim, eCharSet );
                        }
                        else
@@ -2254,11 +2256,11 @@
                                nPos, aStrDelimEncoded, aStrEnc);

                            // write byte encoded
                            if ( bNeedQuotes )
                            if ( bNeedQuotes || bForceQuotes )
                                rStream.WriteBytes(
                                    aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
                            rStream.WriteBytes(aStrEnc.getStr(), aStrEnc.getLength());
                            if ( bNeedQuotes )
                            if ( bNeedQuotes || bForceQuotes )
                                rStream.WriteBytes(
                                    aStrDelimEncoded.getStr(), aStrDelimEncoded.getLength());
                        }
diff --git a/sc/source/ui/inc/imoptdlg.hxx b/sc/source/ui/inc/imoptdlg.hxx
index 1f8b946..bac941c 100644
--- a/sc/source/ui/inc/imoptdlg.hxx
+++ b/sc/source/ui/inc/imoptdlg.hxx
@@ -31,23 +31,11 @@

        ScImportOptions( sal_Unicode nFieldSep, sal_Unicode nTextSep, rtl_TextEncoding nEnc )
            : nFieldSepCode(nFieldSep), nTextSepCode(nTextSep),
            bFixedWidth(false), bSaveAsShown(false), bQuoteAllText(false), bSaveFormulas(false),
            bRemoveSpace(false)
            bFixedWidth(false), bSaveAsShown(false), bQuoteAllText(false),
            bSaveNumberAsSuch(true), bSaveFormulas(false), bRemoveSpace(false)
        { SetTextEncoding( nEnc ); }

    ScImportOptions& operator=( const ScImportOptions& rCpy )
                        {
                            nFieldSepCode   = rCpy.nFieldSepCode;
                            nTextSepCode    = rCpy.nTextSepCode;
                            aStrFont        = rCpy.aStrFont;
                            eCharSet        = rCpy.eCharSet;
                            bFixedWidth     = rCpy.bFixedWidth;
                            bSaveAsShown    = rCpy.bSaveAsShown;
                            bQuoteAllText   = rCpy.bQuoteAllText;
                            bSaveFormulas   = rCpy.bSaveFormulas;
                            bRemoveSpace    = rCpy.bRemoveSpace;
                            return *this;
                        }
    ScImportOptions& operator=( const ScImportOptions& rCpy ) = default;

    OUString  BuildString() const;

@@ -60,6 +48,7 @@
    bool        bFixedWidth;
    bool        bSaveAsShown;
    bool        bQuoteAllText;
    bool        bSaveNumberAsSuch;
    bool        bSaveFormulas;
    bool        bRemoveSpace;
};