Skip to content

[Q] adding new formula using worksheet.getCell('O1').value... is breaking excel sheet, what am I doing wrong? #2838

Open
@nashbrowns

Description

@nashbrowns

I have a script that pulls data from a mongo database, and then creates 13 different sheets in an excel file based on the pulled data.

The script was functioning correctly up until I added a single new function:
//adding formula for 'Sessions (Filtered)' worksheet.getCell('O1').value = { formula: "LET(a,B2:B"+lastRow+",b,BYROW(a,LAMBDA(r,AGGREGATE(3,5,r))),COUNTA(UNIQUE(FILTER(a,b=1))))" };

Now when I run the script, it succeeds, but when I try to open the excel file I get a pop-up "We found a problem with some content in 'filename.xlsx'. do you want us to try too recover as much as we can?"
Screenshot 2024-10-15 132610
Accepting shows everything, but the new function is absent from the generated sheets.

The formula is intended to sum the number of unique ID's in column B for visible rows only (subtotal doesn't work for a returned array unfortunately, so it looks very messy). lastRow is just a string I add so that the function is applied across all rows. I am using it successfully in the same manner in the non sheet-breaking functions as well.

I have already tried testing this function in excel itself, and it works perfectly.

These are the other functions that I was using before adding the new sheet-breaking function:
//adding formula for 'Total Collected' worksheet.getCell('K1').value = { formula: "SUBTOTAL(109,G2:G"+lastRow+")" };

//adding formula for 'Remaining Balance' worksheet.getCell('M1').value = { formula: "SUBTOTAL(109,H2:H"+lastRow+")" };

Can anyone tell me what might be happening here? Thanks in advance!

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