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 9cee6a4563
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>
This commit is contained in:
Justin Luth 2024-04-18 14:46:30 -04:00 committed by Miklos Vajna
parent 4a120f4f55
commit 78bd5e2523

View file

@ -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);
}