summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2024-04-18 14:46:30 -0400
committerMiklos Vajna <vmiklos@collabora.com>2024-04-19 14:21:13 +0200
commit78bd5e2523d077a67468b752d4788a2c3b43fb5f (patch)
treeb56d8e5a74912306043b97f0bbdd2077255c9c4c
parent4a120f4f557b99bb8371474a4e7fdaf52b148143 (diff)
xlsx export: fix corrupt file for Excel: protectedRange must have sqref
Excel refuses to open a file if there is no sqref specified <protectedRanges> <protectedRange name="corruptFile"/> </protectedRanges> In this case, import failed to import sqref="10:131". A follow-up commit avoids exporting these shorthand ranges. I don't see much point in trying to create a unit test for this. (I assume protectedRange is simply round-tripped because I doubt LO has working support for protectedRanges.) commit 9cee6a45632623d3d7e5a574128940f96d8c926b Author: Eike Rathke on Thu Mar 20 10:16:50 2014 +0100 added ScEnhancedProtection to ScTableProtection Change-Id: I97ef1ee801898bdcace067d62890c4ce0e7cf1d8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166265 Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Justin Luth <jluth@mail.com>
-rw-r--r--sc/source/filter/excel/excrecds.cxx5
1 files changed, 4 insertions, 1 deletions
diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx
index 86afa5a6c163..f18e9f829bbe 100644
--- a/sc/source/filter/excel/excrecds.cxx
+++ b/sc/source/filter/excel/excrecds.cxx
@@ -478,6 +478,9 @@ void XclExpSheetProtection::SaveXml( XclExpXmlStream& rStrm )
rWorksheet->startElement(XML_protectedRanges);
for (const auto& rProt : rProts)
{
+ if (!rProt.maRangeList.is())
+ continue; // Excel refuses to open if sqref is missing from a protectedRange
+
SAL_WARN_IF( rProt.maSecurityDescriptorXML.isEmpty() && !rProt.maSecurityDescriptor.empty(),
"sc.filter", "XclExpSheetProtection::SaveXml: losing BIFF security descriptor");
rWorksheet->singleElement( XML_protectedRange,
@@ -492,7 +495,7 @@ void XclExpSheetProtection::SaveXml( XclExpXmlStream& rStrm )
XML_hashValue, sax_fastparser::UseIf(rProt.maPasswordHash.maHashValue, !rProt.maPasswordHash.maHashValue.isEmpty()),
XML_saltValue, sax_fastparser::UseIf(rProt.maPasswordHash.maSaltValue, !rProt.maPasswordHash.maSaltValue.isEmpty()),
XML_spinCount, sax_fastparser::UseIf(OString::number(rProt.maPasswordHash.mnSpinCount), rProt.maPasswordHash.mnSpinCount != 0),
- XML_sqref, rProt.maRangeList.is() ? XclXmlUtils::ToOString( rStrm.GetRoot().GetDoc(), *rProt.maRangeList).getStr() : nullptr);
+ XML_sqref, XclXmlUtils::ToOString(rStrm.GetRoot().GetDoc(), *rProt.maRangeList).getStr());
}
rWorksheet->endElement( XML_protectedRanges);
}