diff options
author | Rafael Lima <rafael.palma.lima@gmail.com> | 2024-03-25 15:24:30 +0100 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-04-01 05:56:10 +0200 |
commit | 350c590620226c4d5b94aa01d3853e15af3cebb0 (patch) | |
tree | b62831a5bdb93e24c2ba24706bd2add8a9293385 | |
parent | 069bf61cea5e3aea07ffd5a1bb9f55324651cb35 (diff) |
tdf#160356 Add support for hidden named expressions in Calc
Since bug 154449 was fixed, Calc now supports hidden named ranges. However, named expressions were not considered in the original patch and it would be useful to support hidden named expressions as well.
This patch adds suppport for hidden named expressions (import and export).
Change-Id: I2580416dcd5db0fcb2aa9061085cdc9975fb03c1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165239
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | sc/qa/unit/data/ods/NamedExpressionsHidden.ods | bin | 0 -> 16611 bytes | |||
-rw-r--r-- | sc/qa/unit/subsequent_filters_test.cxx | 59 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlexprt.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlnexpi.cxx | 4 | ||||
-rw-r--r-- | schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng | 19 |
5 files changed, 86 insertions, 0 deletions
diff --git a/sc/qa/unit/data/ods/NamedExpressionsHidden.ods b/sc/qa/unit/data/ods/NamedExpressionsHidden.ods Binary files differnew file mode 100644 index 000000000000..61e6d1feac6b --- /dev/null +++ b/sc/qa/unit/data/ods/NamedExpressionsHidden.ods diff --git a/sc/qa/unit/subsequent_filters_test.cxx b/sc/qa/unit/subsequent_filters_test.cxx index 87e00ac7f3f0..a0cbd4f0780c 100644 --- a/sc/qa/unit/subsequent_filters_test.cxx +++ b/sc/qa/unit/subsequent_filters_test.cxx @@ -703,6 +703,65 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest, testHiddenRangeNameXLSX) pRangeData2->GetUnoType() & sheet::NamedRangeFlag::HIDDEN); } +CPPUNIT_TEST_FIXTURE(ScFiltersTest, testHiddenNamedExpression) +{ + createScDoc(); + ScDocument* pDoc = getScDoc(); + + // Adds two hidden named expressions and two non-hidden named expressions + ScRangeName* pNamedRanges = pDoc->GetRangeName(); + ScRangeData* pRangeData1 = new ScRangeData(*pDoc, "NAME1", "100"); + pRangeData1->AddType(ScRangeData::Type::Hidden); + pNamedRanges->insert(pRangeData1); + ScRangeData* pRangeData2 = new ScRangeData(*pDoc, "NAME2", "text1"); + pRangeData2->AddType(ScRangeData::Type::Hidden); + pNamedRanges->insert(pRangeData2); + ScRangeData* pRangeData3 = new ScRangeData(*pDoc, "NAME3", "200"); + pNamedRanges->insert(pRangeData3); + ScRangeData* pRangeData4 = new ScRangeData(*pDoc, "NAME4", "text2"); + pNamedRanges->insert(pRangeData4); + CPPUNIT_ASSERT_EQUAL(size_t(4), pNamedRanges->size()); + + // Save and reload to test whether the named expressions retain the hidden where applicable + saveAndReload("calc8"); + pDoc = getScDoc(); + pNamedRanges = pDoc->GetRangeName(); + CPPUNIT_ASSERT_EQUAL(size_t(4), pNamedRanges->size()); + pRangeData1 = pNamedRanges->findByUpperName(OUString("NAME1")); + CPPUNIT_ASSERT(pRangeData1); + CPPUNIT_ASSERT_EQUAL(ScRangeData::Type::Hidden, pRangeData1->GetType()); + CPPUNIT_ASSERT_EQUAL(OUString("100"), pRangeData1->GetSymbol()); + pRangeData2 = pNamedRanges->findByUpperName(OUString("NAME2")); + CPPUNIT_ASSERT(pRangeData2); + CPPUNIT_ASSERT_EQUAL(ScRangeData::Type::Hidden, pRangeData2->GetType()); + CPPUNIT_ASSERT_EQUAL(OUString("text1"), pRangeData2->GetSymbol()); + pRangeData3 = pNamedRanges->findByUpperName(OUString("NAME3")); + CPPUNIT_ASSERT(pRangeData3); + CPPUNIT_ASSERT_EQUAL(ScRangeData::Type::Name, pRangeData3->GetType()); + CPPUNIT_ASSERT_EQUAL(OUString("200"), pRangeData3->GetSymbol()); + pRangeData4 = pNamedRanges->findByUpperName(OUString("NAME4")); + CPPUNIT_ASSERT(pRangeData4); + CPPUNIT_ASSERT_EQUAL(ScRangeData::Type::Name, pRangeData4->GetType()); + CPPUNIT_ASSERT_EQUAL(OUString("text2"), pRangeData4->GetSymbol()); +} + +CPPUNIT_TEST_FIXTURE(ScFiltersTest, testHiddenNamedExpressionODS) +{ + createScDoc("ods/NamedExpressionsHidden.ods"); + ScDocument* pDoc = getScDoc(); + + // The document has 2 named expressions; the first is hidden; the second is visible + ScRangeName* pNamedRanges = pDoc->GetRangeName(); + ScRangeData* pRangeData1 = pNamedRanges->findByUpperName(OUString("NAME1")); + CPPUNIT_ASSERT(pRangeData1); + CPPUNIT_ASSERT_EQUAL(ScRangeData::Type::Hidden, pRangeData1->GetType()); + CPPUNIT_ASSERT_EQUAL(OUString("100"), pRangeData1->GetSymbol()); + ScRangeData* pRangeData2 = pNamedRanges->findByUpperName(OUString("NAME2")); + CPPUNIT_ASSERT(pRangeData2); + CPPUNIT_ASSERT_EQUAL(ScRangeData::Type::Name, pRangeData2->GetType()); + CPPUNIT_ASSERT_EQUAL(OUString("200"), pRangeData2->GetSymbol()); +} + CPPUNIT_TEST_FIXTURE(ScFiltersTest, testHyperlinksXLSX) { createScDoc("xlsx/hyperlinks.xlsx"); diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index abef9391b1fb..e776c006643a 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -4573,6 +4573,10 @@ void ScXMLExport::WriteNamedRange(ScRangeName* pRangeName) else { AddAttribute(XML_NAMESPACE_TABLE, XML_EXPRESSION, sTempSymbol); + // Check if it is a hidden named expression + sal_Int32 nRangeType = rxEntry.second->GetUnoType(); + if ((nRangeType & sheet::NamedRangeFlag::HIDDEN) == sheet::NamedRangeFlag::HIDDEN) + AddAttribute(XML_NAMESPACE_LO_EXT, XML_HIDDEN, XML_TRUE); SvXMLElementExport aElemNE(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSION, true, true); } } diff --git a/sc/source/filter/xml/xmlnexpi.cxx b/sc/source/filter/xml/xmlnexpi.cxx index cf2878032be3..4711e3f1ab1a 100644 --- a/sc/source/filter/xml/xmlnexpi.cxx +++ b/sc/source/filter/xml/xmlnexpi.cxx @@ -151,6 +151,10 @@ ScXMLNamedExpressionContext::ScXMLNamedExpressionContext( case XML_ELEMENT( TABLE, XML_BASE_CELL_ADDRESS ): aNamedExpression.sBaseCellAddress = aIter.toString(); break; + case XML_ELEMENT(LO_EXT, XML_HIDDEN): + if (aIter.toString() == GetXMLToken(XML_TRUE)) + aNamedExpression.sRangeType = GetXMLToken(XML_HIDDEN); + break; } } } diff --git a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng index 9bdcd989f735..7101ce8cfc4c 100644 --- a/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng +++ b/schema/libreoffice/OpenDocument-v1.3+libreoffice-schema.rng @@ -2099,6 +2099,25 @@ xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1. </rng:choice> </rng:attribute> </rng:optional> + </rng:define> + + <rng:define name="table-named-expression-attlist"> + <rng:attribute name="table:name"> + <rng:ref name="string"/> + </rng:attribute> + <rng:attribute name="table:expression"> + <rng:ref name="string"/> + </rng:attribute> + <rng:optional> + <rng:attribute name="table:base-cell-address"> + <rng:ref name="cellAddress"/> + </rng:attribute> + </rng:optional> + <rng:optional> + <rng:attribute name="loext:hidden"> + <rng:ref name="boolean"/> + </rng:attribute> + </rng:optional> </rng:define> </rng:include> |