diff options
author | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2021-03-17 10:33:05 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2021-04-12 16:45:08 +0200 |
commit | 08cfec4a6e27ebc078345c57a7a74b2dffeb5b41 (patch) | |
tree | ad5a1f1645e3fc63b2912e76653d1b3743313152 | |
parent | tdf#141623 Qt5+cairo init surface with widget size (diff) | |
download | core-08cfec4a6e27ebc078345c57a7a74b2dffeb5b41.tar.gz core-08cfec4a6e27ebc078345c57a7a74b2dffeb5b41.zip |
tdf#138646 - consider the document's address convention
When accessing a named range using getCellRangeByName, consider the
document's address convention. Otherwise, an exception is raised, when
the formula syntax is EXCEL R1C1 or EXCEL A1.
Change-Id: I5df2546f1c3fd00ff30cb057dcf47f6bb01d501d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112602
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113984
-rw-r--r-- | sc/qa/extras/macros-test.cxx | 48 | ||||
-rw-r--r-- | sc/qa/extras/testdocuments/tdf138646.ods | bin | 0 -> 13577 bytes | |||
-rw-r--r-- | sc/source/core/tool/rangeutl.cxx | 4 |
3 files changed, 51 insertions, 1 deletions
diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index 2970a587ecc5..fce7684e53a4 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -52,6 +52,7 @@ public: void testTdf128218(); void testTdf71271(); void testTdf43003(); + void testTdf138646(); CPPUNIT_TEST_SUITE(ScMacrosTest); CPPUNIT_TEST(testStarBasic); @@ -70,6 +71,7 @@ public: CPPUNIT_TEST(testTdf128218); CPPUNIT_TEST(testTdf71271); CPPUNIT_TEST(testTdf43003); + CPPUNIT_TEST(testTdf138646); CPPUNIT_TEST_SUITE_END(); }; @@ -864,6 +866,52 @@ void ScMacrosTest::testTdf43003() xCloseable->close(true); } +void ScMacrosTest::testTdf138646() +{ + OUString aFileName; + createFileURL(u"tdf138646.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + CPPUNIT_ASSERT_MESSAGE("Failed to load the doc", xComponent.is()); + + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Without the fix in place, changing the grammar from GRAM_NATIVE to either GRAM_NATIVE_XL_A1 + // or GRAM_NATIVE_XL_R1C1 would cause a Basic exception/error in the following script. + pDocSh->GetDocument().SetGrammar(formula::FormulaGrammar::Grammar::GRAM_NATIVE_XL_R1C1); + + const std::vector<std::pair<OUString, OUString>> aTests({ + { "GlobalNamedCell", "GlobalNamedCell" }, + { "GlobalNamedCellSheet", "GlobalNamedCell" }, + { "LocalNamedCell", "LocalNamedCell" }, + { "LocalNamedCellAccessError", "Exception" } + }); + + { + Any aRet; + Sequence<sal_Int16> aOutParamIndex; + Sequence<Any> aOutParam; + Sequence<uno::Any> aParams; + + for (auto& [sTestName, sExpected] : aTests) + { + SfxObjectShell::CallXScript(xComponent, + "vnd.sun.Star.script:Standard.Module1." + sTestName + + "?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue); + } + } + + pDocSh->DoClose(); +} + ScMacrosTest::ScMacrosTest() : UnoApiTest("/sc/qa/extras/testdocuments") { diff --git a/sc/qa/extras/testdocuments/tdf138646.ods b/sc/qa/extras/testdocuments/tdf138646.ods Binary files differnew file mode 100644 index 000000000000..9faa95a54334 --- /dev/null +++ b/sc/qa/extras/testdocuments/tdf138646.ods diff --git a/sc/source/core/tool/rangeutl.cxx b/sc/source/core/tool/rangeutl.cxx index dfcdb30875ee..c8c8978ff348 100644 --- a/sc/source/core/tool/rangeutl.cxx +++ b/sc/source/core/tool/rangeutl.cxx @@ -276,7 +276,9 @@ bool ScRangeUtil::MakeRangeFromName ( ScRefAddress aStartPos; ScRefAddress aEndPos; - pData->GetSymbol( aStrArea ); + // tdf#138646 - consider the current grammar and address convention of the document + pData->GetSymbol(aStrArea, + FormulaGrammar::mergeToGrammar(rDoc.GetGrammar(), rDetails.eConv)); if ( IsAbsArea( aStrArea, rDoc, nTable, nullptr, &aStartPos, &aEndPos, rDetails ) ) |