Change in core[libreoffice-4-0]: resolved fdo#60087 corrected .xlsx export of functions

Eike Rathke (via Code Review) gerrit at gerrit.libreoffice.org
Wed Jan 30 13:47:39 PST 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/1929

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/29/1929/1

resolved fdo#60087 corrected .xlsx export of functions

Change-Id: I6c7ba47dde88a73d035b1db5f7f4cede78b262db
(cherry picked from commit 0c7a1b6e10011930b703897073b8d41e94f7d827)
---
M sc/source/filter/excel/xeformula.cxx
M sc/source/filter/oox/formulabase.cxx
2 files changed, 71 insertions(+), 41 deletions(-)



diff --git a/sc/source/filter/excel/xeformula.cxx b/sc/source/filter/excel/xeformula.cxx
index 603ee9d..893321b 100644
--- a/sc/source/filter/excel/xeformula.cxx
+++ b/sc/source/filter/excel/xeformula.cxx
@@ -1406,20 +1406,24 @@
 
 void XclExpFmlaCompImpl::PrepareFunction( XclExpFuncData& rFuncData )
 {
-    switch( rFuncData.GetOpCode() )
+    // For OOXML these are not rewritten anymore.
+    if (GetOutput() != EXC_OUTPUT_XML_2007)
     {
-        case ocCosecant:                // simulate CSC(x) by (1/SIN(x))
-        case ocSecant:                  // simulate SEC(x) by (1/COS(x))
-        case ocCot:                     // simulate COT(x) by (1/TAN(x))
-        case ocCosecantHyp:             // simulate CSCH(x) by (1/SINH(x))
-        case ocSecantHyp:               // simulate SECH(x) by (1/COSH(x))
-        case ocCotHyp:                  // simulate COTH(x) by (1/TANH(x))
-            AppendIntToken( 1 );
-        break;
-        case ocArcCot:                  // simulate ACOT(x) by (PI/2-ATAN(x))
-            AppendNumToken( F_PI2 );
-        break;
-        default:;
+        switch( rFuncData.GetOpCode() )
+        {
+            case ocCosecant:                // simulate CSC(x) by (1/SIN(x))
+            case ocSecant:                  // simulate SEC(x) by (1/COS(x))
+            case ocCot:                     // simulate COT(x) by (1/TAN(x))
+            case ocCosecantHyp:             // simulate CSCH(x) by (1/SINH(x))
+            case ocSecantHyp:               // simulate SECH(x) by (1/COSH(x))
+            case ocCotHyp:                  // simulate COTH(x) by (1/TANH(x))
+                AppendIntToken( 1 );
+                break;
+            case ocArcCot:                  // simulate ACOT(x) by (PI/2-ATAN(x))
+                AppendNumToken( F_PI2 );
+                break;
+            default:;
+        }
     }
 }
 
@@ -1468,12 +1472,20 @@
             case ocCosecantHyp:             // simulate CSCH(x) by (1/SINH(x))
             case ocSecantHyp:               // simulate SECH(x) by (1/COSH(x))
             case ocCotHyp:                  // simulate COTH(x) by (1/TANH(x))
-                AppendBinaryOperatorToken( EXC_TOKID_DIV, true );
-                AppendParenToken();
+                // For OOXML not rewritten anymore.
+                if (GetOutput() != EXC_OUTPUT_XML_2007)
+                {
+                    AppendBinaryOperatorToken( EXC_TOKID_DIV, true );
+                    AppendParenToken();
+                }
             break;
             case ocArcCot:                  // simulate ACOT(x) by (PI/2-ATAN(x))
-                AppendBinaryOperatorToken( EXC_TOKID_SUB, true );
-                AppendParenToken();
+                // For OOXML not rewritten anymore.
+                if (GetOutput() != EXC_OUTPUT_XML_2007)
+                {
+                    AppendBinaryOperatorToken( EXC_TOKID_SUB, true );
+                    AppendParenToken();
+                }
             break;
 
             default:;
diff --git a/sc/source/filter/oox/formulabase.cxx b/sc/source/filter/oox/formulabase.cxx
index 929e6b0..ec3c411 100644
--- a/sc/source/filter/oox/formulabase.cxx
+++ b/sc/source/filter/oox/formulabase.cxx
@@ -215,6 +215,8 @@
 const sal_uInt16 FUNCFLAG_MACROCALL_NEW     = FUNCFLAG_MACROCALL | FUNCFLAG_MACROCALL_FN;   /** New Excel functions not
                                                             defined in OOXML, _xlfn. prefix in all formats. OOXML name
                                                             must exist. */
+const sal_uInt16 FUNCFLAG_BIFFIMPORTONLY    = 0x0800;   /// Only used in BIFF binary import filter.
+const sal_uInt16 FUNCFLAG_BIFFEXPORTONLY    = 0x1000;   /// Only used in BIFF binary export filter.
 
 /// Converts a function library index (value of enum FunctionLibraryType) to function flags.
 #define FUNCLIB_TO_FUNCFLAGS( funclib_index ) static_cast< sal_uInt16 >( static_cast< sal_uInt8 >( funclib_index ) << 12 )
@@ -235,14 +237,21 @@
     FunctionParamInfo   mpParamInfos[ FUNCINFO_PARAMINFOCOUNT ]; /// Information about all parameters.
     sal_uInt16          mnFlags;            /// Additional flags.
 
-    inline bool         isSupported( bool bImportFilter ) const;
+    inline bool         isSupported( bool bImportFilter, FilterType eFilter ) const;
 };
 
-inline bool FunctionData::isSupported( bool bImportFilter ) const
+inline bool FunctionData::isSupported( bool bImportFilter, FilterType eFilter ) const
 {
-    /*  For import filters: the FUNCFLAG_EXPORTONLY flag must not be set,
-        for export filters: the FUNCFLAG_IMPORTONLY flag must not be set. */
-    return !getFlag( mnFlags, bImportFilter ? FUNCFLAG_EXPORTONLY : FUNCFLAG_IMPORTONLY );
+    /*  For import filters: the FUNCFLAG_EXPORTONLY and FUNCFLAG_BIFFEXPORTONLY flag must not be set.
+        For OOXML import:   the FUNCFLAG_BIFFIMPORTONLY flag must not be set.
+        For export filters: the FUNCFLAG_IMPORTONLY and FUNCFLAG_BIFFIMPORTONLY flag must not be set.
+        For OOXML export:   the FUNCFLAG_BIFFEXPORTONLY flag must not be set. */
+    bool bSupported = !getFlag( mnFlags, static_cast<sal_uInt16>(bImportFilter ?
+                (FUNCFLAG_EXPORTONLY | FUNCFLAG_BIFFEXPORTONLY) :
+                (FUNCFLAG_IMPORTONLY | FUNCFLAG_BIFFIMPORTONLY)));
+    if (bSupported && eFilter == FILTER_OOXML)
+        bSupported = !getFlag( mnFlags, bImportFilter ? FUNCFLAG_BIFFIMPORTONLY : FUNCFLAG_BIFFEXPORTONLY );
+    return bSupported;
 }
 
 const sal_uInt16 NOID = SAL_MAX_UINT16;     /// No BIFF function identifier available.
@@ -289,13 +298,13 @@
     { "DOLLAR",                 "DOLLAR",               13,     13,     1,  2,  V, { VR }, 0 },
     { "FIXED",                  "FIXED",                14,     14,     1,  2,  V, { VR, VR, C }, 0 },
     { "SIN",                    "SIN",                  15,     15,     1,  1,  V, { VR }, 0 },
-    { "CSC",                    "SIN",                  15,     15,     1,  1,  V, { VR }, FUNCFLAG_EXPORTONLY },
+    { "CSC",                    "SIN",                  15,     15,     1,  1,  V, { VR }, FUNCFLAG_BIFFEXPORTONLY },
     { "COS",                    "COS",                  16,     16,     1,  1,  V, { VR }, 0 },
-    { "SEC",                    "COS",                  16,     16,     1,  1,  V, { VR }, FUNCFLAG_EXPORTONLY },
+    { "SEC",                    "COS",                  16,     16,     1,  1,  V, { VR }, FUNCFLAG_BIFFEXPORTONLY },
     { "TAN",                    "TAN",                  17,     17,     1,  1,  V, { VR }, 0 },
-    { "COT",                    "TAN",                  17,     17,     1,  1,  V, { VR }, FUNCFLAG_EXPORTONLY },
+    { "COT",                    "TAN",                  17,     17,     1,  1,  V, { VR }, FUNCFLAG_BIFFEXPORTONLY },
     { "ATAN",                   "ATAN",                 18,     18,     1,  1,  V, { VR }, 0 },
-    { "ACOT",                   "ATAN",                 18,     18,     1,  1,  V, { VR }, FUNCFLAG_EXPORTONLY },
+    { "ACOT",                   "ATAN",                 18,     18,     1,  1,  V, { VR }, FUNCFLAG_BIFFEXPORTONLY },
     { "PI",                     "PI",                   19,     19,     0,  0,  V, {}, 0 },
     { "SQRT",                   "SQRT",                 20,     20,     1,  1,  V, { VR }, 0 },
     { "EXP",                    "EXP",                  21,     21,     1,  1,  V, { VR }, 0 },
@@ -451,15 +460,15 @@
     { "MEDIAN",                 "MEDIAN",               227,    227,    1,  MX, V, { RX }, 0 },
     { "SUMPRODUCT",             "SUMPRODUCT",           228,    228,    1,  MX, V, { VA }, 0 },
     { "SINH",                   "SINH",                 229,    229,    1,  1,  V, { VR }, 0 },
-    { "CSCH",                   "SINH",                 229,    229,    1,  1,  V, { VR }, FUNCFLAG_EXPORTONLY },
+    { "CSCH",                   "SINH",                 229,    229,    1,  1,  V, { VR }, FUNCFLAG_BIFFEXPORTONLY },
     { "COSH",                   "COSH",                 230,    230,    1,  1,  V, { VR }, 0 },
-    { "SECH",                   "COSH",                 230,    230,    1,  1,  V, { VR }, FUNCFLAG_EXPORTONLY },
+    { "SECH",                   "COSH",                 230,    230,    1,  1,  V, { VR }, FUNCFLAG_BIFFEXPORTONLY },
     { "TANH",                   "TANH",                 231,    231,    1,  1,  V, { VR }, 0 },
-    { "COTH",                   "TANH",                 231,    231,    1,  1,  V, { VR }, FUNCFLAG_EXPORTONLY },
+    { "COTH",                   "TANH",                 231,    231,    1,  1,  V, { VR }, FUNCFLAG_BIFFEXPORTONLY },
     { "ASINH",                  "ASINH",                232,    232,    1,  1,  V, { VR }, 0 },
     { "ACOSH",                  "ACOSH",                233,    233,    1,  1,  V, { VR }, 0 },
     { "ATANH",                  "ATANH",                234,    234,    1,  1,  V, { VR }, 0 },
-    { "ACOTH",                  "ATANH",                234,    234,    1,  1,  V, { VR }, FUNCFLAG_EXPORTONLY },
+    { "ACOTH",                  "ATANH",                234,    234,    1,  1,  V, { VR }, FUNCFLAG_BIFFEXPORTONLY },
     { "DGET",                   "DGET",                 235,    235,    3,  3,  V, { RO, RR }, 0 },
     { "INFO",                   "INFO",                 244,    244,    1,  1,  V, { VR }, FUNCFLAG_VOLATILE },
 
@@ -728,6 +737,12 @@
 /* FIXME: BIFF12 function identifer available? Where to obtain? */
 static const FunctionData saFuncTable2013[] =
 {
+    { "ACOT",                   "ACOT",                 NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
+    { "ACOTH",                  "ACOTH",                NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
+    { "COT",                    "COT",                  NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
+    { "COTH",                   "COTH",                 NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
+    { "CSC",                    "CSC",                  NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
+    { "CSCH",                   "CSCH",                 NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
     { "IFNA",                   "IFNA",                 NOID,   NOID,   2,  2,  V, { VO, RO }, FUNCFLAG_MACROCALL_NEW },
     { "IMCOSH",                 "IMCOSH",               NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW | FUNCFLAG_EXTERNAL },
     { "IMCOT",                  "IMCOT",                NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW | FUNCFLAG_EXTERNAL },
@@ -737,6 +752,8 @@
     { "IMSECH",                 "IMSECH",               NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW | FUNCFLAG_EXTERNAL },
     { "IMSINH",                 "IMSINH",               NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW | FUNCFLAG_EXTERNAL },
     { "IMTAN",                  "IMTAN",                NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW | FUNCFLAG_EXTERNAL },
+    { "SEC",                    "SEC",                  NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW },
+    { "SECH",                   "SECH",                 NOID,   NOID,   1,  1,  V, { VR }, FUNCFLAG_MACROCALL_NEW }
 };
 
 /** Functions defined by OpenFormula, but not supported by Calc or by Excel. */
@@ -849,7 +866,7 @@
     /** Initializes the members from the passed function data list. */
     void                initFuncs(
                             const FunctionData* pBeg, const FunctionData* pEnd,
-                            sal_uInt8 nMaxParam, bool bImportFilter );
+                            sal_uInt8 nMaxParam, bool bImportFilter, FilterType eFilter );
 };
 
 // ----------------------------------------------------------------------------
@@ -884,18 +901,18 @@
         tables from later BIFF versions may overwrite single functions from
         earlier tables. */
     if( eBiff >= BIFF2 )
-        initFuncs( saFuncTableBiff2, STATIC_ARRAY_END( saFuncTableBiff2 ), nMaxParam, bImportFilter );
+        initFuncs( saFuncTableBiff2, STATIC_ARRAY_END( saFuncTableBiff2 ), nMaxParam, bImportFilter, eFilter );
     if( eBiff >= BIFF3 )
-        initFuncs( saFuncTableBiff3, STATIC_ARRAY_END( saFuncTableBiff3 ), nMaxParam, bImportFilter );
+        initFuncs( saFuncTableBiff3, STATIC_ARRAY_END( saFuncTableBiff3 ), nMaxParam, bImportFilter, eFilter );
     if( eBiff >= BIFF4 )
-        initFuncs( saFuncTableBiff4, STATIC_ARRAY_END( saFuncTableBiff4 ), nMaxParam, bImportFilter );
+        initFuncs( saFuncTableBiff4, STATIC_ARRAY_END( saFuncTableBiff4 ), nMaxParam, bImportFilter, eFilter );
     if( eBiff >= BIFF5 )
-        initFuncs( saFuncTableBiff5, STATIC_ARRAY_END( saFuncTableBiff5 ), nMaxParam, bImportFilter );
+        initFuncs( saFuncTableBiff5, STATIC_ARRAY_END( saFuncTableBiff5 ), nMaxParam, bImportFilter, eFilter );
     if( eBiff >= BIFF8 )
-        initFuncs( saFuncTableBiff8, STATIC_ARRAY_END( saFuncTableBiff8 ), nMaxParam, bImportFilter );
-    initFuncs( saFuncTableOox, STATIC_ARRAY_END( saFuncTableOox ), nMaxParam, bImportFilter );
-    initFuncs( saFuncTable2013, STATIC_ARRAY_END( saFuncTable2013 ), nMaxParam, bImportFilter );
-    initFuncs( saFuncTableOdf, STATIC_ARRAY_END( saFuncTableOdf ), nMaxParam, bImportFilter );
+        initFuncs( saFuncTableBiff8, STATIC_ARRAY_END( saFuncTableBiff8 ), nMaxParam, bImportFilter, eFilter );
+    initFuncs( saFuncTableOox, STATIC_ARRAY_END( saFuncTableOox ), nMaxParam, bImportFilter, eFilter );
+    initFuncs( saFuncTable2013, STATIC_ARRAY_END( saFuncTable2013 ), nMaxParam, bImportFilter, eFilter );
+    initFuncs( saFuncTableOdf, STATIC_ARRAY_END( saFuncTableOdf ), nMaxParam, bImportFilter, eFilter );
 }
 
 void FunctionProviderImpl::initFunc( const FunctionData& rFuncData, sal_uInt8 nMaxParam )
@@ -954,10 +971,11 @@
         maMacroFuncs[ xFuncInfo->maBiffMacroName ] = xFuncInfo;
 }
 
-void FunctionProviderImpl::initFuncs( const FunctionData* pBeg, const FunctionData* pEnd, sal_uInt8 nMaxParam, bool bImportFilter )
+void FunctionProviderImpl::initFuncs( const FunctionData* pBeg, const FunctionData* pEnd, sal_uInt8 nMaxParam,
+        bool bImportFilter, FilterType eFilter )
 {
     for( const FunctionData* pIt = pBeg; pIt != pEnd; ++pIt )
-        if( pIt->isSupported( bImportFilter ) )
+        if( pIt->isSupported( bImportFilter, eFilter ) )
             initFunc( *pIt, nMaxParam );
 }
 

-- 
To view, visit https://gerrit.libreoffice.org/1929
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c7ba47dde88a73d035b1db5f7f4cede78b262db
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Eike Rathke <erack at redhat.com>


More information about the LibreOffice mailing list