Bug 166413 - FILESAVE XLSX Excel fails to open roundtripped spreadsheet due to unescaped quotes in conditional formatting XML
Summary: FILESAVE XLSX Excel fails to open roundtripped spreadsheet due to unescaped q...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: filters and storage (show other bugs)
Version:
(earliest affected)
6.1.0.3 release
Hardware: All All
: medium normal
Assignee: Aron Budea
URL:
Whiteboard: target:25.8.0 target:25.2.4
Keywords: bibisected, bisected
Depends on:
Blocks: XLSX-Corrupted XLSX-Conditional-Formatting
  Show dependency treegraph
 
Reported: 2025-05-01 03:16 UTC by Aron Budea
Modified: 2025-05-07 00:45 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Sample XLSX (8.69 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2025-05-01 03:16 UTC, Aron Budea
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Aron Budea 2025-05-01 03:16:03 UTC
Created attachment 200621 [details]
Sample XLSX

The attached sample was created in Excel, and has a couple of simple conditional formatting rules with various "Specific text" conditions.
Open and save the file back to XLSX in Calc, then try opening it in Excel.

=> Excel fails to open the file cleanly.
When attempting repairs, it claims: "Removed Feature: Conditional formatting from /xl/worksheets/sheet1.xml part"

Observed using LO 25.8.0.0.alpha0+ (736998ccef0bacdd2bbf038c98dacfbe654f1a4d) / Windows.

If one:
- unzips the saved XLSX,
- executes the following command (can be done in Linux/Cygwin, needs xmllint installed): find . -name "*.xml" -type f -exec xmllint --output '{}' --format '{}' \;

...they can find this in /xl/worksheets/sheet1.xml:
<conditionalFormatting sqref="A1:C1">
  <cfRule type="containsText" priority="5" operator="containsText" aboveAverage="0" equalAverage="0" bottom="0" percent="0" rank="0" text="&quot;ABC&quot;" dxfId="3">
    <formula>NOT(ISERROR(SEARCH(""ABC"",A1)))</formula>
  </cfRule>
</conditionalFormatting>

Comparing the same part in the original file, the extra quotes (""" instead of "") stand out in the original, ie. the quotes aren't escaped properly:
<conditionalFormatting sqref="A1:C1">
  <cfRule type="containsText" dxfId="3" priority="4" operator="containsText" text="&quot;ABC&quot;">
    <formula>NOT(ISERROR(SEARCH("""ABC""",A1)))</formula>
  </cfRule>
</conditionalFormatting>

Manually adding the extra quotes, and zipping the files with XLSX extension makes the file openable in Excel.

Before the below commit in 6.2 (and its 6.1 backport), the part between the <formula> tag wasn't written at all, and the result could be opened in Excel, but the conditional formatting wasn't shown correctly.

https://git.libreoffice.org/core/commit/e77596be879c25f5766b73a2f67cf0ddf7775ccc
https://cgit.freedesktop.org/libreoffice/core/commit/?id=e77596be879c25f5766b73a2f67cf0ddf7775ccc
author		Markus Mohrhard <markus.mohrhard@googlemail.com>	2018-07-14 15:16:46 +0200
committer	Markus Mohrhard <markus.mohrhard@googlemail.com>	2018-07-15 00:36:18 +0200

tdf#117816, work around MS Excel bug with containsText cond format
Comment 1 Commit Notification 2025-05-01 09:55:45 UTC
Aron Budea committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/55169df2f6e4f8deb9c042b81cc3ff4f01cbf522

tdf166413 sc: escape quotes in XLSX cond. formatting fixed formula

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 2 Commit Notification 2025-05-02 08:52:28 UTC
Aron Budea committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/d1250d073fa978163eb86e4bd8aedcacbdd7895b

tdf166413 sc: escape quotes in XLSX cond. formatting fixed formula

It will be available in 25.2.4.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Jazevedo 2025-05-07 00:45:35 UTC
Tested with the sample file provided and: 

Version: 25.2.4.0.0+ (X86_64) / LibreOffice Community
Build ID: 3176efaa5df50c202a6e45cd219d1f458fd3bded
CPU threads: 20; OS: Linux 6.12; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

The file opens normally in MSO now. 

Thanks for the fix.