sc/source/filter/excel/excrecds.cxx |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

New commits:
commit 78bd5e2523d077a67468b752d4788a2c3b43fb5f
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Thu Apr 18 14:46:30 2024 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Apr 19 14:21:13 2024 +0200

    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 <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Justin Luth <jl...@mail.com>

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

Reply via email to