Bug 167496 - FILESAVE XLSX Invalid ranges saved into sorted autofilter
Summary: FILESAVE XLSX Invalid ranges saved into sorted autofilter
Status: ASSIGNED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: filters and storage (show other bugs)
Version:
(earliest affected)
6.4.7.2 release
Hardware: All All
: medium normal
Assignee: Markus Mohrhard
URL:
Whiteboard:
Keywords: bibisected, bisected, implementationError
Depends on:
Blocks: XLSX-Corrupted XLSX-Autofilter
  Show dependency treegraph
 
Reported: 2025-07-13 22:26 UTC by Aron Budea
Modified: 2025-08-06 18:11 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
Sample XLSX (8.51 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2025-07-13 22:26 UTC, Aron Budea
Details
forum-mso-de-122145.xlsx (10.26 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2025-07-13 22:27 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-07-13 22:26:54 UTC
Created attachment 201785 [details]
Sample XLSX

The attached test file, which was based on an issue seen with forum-mso-de-122145.xlsx (also attached), was created in Excel by adding autofilter to a minimal set of data (2 columns), and sorting the first column in the filter.
Open and save it back to XLSX, then try opening it in Excel.

=> Excel fails to open the file cleanly, and claims it found a problem with the file. After attempting recovery, the file opens without further message.

This is the relevant part from xl/worksheets/sheet1.xml:
<autoFilter ref="A3:B3">
  <sortState ref="A4:B6">
    <sortCondition ref="A3"/>
  </sortState>
</autoFilter>

Here's the same part from the exported file:
<autoFilter ref="A3:B3">
  <sortState ref="A4:B3">
    <sortCondition ref="A4:A3" customList=""/>
  </sortState>
</autoFilter>

Note the 'sortState' ref, which is an invalid range: "A4:B3", and the 'sortCondition' ref, where "A4:A3" is equally invalid.

This issue is an implementation error in 7.1 from the following commit:
https://git.libreoffice.org/core/commit/a9f8f0a484965338221cad4f97d98f418b5ccff1
https://cgit.freedesktop.org/libreoffice/core/commit/?id=a9f8f0a484965338221cad4f97d98f418b5ccff1
author		Serge Krot <Serge.Krot@cib.de>	2020-06-29 13:23:34 +0200
committer	Thorsten Behrens <Thorsten.Behrens@CIB.de>	2020-09-08 12:51:17 +0200

"tdf#95640 XLSX: import/export of custom sort lists"

Before that, the same exported XML part looked like this (no 'sortState' was exported):
<autoFilter ref="A3:B3"/>

Still in LO 26.2.0.0.alpha0+ (697fadb8f4efdc09091088261ca1b43984c029b4) / Windows.

A specialty of this file is that the autofilter was created in Excel by selecting the header cells, and those only, and clicking the filter button. Selecting the whole data area, and creating the autofilter that way will produce different XML that doesn't exhibit the bug.
Comment 1 Aron Budea 2025-07-13 22:27:52 UTC
Created attachment 201786 [details]
forum-mso-de-122145.xlsx
Comment 2 b. 2025-07-13 23:36:06 UTC
likely a variant of an issue ignored since 5 years,  
calc has only one setting and mixes up use for sort  
and filtering or the like, see: #133529