sc/qa/extras/vba-macro-test.cxx | 29 +++++++++++++++++++++++++++++ sc/source/ui/vba/vbarange.cxx | 13 +++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-)
New commits: commit ad76806524aae8c07481b0e4133c24f20c4fc687 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Jul 4 17:07:20 2025 +0500 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Jul 4 21:10:11 2025 +0200 tdf#167378: handle css::bridge::oleautomation::Date in CellValueSetter Commit 63e7a70ad1a6a8ec4190ab510f683d2fc9dea417 (tdf#164811: swap the "if IsCompatibility()" branches to match other places, 2025-01-23) made dates be passed as oleautomation::Date in VBA compatibility mode. These values were handled in CellValueGetter::processValue; but CellValueSetter::processValue lacked similar handling. This change fixes the omission. Change-Id: I8e97792f2014f16bf9a7520fcb6c46848d9fa938 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187393 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit e90e4b81b049a9d7c36de8d7f0371e2da7c60c01) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187408 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx index 4dc1f0fe93c4..2b927c1d7e0b 100644 --- a/sc/qa/extras/vba-macro-test.cxx +++ b/sc/qa/extras/vba-macro-test.cxx @@ -838,6 +838,35 @@ CPPUNIT_TEST_FIXTURE(VBAMacroTest, testNonAsciiMacroIRI) CPPUNIT_ASSERT_EQUAL(u"zab"_ustr, rDoc.GetString(ScAddress(0, 2, 0))); } +CPPUNIT_TEST_FIXTURE(VBAMacroTest, testTdf167378) +{ + loadFromURL(u"private:factory/scalc"_ustr); + + css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, uno::UNO_QUERY_THROW); + auto xLibs = xDocScr->getBasicLibraries(); + auto xLibrary = xLibs->createLibrary(u"TestLibrary"_ustr); + + // Execute a macro that assigns a Date variable to a cell value + OUString sMacro = uR"vba( + Option VBASupport 1 + Sub TestSetDate + Dim d As Date + d = #2025-07-04# ' numeric value 45842 + Cells(1, 1).Value = d + End Sub + )vba"_ustr; + xLibrary->insertByName(u"TestModule"_ustr, uno::Any(sMacro)); + + executeMacro(u"vnd.sun.Star.script:TestLibrary.TestModule.TestSetDate?language=Basic&location=" + "document"_ustr); + + SfxObjectShell* pObjectShell = SfxObjectShell::GetShellFromComponent(mxComponent); + CPPUNIT_ASSERT(pObjectShell); + ScDocument& rDoc = static_cast<ScDocShell*>(pObjectShell)->GetDocument(); + // Without a fix, this was 0, because oleautomation::Date wasn't handled + CPPUNIT_ASSERT_EQUAL(45842.0, rDoc.GetValue(0, 0, 0)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index e0562dc7f0f2..f766e0b1c961 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -705,7 +705,7 @@ bool CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell ) { - bool isExtracted = false; + bool isExtracted = true; switch ( aValue.getValueTypeClass() ) { case uno::TypeClass_BOOLEAN: @@ -756,7 +756,14 @@ CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< tab default: { double nDouble = 0.0; - if ( aValue >>= nDouble ) + if (!(aValue >>= nDouble)) + { + if (css::bridge::oleautomation::Date date; aValue >>= date) + nDouble = date.Value; + else + isExtracted = false; + } + if (isExtracted) { uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW ); NumFormatHelper cellFormat( xRange ); @@ -767,8 +774,6 @@ CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< tab cellFormat.setNumberFormat(u"General"_ustr); xCell->setValue( nDouble ); } - else - isExtracted = false; break; } }