zaz/doc/build/_sources/main/calc_data.rst.txt

93 lines
1.5 KiB
Plaintext
Raw Normal View History

2021-07-04 19:33:44 -05:00
Data
~~~~
Read
^^^^
* Get value from cell, automatic detect type and get value.
.. code-block:: python
sheet = app.active_sheet
cell = sheet['A1']
value = cell.value
info = f'Cell Type = {cell.type}\n\nCell Value = {cell.value}'
app.msgbox(info)
2021-07-06 22:29:05 -05:00
* Get date, time and datetime like data Python.
.. code-block:: python
sheet = app.active_sheet
cell = sheet['A1']
app.msgbox(cell.date)
app.msgbox(cell.time)
app.msgbox(cell.datetime)
* Get values from cell range.
.. code-block:: python
sheet = app.active_sheet
rango = sheet['A1:B5']
app.msgbox(rango.data)
* Get formulas
.. code-block:: python
sheet = app.active_sheet
rango = sheet['A1:B5']
app.msgbox(rango.formula)
* Get array formula
.. code-block:: python
sheet = app.active_sheet
rango = sheet['C10:E15']
app.msgbox(rango.array_formula)
* Get like dictionary
The first row in range are the keys.
.. code-block:: python
sheet = app.active_sheet
rango = sheet['A1:B5']
app.msgbox(rango.dict)
2021-07-04 19:33:44 -05:00
Write
^^^^^
* Automatic detect data type.
.. code-block:: python
sheet = app.active_sheet
# ~ Set int
sheet['A1'].value = 1
# ~ Set float
sheet['A2'].value = 10.5
# ~ Set string
sheet['A3'].value = 'Damn World'
2021-07-06 22:29:05 -05:00
# ~ Set formula
sheet['A4'].value = '=RAND()'
2021-07-04 19:33:44 -05:00
# ~ Set date
2021-07-06 22:29:05 -05:00
sheet['A5'].value = app.today()
2021-07-04 19:33:44 -05:00
# ~ Set time
2021-07-06 22:29:05 -05:00
sheet['A6'].value = app.now(True)
2021-07-04 19:33:44 -05:00
# ~ Set datetime
2021-07-06 22:29:05 -05:00
sheet['A7'].value = app.now()