basic/source/classes/sbunoobj.cxx | 13 ++++++++++++ basic/source/inc/sbunoobj.hxx | 2 + include/basic/sbxvar.hxx | 2 - sc/qa/extras/macros-test.cxx | 17 +++++++++++++++ sc/qa/extras/testdocuments/vba-date.fods | 33 +++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-)
New commits: commit 2f37849bb1ac2fb336889e569c234d35b131372b Author: Mike Kaganski <[email protected]> AuthorDate: Fri Aug 29 16:27:09 2025 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Fri Aug 29 20:25:24 2025 +0200 tdf#81003: override GetDate in SbUnoObject to handle oleautomation::Date Without that, there is no code to deliver that value. The call to SbxValue::Get will eventually get to the SbUnoObject containing a css::bridge::oleautomation::Date in struct info; and there it will find that the object's SbxValue points to itself, at which point, it will error out from SbxValue::TheRealValue. Change-Id: Ia08fb2a7b1bcd7292faf5a5719a4fad0054a3f5e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190384 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 4dffb8fec5eb..92d691fce4ad 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -2863,6 +2863,19 @@ Any SbUnoObject::getUnoAny() return aRetAny; } +double SbUnoObject::GetDate() const +{ + // Handle structure info here. Without this, oleautomation data may be unable to convert + // to the wanted data type in the base method. + if (maStructInfo) + { + if (css::bridge::oleautomation::Date date; maTmpUnoObj >>= date) + return date.Value; + } + + return SbxObject::GetDate(); +} + // help method to create a Uno-Struct per CoreReflection static SbUnoObjectRef Impl_CreateUnoStruct( const OUString& aClassName ) { diff --git a/basic/source/inc/sbunoobj.hxx b/basic/source/inc/sbunoobj.hxx index 16e32af5a87e..db61f1036457 100644 --- a/basic/source/inc/sbunoobj.hxx +++ b/basic/source/inc/sbunoobj.hxx @@ -141,6 +141,8 @@ public: bool isNativeCOMObject() const { return bNativeCOMObject; } + + virtual double GetDate() const override; }; typedef tools::SvRef<SbUnoObject> SbUnoObjectRef; diff --git a/include/basic/sbxvar.hxx b/include/basic/sbxvar.hxx index daa961be1a19..a98e1f957dd4 100644 --- a/include/basic/sbxvar.hxx +++ b/include/basic/sbxvar.hxx @@ -147,7 +147,7 @@ public: float GetSingle() const { return Get(SbxSINGLE).nSingle; } double GetDouble() const { return Get(SbxDOUBLE).nDouble; } - double GetDate() const { return Get(SbxDATE).nDouble; } + virtual double GetDate() const { return Get(SbxDATE).nDouble; } bool GetBool() const { return Get(SbxBOOL).nUShort != 0; } SAL_DLLPRIVATE const OUString& GetCoreString() const; diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index e45b6d6e90e8..dd5a178a2ec7 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -1017,6 +1017,23 @@ CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf161948NaturalSortAPI) CPPUNIT_ASSERT_EQUAL(u"K10"_ustr, sCellContent); } +CPPUNIT_TEST_FIXTURE(ScMacrosTest, testTdf81003_DateCellToVbaUDF) +{ + // The document contains a formula in B1 with a user-defined spreadsheet function from a + // VBA-compatibility module, taking a date from A1. + // Without the fix, this failed with + // - Expression: xComponent.is() + // - loading failed: file://.../vba-date.fods + // because there was a failure evaluating the function at the loading time, and loading failed. + // The reason was that the variable representing the cell as a VBA-compatibility object, with a + // css::bridge::oleautomation::Date as its value, didn't convert to Basic's Date when passed to + // the user-defined function: + createScDoc("vba-date.fods"); + ScDocument* pDoc = getScDoc(); + // Check value of B1. The serial date for 2025-08-29 is 45898. + CPPUNIT_ASSERT_EQUAL(45898.0, pDoc->GetValue(1, 0, 0)); +} + ScMacrosTest::ScMacrosTest() : ScModelTestBase(u"/sc/qa/extras/testdocuments"_ustr) { diff --git a/sc/qa/extras/testdocuments/vba-date.fods b/sc/qa/extras/testdocuments/vba-date.fods new file mode 100644 index 000000000000..403670ba1a33 --- /dev/null +++ b/sc/qa/extras/testdocuments/vba-date.fods @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.spreadsheet"> + <office:scripts> + <office:script script:language="ooo:Basic"> + <ooo:libraries> + <ooo:library-embedded ooo:name="Standard"> + <ooo:module ooo:name="Module1"> + <ooo:source-code> +Option VBASupport 1 + +function valueOfDate(d as date) as double + valueOfDate = CDbl(d) +end function + </ooo:source-code> + </ooo:module> + </ooo:library-embedded> + </ooo:libraries> + </office:script> + </office:scripts> + <office:body> + <office:spreadsheet> + <table:table table:name="Sheet1"> + <table:table-column/> + <table:table-column/> + <table:table-row> + <table:table-cell office:value-type="date" office:date-value="2025-08-29"/> + <table:table-cell table:formula="of:=VALUEOFDATE([.A1])" office:value-type="float"/> + </table:table-row> + </table:table> + </office:spreadsheet> + </office:body> +</office:document> \ No newline at end of file
