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 <mike.kaganski@collabora.com>
This commit is contained in:
Hannah Meeks
2022-06-30 03:36:15 +02:00
committed by Mike Kaganski
parent 7ca3eca668
commit cb41db23a0
4 changed files with 37 additions and 12 deletions
+1
View File
@@ -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;
Binary file not shown.
+31 -12
View File
@@ -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()
{
+5
View File
@@ -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;