o-spreadsheet icon indicating copy to clipboard operation
o-spreadsheet copied to clipboard

Can extract data from the sheet

Open ramusesan opened this issue 2 years ago • 7 comments

hi, I found this lib is very useful. am looking for a library where we can store and retrieve the data from the sheet is this possible with this library,i am not able to see anything relevant extract data from the sheet and store in DB

ramusesan avatar Feb 02 '23 11:02 ramusesan

Hello @ramusesan Are you looking for a way to save the state of the sheet and store it in a DB? With the goal to re-open the spreadsheet later with the data? Did I understand correctly ?

If that's what you are looking for, you can use the exportData() method on the model. The spreadsheet state is a json data structure.

const model = new Model(...);

// when you want to retrieve the spreadsheet data
const data = model.exportData();
// now you can do whatever you want with the data, including saving it to a database

LucasLefevre avatar Feb 02 '23 12:02 LucasLefevre

Without any update for two months, I will close this issue.

Regards

rrahir avatar Apr 17 '23 13:04 rrahir

Hello @ramusesan Are you looking for a way to save the state of the sheet and store it in a DB? With the goal to re-open the spreadsheet later with the data? Did I understand correctly ?

If that's what you are looking for, you can use the exportData() method on the model. The spreadsheet state is a json data structure.

const model = new Model(...);

// when you want to retrieve the spreadsheet data
const data = model.exportData();
// now you can do whatever you want with the data, including saving it to a database

I tried this but I cannot get the data from Cells which has formula in it

saifkazi avatar May 19 '23 15:05 saifkazi

Do you mean you don't get the cell values (evaluated formulas)?

LucasLefevre avatar May 19 '23 15:05 LucasLefevre

Do you mean you don't get the cell values (evaluated formulas)?

That is exactly what I wanted evaluated(or should I say computed ?) values . so I can put that in my db I tried model.getters.getCell("Sheet1",1,12) I am getting the formula but evaluated object shows value "Loading..."

saifkazi avatar May 19 '23 15:05 saifkazi

Do you mean you don't get the cell values (evaluated formulas)?

That is exactly what I wanted evaluated(or should I say computed ?) values . so I can put that in my db I tried model.getters.getCell("Sheet1",1,12) I am getting the formula but evaluated object shows value "Loading..."

Update :

I just set my model mode from headless to normal and it worked but only for one sheet while the evaluated data in other sheets shows 'Loading'

 const model = await new Model(data, {
            mode: "normal",
        });

Update 2:

I need to evaluate Cells in loop and it worked

var sheets = model.getters.getSheets()
for (let index = 0; index < sheets.length; index++) {
            await model.dispatch("EVALUATE_CELLS", { sheetId: sheets[index].id})
        }

saifkazi avatar May 21 '23 04:05 saifkazi

Which version are you using ? (I strongly suggest using 16.0 or the latest 16.3)

LucasLefevre avatar May 21 '23 07:05 LucasLefevre