tdf#71271 - add code names regardless of VBA compatibility mode
During the save process of a document, save code names of calc sheets
regardless of the VBA compatibility mode. Loading of documents with
changed code names already work without checking the VBA mode.
Change-Id: Ieb5297ac3b671fd39a200c34409ba2ffdad4e1f7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103589
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx
index 5e6aa3d..cf7d46a 100644
--- a/sc/qa/extras/macros-test.cxx
+++ b/sc/qa/extras/macros-test.cxx
@@ -19,6 +19,8 @@
#include <attrib.hxx>
#include <scitems.hxx>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/script/XLibraryContainerPassword.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
@@ -48,6 +50,7 @@ public:
void testTdf131296_legacy();
void testTdf131296_new();
void testTdf128218();
void testTdf71271();
CPPUNIT_TEST_SUITE(ScMacrosTest);
CPPUNIT_TEST(testStarBasic);
@@ -64,6 +67,7 @@ public:
CPPUNIT_TEST(testTdf131296_legacy);
CPPUNIT_TEST(testTdf131296_new);
CPPUNIT_TEST(testTdf128218);
CPPUNIT_TEST(testTdf71271);
CPPUNIT_TEST_SUITE_END();
};
@@ -803,6 +807,37 @@ void ScMacrosTest::testTdf128218()
xCloseable->close(true);
}
void ScMacrosTest::testTdf71271()
{
uno::Reference<lang::XComponent> xComponent = loadFromDesktop("private:factory/scalc");
CPPUNIT_ASSERT(xComponent);
{
uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, uno::UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW);
uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xProps(xSheet, uno::UNO_QUERY_THROW);
xProps->setPropertyValue("CodeName", uno::Any(OUString("NewCodeName")));
}
saveAndReload(xComponent, "");
CPPUNIT_ASSERT(xComponent);
{
uno::Reference<sheet::XSpreadsheetDocument> xDoc(xComponent, uno::UNO_QUERY_THROW);
uno::Reference<container::XIndexAccess> xIndex(xDoc->getSheets(), uno::UNO_QUERY_THROW);
uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW);
OUString sCodeName;
uno::Reference<beans::XPropertySet> xProps(xSheet, uno::UNO_QUERY_THROW);
// Without the fix in place the codename would not have been saved
xProps->getPropertyValue("CodeName") >>= sCodeName;
CPPUNIT_ASSERT_EQUAL(OUString("NewCodeName"), sCodeName);
}
css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW);
xCloseable->close(true);
}
ScMacrosTest::ScMacrosTest()
: UnoApiTest("/sc/qa/extras/testdocuments")
{
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 41896b2..0acd2d6 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -5157,11 +5157,13 @@ void ScXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>&
bool bVBACompat = false;
uno::Reference <container::XNameAccess> xCodeNameAccess;
OSL_ENSURE( pDoc, "ScXMLExport::GetConfigurationSettings - no ScDocument!" );
if( pDoc && pDoc->IsInVBAMode() )
// tdf#71271 - add code names regardless of VBA compatibility mode
if (pDoc)
{
// VBA compatibility mode
bVBACompat = true;
++nPropsToAdd;
if (bVBACompat = pDoc->IsInVBAMode(); bVBACompat)
++nPropsToAdd;
// code names
xCodeNameAccess = new XMLCodeNameProvider( pDoc );
if( xCodeNameAccess->hasElements() )