Skip to content

[Q] How to remove the "frozen" state of a worksheet using ExcelJS #2598

@Mercer-L

Description

@Mercer-L

I am attempting to utilize ExcelJS to remove the "frozen" state of a worksheet. My Code is as follows:

const workbook = new Workbook();
await workbook.xlsx.readFile(excel_path);
const worksheet = workbook.getWorksheet(sheet_name);

if(worksheet){
    if(worksheet?.views[0]){
        (worksheet.views as any) = [{
            state: 'normal',
            zoomScale: 100,
            zoomScaleNormal: 100,
            rightToLeft: false,
            showGridLines: true,
            showRowColHeaders: true,
            showRuler: true,
            workbookViewId: (worksheet.views[0] as any).workbookViewId,
        }];
    }
}
await workbook.xlsx.writeFile(excel_path);

However, upon saving and subsequently attempting to open the saved Excel file with Microsoft Excel, an alert is presented indicating an issue with the worksheet's view that necessitates repair.
I read the saved file using the following code, and then get the worksheet's view property:

const workbook = new Workbook();
await workbook.xlsx.readFile(excel_path);
const worksheet = workbook.getWorksheet(sheet_name);

if(worksheet){
    console.log(worksheet.views);
}

The result I got is:

[{
    state: 'frozen',
    zoomScale: 100,
    zoomScaleNormal: 100,
    rightToLeft: false,
    showGridLines: true,
    showRowColHeaders: true,
    showRuler: true,
    xSplit: 0,
    ySplit: 0,
    topLeftCell: "A1",
    workbookViewId: 0,
}]

Indeed, there is a problem. I would like to ask how to correctly remove the "frozen" property of a worksheet?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions