oovbaapi/ooo/vba/excel/XRange.idl  |    1 
 sc/qa/extras/testdocuments/vba.xls |binary
 sc/source/ui/vba/vbarange.cxx      |   41 +++++++++++++++++++++++++++----------
 sc/source/ui/vba/vbarange.hxx      |    5 ++++
 4 files changed, 36 insertions(+), 11 deletions(-)

New commits:
commit cb41db23a044e6e6337bad642aad2c49174aa068
Author:     Hannah Meeks <[email protected]>
AuthorDate: Fri Apr 29 15:25:51 2022 +0100
Commit:     Mike Kaganski <[email protected]>
CommitDate: Thu Jun 30 03:36:15 2022 +0200

    tdf#99514 - implement Value2 for compatibility
    
    Value2 ignores date formatting in a way that Value does not.
    Extended vba.xls to test this too.
    
    Change-Id: Id75a3dafae2166221731847b7c81e93e8ad835fe
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133645
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/oovbaapi/ooo/vba/excel/XRange.idl 
b/oovbaapi/ooo/vba/excel/XRange.idl
index e640f39eb33e..9dcc41f95166 100644
--- a/oovbaapi/ooo/vba/excel/XRange.idl
+++ b/oovbaapi/ooo/vba/excel/XRange.idl
@@ -43,6 +43,7 @@ interface XRange
     //interface ::ooo::vba::XHelperInterface;
 
     [attribute] any Value;
+    [attribute] any Value2;
     [attribute] any Formula;
     [attribute] any FormulaArray;
     [attribute] any FormulaR1C1;
diff --git a/sc/qa/extras/testdocuments/vba.xls 
b/sc/qa/extras/testdocuments/vba.xls
index 399b1ec20675..22bee379caf1 100644
Binary files a/sc/qa/extras/testdocuments/vba.xls and 
b/sc/qa/extras/testdocuments/vba.xls differ
diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx
index d94bd7b04a35..99bcce81ba00 100644
--- a/sc/source/ui/vba/vbarange.cxx
+++ b/sc/source/ui/vba/vbarange.cxx
@@ -781,13 +781,13 @@ namespace {
 class CellValueGetter : public ValueGetter
 {
 protected:
+    RangeValueType meValueType;
     uno::Any maValue;
 public:
-    CellValueGetter() {}
+    CellValueGetter(RangeValueType eValueType) { meValueType = eValueType; }
     virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< 
table::XCell >& xCell ) override;
     virtual void processValue( const uno::Any& aValue ) override;
     const uno::Any& getValue() const override { return maValue; }
-
 };
 
 }
@@ -800,10 +800,10 @@ CellValueGetter::processValue(  const uno::Any& aValue )
 void CellValueGetter::visitNode( sal_Int32 /*x*/, sal_Int32 /*y*/, const 
uno::Reference< table::XCell >& xCell )
 {
     uno::Any aValue;
-    table::CellContentType eType = xCell->getType();
-    if( eType == table::CellContentType_VALUE || eType == 
table::CellContentType_FORMULA )
+    table::CellContentType eCellContentType = xCell->getType();
+    if( eCellContentType == table::CellContentType_VALUE || eCellContentType 
== table::CellContentType_FORMULA )
     {
-        if ( eType == table::CellContentType_FORMULA )
+        if ( eCellContentType == table::CellContentType_FORMULA )
         {
 
             OUString sFormula = xCell->getFormula();
@@ -834,13 +834,13 @@ void CellValueGetter::visitNode( sal_Int32 /*x*/, 
sal_Int32 /*y*/, const uno::Re
             NumFormatHelper cellFormat( xRange );
             if ( cellFormat.isBooleanType() )
                 aValue <<= ( xCell->getValue() != 0.0 );
-            else if ( cellFormat.isDateType() )
+            else if ( cellFormat.isDateType() && meValueType == 
RangeValueType::value)
                 aValue <<= bridge::oleautomation::Date( xCell->getValue() );
             else
                 aValue <<= xCell->getValue();
         }
     }
-    if( eType == table::CellContentType_TEXT )
+    if( eCellContentType == table::CellContentType_TEXT )
     {
         uno::Reference< text::XTextRange > xTextRange(xCell, 
::uno::UNO_QUERY_THROW);
         aValue <<= xTextRange->getString();
@@ -908,7 +908,8 @@ private:
     ScDocument& m_rDoc;
     formula::FormulaGrammar::Grammar m_eGrammar;
 public:
-    CellFormulaValueGetter(ScDocument& rDoc, formula::FormulaGrammar::Grammar 
eGram ) :  m_rDoc( rDoc ), m_eGrammar( eGram ) {}
+    CellFormulaValueGetter(ScDocument& rDoc, formula::FormulaGrammar::Grammar 
eGram ) :
+         CellValueGetter( RangeValueType::value ), m_rDoc( rDoc ), m_eGrammar( 
eGram ) {}
     virtual void visitNode( sal_Int32 /*x*/, sal_Int32 /*y*/, const 
uno::Reference< table::XCell >& xCell ) override
     {
         uno::Any aValue;
@@ -1524,8 +1525,7 @@ ScVbaRange::getValue( ValueGetter& valueGetter)
     return uno::Any( script::ArrayWrapper( false, arrayGetter.getValue() ) );
 }
 
-uno::Any SAL_CALL
-ScVbaRange::getValue()
+css::uno::Any ScVbaRange::DoGetValue( RangeValueType eValueType )
 {
     // #TODO code within the test below "if ( m_Areas... " can be removed
     // Test is performed only because m_xRange is NOT set to be
@@ -1537,11 +1537,23 @@ ScVbaRange::getValue()
         return xRange->getValue();
     }
 
-    CellValueGetter valueGetter;
+    CellValueGetter valueGetter( eValueType );
     return getValue( valueGetter );
+}
 
+uno::Any SAL_CALL
+ScVbaRange::getValue()
+{
+    return DoGetValue( RangeValueType::value );
 }
 
+uno::Any SAL_CALL
+ScVbaRange::getValue2()
+{
+    return DoGetValue( RangeValueType::value2 );
+}
+
+
 void
 ScVbaRange::setValue( const uno::Any& aValue, ValueSetter& valueSetter )
 {
@@ -1594,6 +1606,13 @@ ScVbaRange::setValue( const uno::Any  &aValue )
     setValue( aValue, valueSetter );
 }
 
+void SAL_CALL
+ScVbaRange::setValue2( const uno::Any  &aValue )
+{
+    return setValue( aValue );
+}
+
+
 void SAL_CALL
 ScVbaRange::Clear()
 {
diff --git a/sc/source/ui/vba/vbarange.hxx b/sc/source/ui/vba/vbarange.hxx
index 118ad044cf47..7a2d186f5edb 100644
--- a/sc/source/ui/vba/vbarange.hxx
+++ b/sc/source/ui/vba/vbarange.hxx
@@ -69,6 +69,8 @@ public:
 
 typedef ScVbaFormat< ov::excel::XRange > ScVbaRange_BASE;
 
+enum class RangeValueType { value, value2 };
+
 class ScVbaRange : public ScVbaRange_BASE
 {
     css::uno::Reference< ov::XCollection > m_Areas;
@@ -95,6 +97,7 @@ class ScVbaRange : public ScVbaRange_BASE
 
     /// @throws css::uno::RuntimeException
     css::uno::Any getValue( ValueGetter& rValueGetter );
+    css::uno::Any DoGetValue( RangeValueType eValueType );
     /// @throws css::uno::RuntimeException
     void setValue( const css::uno::Any& aValue, ValueSetter& setter );
 
@@ -174,7 +177,9 @@ public:
 
     // Attributes
     virtual css::uno::Any SAL_CALL getValue() override;
+    virtual css::uno::Any SAL_CALL getValue2() override;
     virtual void   SAL_CALL setValue( const css::uno::Any& aValue ) override;
+    virtual void   SAL_CALL setValue2( const css::uno::Any& aValue2 ) override;
     virtual css::uno::Any SAL_CALL getFormula() override;
     virtual void   SAL_CALL setFormula( const css::uno::Any& rFormula ) 
override;
     virtual css::uno::Any SAL_CALL getFormulaArray() override;

Reply via email to