qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
17.64k stars 1.69k forks source link

Addition of SortState for Table #1838

Open doracpphp opened 4 months ago

doracpphp commented 4 months ago

Description

I would like to sort the elements of a Table using Excel's sort function. Currently, I have implemented SortState and sortCondition in Table. On first startup, the ascending and descending marks appear, but the elements are not sorted.

Steps to reproduce the issue:

  1. It generates xml like this
    <?xml version="1.0" encoding="UTF-8"?>
    <table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="1"
    name="Table1" displayName="Table1" ref="A1:B6">
    <autoFilter ref="A1:B6"></autoFilter>
    <sortState ref="A2:B6"
        xmlns:xlrd2="http://schemas.microsoft.com/office/spreadsheetml/2017/richdata2">
        <sortCondition descending="1" ref="A1:A6"></sortCondition>
    </sortState>
    <tableColumns count="2">
        <tableColumn id="1" name="id"></tableColumn>
        <tableColumn id="2" name="name"></tableColumn>
    </tableColumns>
    <tableStyleInfo name="TableStyleMedium2" showFirstColumn="false" showLastColumn="false"
        showRowStripes="true" showColumnStripes="false"></tableStyleInfo>
    </table>
  2. This is the screen when Excel is opened They are supposed to be lined up in descending order, but they are not.

image

Describe the results you expected:

Excel files are sorted and displayed when opened If anyone knows how to do this, could you please advise?

Output of go version:

go version go1.21.6 windows/amd64

Excelize version or commit ID:

f20bbd1f1dcb44eeaf60ed2f5bdc1ac77000a930

Environment details (OS, Microsoft Excel™ version, physical, etc.):

Blogoslov commented 3 months ago

I'm also interesting in method how to apply necessary soring on the columns.