Aspose.Cells for Node.js via Java 26.1.0: key2 sort is ignored when key1 has only one distinct value

We are seeing what looks like a sorting issue in Aspose.Cells for Node.js via Java 26.1.0.

Environment:

  • aspose.cells version: 26.1.0

  • Node.js: 20.19.0

  • OS: macOS

Scenario:

  • We load a CSV into a workbook

  • We sort with headers enabled

  • key1 is Employee Id in descending order

  • key2 is Request Date in ascending order

Expected behavior:

  • If all rows have the same Employee Id, Aspose should still apply the secondary sort on Request Date

  • The dates should become ascending within that single employee group

Actual behavior:

  • When all values in key1 are identical, the sort appears to ignore key2

  • The row order remains unchanged

  • If we instead make Request Date the first sort key, sorting works correctly

This suggests that key2 is not being honored when key1 has only one distinct value.

Minimal repro files are below.

Expected Request Date order after sort: 06-Sep-2025, 06-Sep-2025, 06-Sep-2025, 06-Sep-2025, 06-Sep-2025, 06-Sep-2025, 06-Sep-2025, 08-Sep-2025, 14-Sep-2025, 14-Sep-2025, 14-Sep-2025

Actual order we get: 06-Sep-2025, 06-Sep-2025, 06-Sep-2025, 08-Sep-2025, 14-Sep-2025, 14-Sep-2025, 14-Sep-2025, 06-Sep-2025, 06-Sep-2025, 06-Sep-2025, 06-Sep-2025

We also verified that:

  • the sort columns are resolved correctly

  • the secondary date column is populated correctly

  • sorting by Request Date alone works

  • promoting Request Date to key1 works as a workaround

Can you confirm whether this is a bug or a known limitation in multi-key sorting for CSV-loaded workbooks?

Minimal Repro CSV

Save as repro.csv:

“Employee Id”,“Employee Name”,“Event Type”,“Request Date”,“Form Name”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,06-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,06-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,06-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,08-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,14-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,14-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,14-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,06-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,06-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,06-Sep-2025,“nw form (Version - 1.0)”

Ysr_Usreee,“Yanth Ur_10”,“Attendance Request Attestation”,06-Sep-2025,"nw form (Version - 1.0)

@KarthikMunjam

Please try the following Java codes:

Workbook w = new Workbook(dir + "a.csv");
      
      
      DataSorter sorter = w.getDataSorter();
      sorter.setHasHeaders(true);  
      sorter.setKey1(0);         
      sorter.setKey2(3);          
      
    
      CellArea ca = CellArea.createCellArea("A1", "E12");
      sorter.sort(w.getWorksheets().get(0).getCells(), ca);
      
    
      w.save(dir + "dest.xlsx");

Hello Aspose Team,

We are using Aspose.Cells for Node.js via Java 26.1.0 on Node.js 20.19.0.

We found what appears to be an issue with DataSorter when sorting a worksheet loaded from CSV.

Scenario

The worksheet is loaded from CSV using TxtLoadOptions.

We perform a multi-key sort with:

  • key1 = "Employee Id" (descending)
  • key2 = "Request Date" (ascending)

In the failing dataset, all rows contain the same value for Employee Id.

In this situation, key2 does not appear to be applied, and the row order remains unchanged.

However, if we instead make "Request Date" the primary sort key (key1), the sorting works correctly.

Expected Behavior

Even if all values in key1 are identical, DataSorter should still apply key2 and sort the rows based on the secondary column.

Actual Behavior

When key1 contains only one distinct value, the secondary sort key (key2) appears to be ignored.

Additional Observations

  • The same multi-key sort works correctly on another CSV where key1 contains multiple distinct values.
  • We also tested the key collection API (addKey) and observed the same behavior.
  • Our current workaround is to promote the secondary key to key1 when the primary column has only one distinct value, but this should not be necessary.

Minimal Repro Script

const fs = require('fs');
const os = require('os');
const path = require('path');
const aspose = require('aspose.cells');

const csvContent = `"Employee Id","Employee Name","Event Type","Request Date","Form Name"
"Ysr_Usr_10","Yaswanth User_10","Attendance Request Attestation","06-Sep-2025","nw form (Version - 1.0)"
"Ysr_Usr_10","Yaswanth User_10","Attendance Request Attestation","14-Sep-2025","nw form (Version - 1.0)"
"Ysr_Usr_10","Yaswanth User_10","Attendance Request Attestation","06-Sep-2025","nw form (Version - 1.0)"
"Ysr_Usr_10","Yaswanth User_10","Attendance Request Attestation","08-Sep-2025","nw form (Version - 1.0)"`;

const csvPath = path.join(os.tmpdir(), 'aspose-sort-repro.csv');
fs.writeFileSync(csvPath, csvContent, 'utf8');

function loadWorkbook() {
    const loadOptions = new aspose.TxtLoadOptions(aspose.LoadFormat.CSV);
    loadOptions.setConvertNumericData(false);

    const workbook = new aspose.Workbook(csvPath, loadOptions);
    workbook.getSettings().setRegion(aspose.CountryCode.UNITED_KINGDOM);

    return workbook;
}

function getRequestDates(workbook) {
    const cells = workbook.getWorksheets().get(0).getCells();
    const maxRow = cells.getMaxDataRow();
    const dates = [];

    for (let row = 1; row <= maxRow; row++) {
        dates.push(cells.get(row, 3).getStringValue());
    }

    return dates;
}

function sortWithPrimaryThenSecondary() {
    const workbook = loadWorkbook();
    const cells = workbook.getWorksheets().get(0).getCells();
    const sorter = workbook.getDataSorter();

    console.log('Before current sort:', getRequestDates(workbook));

    sorter.setHasHeaders(true);
    sorter.setKey1(0);
    sorter.setOrder1(aspose.SortOrder.DESCENDING);

    sorter.setKey2(3);
    sorter.setOrder2(aspose.SortOrder.ASCENDING);

    sorter.sort(cells, 0, 0, cells.getMaxDataRow(), cells.getMaxDataColumn());

    console.log('After current sort:', getRequestDates(workbook));
}

function sortWithDateAsKey1() {
    const workbook = loadWorkbook();
    const cells = workbook.getWorksheets().get(0).getCells();
    const sorter = workbook.getDataSorter();

    sorter.setHasHeaders(true);

    sorter.setKey1(3);
    sorter.setOrder1(aspose.SortOrder.ASCENDING);

    sorter.sort(cells, 0, 0, cells.getMaxDataRow(), cells.getMaxDataColumn());

    console.log('After date as key1:', getRequestDates(workbook));
}

sortWithPrimaryThenSecondary();
sortWithDateAsKey1();

Expected Console Output

Before current sort:
[ '06-Sep-2025', '14-Sep-2025', '06-Sep-2025', '08-Sep-2025' ]

After current sort:
[ '06-Sep-2025', '14-Sep-2025', '06-Sep-2025', '08-Sep-2025' ]
← unchanged / problematic

After date as key1:
[ '06-Sep-2025', '06-Sep-2025', '08-Sep-2025', '14-Sep-2025' ]
← expected ordering

Thank you.

@KarthikMunjam

Thank you for providing the detailed reproduction script and the evidence regarding the DataSorter behavior. We have successfully received your findings and the specific scenario where the second sort key is ignored when the first key contains identical values.

I have logged this information with our development team to be included in the ongoing investigation. Your provided code and dataset description are very helpful in pinpointing why the sorting logic is failing to transition to the secondary key in this specific context.

We are currently analyzing the internal sorting mechanism for the Node.js via Java wrapper to identify the root cause. We will keep you updated on the progress of this investigation and notify you as soon as a fix or further information becomes available.