Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error saving files when streaming using autofilter and sheet protection #2685

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Dokril
Copy link

@Dokril Dokril commented Feb 11, 2024

Summary

Hello. Recently I came across a problem when, when recording a file in a stream, you set a password and autofilter, the file breaks and cannot be opened. Having slightly changed the source code, I was able to solve this problem by changing the order in which data was written to the file.

Test plan

The code below on the current version of the library creates a file that does not open and causes an error
image

After commenting

worksheet.autoFilter = { from: 'A1', to: 'C1' };

or

await worksheet.protect('test', { formatColumns: true, formatRows: true, autoFilter: true, pivotTables: true });

out the error disappears

import { stream } from 'exceljs';

async function main() {
    const workbook = new stream.xlsx.WorkbookWriter({ filename: './test.xlsx', useStyles: true });

    const worksheet = workbook.addWorksheet('test');
    worksheet.addRow([3, 'Sam', new Date()]).commit();
    worksheet.autoFilter = { from: 'A1', to: 'C1' };
    await worksheet.protect('test', { formatColumns: true, formatRows: true, autoFilter: true, pivotTables: true });
    worksheet.commit();
    await workbook.commit();
}
main();

Changes to the pull request correct this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant