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

Sheet not found when using API #490

Open
TiagoBlauth opened this issue Oct 11, 2023 · 0 comments
Open

Sheet not found when using API #490

TiagoBlauth opened this issue Oct 11, 2023 · 0 comments

Comments

@TiagoBlauth
Copy link

TiagoBlauth commented Oct 11, 2023

Describe the bug
I am trying to recreate a sheet by removing current sheets, adding new sheets, and populating the cells. So far so good, the sheet remove and recreate works, value set works, but when I try to set cell formats it presents the error below.

ERROR
sheet not found

at ./node_modules/@fortune-sheet/core/dist/index.esm.js (http://localhost:3000/static/js/bundle.js:73709:23)
at options.factory (http://localhost:3000/static/js/bundle.js:159957:31)
at webpack_require (http://localhost:3000/static/js/bundle.js:159380:33)
at fn (http://localhost:3000/static/js/bundle.js:159614:21)
at ./node_modules/@fortune-sheet/react/dist/index.esm.js (http://localhost:3000/static/js/bundle.js:80513:77)
at options.factory (http://localhost:3000/static/js/bundle.js:159957:31)
at webpack_require (http://localhost:3000/static/js/bundle.js:159380:33)
at fn (http://localhost:3000/static/js/bundle.js:159614:21)
at ./src/Test.tsx (http://localhost:3000/static/js/bundle.js:148:78)
at options.factory (http://localhost:3000/static/js/bundle.js:159957:31)

To Reproduce
Steps to reproduce the behavior:

Sheet reloading process, this is the failing process.

async function getAllSheets() {
    //loading the sheet from local storage
    const sampleSheet = localStorage.getItem("samplesheet")
    const convertedSheet = JSON.parse(sampleSheet)
    //Removing all sheets from the list
    for (let i = 0; i < sheetList.length; i++) {
        workbookRef.current?.deleteSheet({ 'id': sheetList[i].id })
    }
    sheetList = []
    //Sheet creation
    for (let i = 0; i < convertedSheet.length; i++) {
        await workbookRef.current?.addSheet()
        workbookRef.current?.setSheetName(convertedSheet[i].name)
        //Adding data
        for (let j = 0; j < convertedSheet[i].data.length; j++) {
            for (let k = 0; k < convertedSheet[i].data[j].length; k++) {
                if (convertedSheet[i].data[j][k] !== null) {
                    workbookRef.current?.setCellValue(j, k, convertedSheet[i].data[j][k].v);
                }
            }
        }
        //set cell format - ### it fails here ###
        cellFormat()
    }
}

Cell format function

function cellFormat() {
    //set cell format
    for (let i = 0; i < 30; i++) {
        if (workbookRef.current?.getCellValue(i, 0) !== null) {
            workbookRef.current?.setCellFormat(i, 0, 'bl', 'data');
            workbookRef.current?.setCellFormat(i, 0, 'bg', '#eeeeee');
        }
    }
    for (let j = 0; j < 30; j++) {
        if (workbookRef.current?.getCellValue(0, j) !== null) {
            workbookRef.current?.setCellFormat(0, j, 'bl', 'data');
            workbookRef.current?.setCellFormat(0, j, 'bg', '#eeeeee');
        }
    }
}

Not relevant, but it is here, the saving process for local storage

function saveAllSheets() {
    const allSheets = workbookRef.current?.getAllSheets();
    localStorage.setItem("samplesheet", JSON.stringify(allSheets))
}

The workbook itself:

      <Workbook ref={workbookRef} data={workbookData} onOp={opChange} />

The error happens when getAllSheets() process runs and cellFormat() is called. If I take cellFormat() out of getAllSheets() and use separate buttons, both works.

Expected behavior
I expect to be able to format the sheet in the same process I am creating the sheets.

Additional context
I tried to use CommonOptions to determine the sheet I am referring to, but I am probably doing it wrong. Try to find an example in the documentation or in here with no luck. It would be nice if you can provide me an example.

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

No branches or pull requests

1 participant