tdf#126177 XLSX export: fix hyperlinks to documents
After export hyperlinks to documents didn't work, because the
the hyperlink relationship targets contained also the anchor.
Change-Id: I0bfc5bd1ef2b37f769d6a6b97e31c1b4bbfcb9aa
Reviewed-on: https://gerrit.libreoffice.org/74988
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
diff --git a/sc/qa/unit/data/xlsx/hyperlink_export.xlsx b/sc/qa/unit/data/xlsx/hyperlink_export.xlsx
new file mode 100644
index 0000000..4c3952d
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/hyperlink_export.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 9d628f9..06eaf39 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -225,6 +225,7 @@ public:
void testTdf125173XLSX();
void testTdf79972XLSX();
void testTdf126024XLSX();
void testTdf126177XLSX();
void testXltxExport();
@@ -355,6 +356,7 @@ public:
CPPUNIT_TEST(testTdf125173XLSX);
CPPUNIT_TEST(testTdf79972XLSX);
CPPUNIT_TEST(testTdf126024XLSX);
CPPUNIT_TEST(testTdf126177XLSX);
CPPUNIT_TEST(testXltxExport);
@@ -4437,6 +4439,23 @@ void ScExportTest::testTdf126024XLSX()
assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "TargetMode", "External");
}
void ScExportTest::testTdf126177XLSX()
{
ScDocShellRef xDocSh = loadDoc("hyperlink_export.", FORMAT_XLSX);
CPPUNIT_ASSERT(xDocSh.is());
std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX);
xmlDocPtr pDoc = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/sheet1.xml");
CPPUNIT_ASSERT(pDoc);
assertXPath(pDoc, "/x:worksheet/x:hyperlinks/x:hyperlink", "location", "Munka1!A5");
xmlDocPtr pXmlRels = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/worksheets/_rels/sheet1.xml.rels");
CPPUNIT_ASSERT(pXmlRels);
OUString aTarget = getXPath(pXmlRels, "/r:Relationships/r:Relationship", "Target");
CPPUNIT_ASSERT(aTarget.endsWith("test.xlsx"));
assertXPath(pXmlRels, "/r:Relationships/r:Relationship", "TargetMode", "External");
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index 234c681..3237ff1 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -445,6 +445,10 @@ XclExpHyperlink::XclExpHyperlink( const XclExpRoot& rRoot, const SvxURLField& rU
aXclStrm << sal_uInt16( 0 );
mnFlags |= EXC_HLINK_MARK;
OUString location = XclXmlUtils::ToOUString(*mxTextMark);
if (msTarget.endsWith(location))
msTarget = msTarget.copy(0, msTarget.getLength() - location.getLength() - 1);
}
SetRecSize( 32 + mxVarData->Tell() );