Closed giswqs closed 2 years ago
It seems that if the sheet is constructed using from_dataframe()
, the to_dataframe()
works properly.
IIRC you need to specifically create the cells if you need them to be synced between front-end/back-end.
from_dataframe
might create the cells objects for you, but if you don't use from_dataframe
you'll probably have to create the cells objects by yourself.
My question is: how to capture the values entered into the cells if I have to create the cells objects manually?
I don't understand the question?
I you want to be able to capture the values entered into the cells, you need the cells connection to actually exist. We could agree on the fact that it's not a user-friendly behavior, but I guess that was for optimization purpose (not creating useless cells objects, each cell being a widget).
My goal is to create a tool that can capture values entered by user and pass those values to properties of user draw features. That's why I need to use to_dataframe()
to get the cell values.
Sure :) You can do this by creating the cell-range objects manually when creating the sheet, then if the user enters something, you will know about it and be able to use to_dataframe
I just tested the cell-range example. It does not work for to_dataframe()
.
Not sure what's happening with this code example, what happens if you make a simpler table?
sheet = ipysheet.sheet(rows=1, columns=2)
row = ipysheet.row(0, [3.4, 5.6])
The cell-range trick works. I need to add the the cell-range with empty strings. Otherwise, it won't work.
@martinRenou Thanks for you help. Closing it for now.
Just a reference for future readers: the follow code snippet will create a sheet that works for to_dataframe()
and to_array()
.
import ipysheet
rows = 3
columns = 2
sheet = ipysheet.sheet(rows=rows, columns=columns)
for i in range(columns):
ipysheet.column(i, [""] * sheet.rows)
sheet
# ipysheet.to_dataframe(sheet)
# ipysheet.to_array(sheet)
The
to_dataframe()
andto_array()
functions can only return values added the the cells programmatically. Any values entered manually on the sheet are not passed to the dataframe/array. This makes ipysheet much less usable if it can't capture values entered manually.Related issue: #194