exceljs icon indicating copy to clipboard operation
exceljs copied to clipboard

[BUG] Sorting is not working after I apply auto filter

Open ShyamL1319 opened this issue 2 years ago • 4 comments

🐛 Bug Report

Sorting is not working after I apply auto filter We create excel file using below code and try to sort on filters but it gets closed unexpectedly.

Lib version: 4.3.0

Steps To Reproduce

const ExcelJS = require('exceljs');

// Create a new workbook and add a worksheet
const workbook = new ExcelJS.Workbook();
const worksheet = workbook.addWorksheet('Sheet1');

// Add data to the worksheet
worksheet.addRow(['Name', 'Age', 'City']);
worksheet.addRow(['John Doe', 30, 'New York']);
worksheet.addRow(['Jane Smith', 23, 'London']);
worksheet.addRow(['Jane Smith', 21, 'PAk']);
worksheet.addRow(['Jane Smith', 20, 'India']);
worksheet.addRow(['Jane Smith', 33, 'London']);

// worksheet.mergeCells('B2:C2');
// worksheet.getCell('B2').value = "flight not found";

// Enable filters on the desired columns
worksheet.autoFilter = {
  from: {
    row: 1,
    column: 1
  },
  to: {
    row: 3,
    column: 3
  }
};
// Save the workbook to a file
workbook.xlsx.writeFile('output.xlsx')
  .then(function() {
    console.log('Excel file created successfully.');
  })
  .catch(function(error) {
    console.log('An error occurred while creating the Excel file:', error);
  });

Open created excel and try to apply sorting on filters the gets closed unexpectedly.

The expected behavior:

Opened created file should be able to apply sorting on columns

ShyamL1319 avatar Jun 22 '23 10:06 ShyamL1319

Please let us know if any solution is there or there is another way of implementation

ShyamL1319 avatar Jun 22 '23 10:06 ShyamL1319

@ShyamL1319 The excel generated after running your code locally to me is sorting properly, and is now a screenshot in ascending order by Age. What software are you using to open it, I am using WPS.

image

zurmokeeper avatar Jun 22 '23 12:06 zurmokeeper

@zurmokeeper I am facing the same issue with autofilter i am using MS Excel for open my file. In my case after applying filter sorting is working but if i try to sorting without filter excel is unexpectedly closed. and the same filter is working well in wps excel If you want i can share my code. and this is the file i am facing issue with. Stocklist-15-8-2024 1140114.xlsx

HarshJogani avatar Aug 15 '24 06:08 HarshJogani

@ShyamL1319 did you find any solution ?

ds-talaviya avatar Sep 27 '24 07:09 ds-talaviya