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

269 lines
3.6 KiB
Plaintext
Raw Normal View History

2021-06-25 22:55:52 -05:00
Calc
----
2021-07-03 19:23:23 -05:00
Remember, always import library.
2021-06-25 22:55:52 -05:00
.. code-block:: python
import easymacro as app
Current doc
2021-07-03 19:23:23 -05:00
~~~~~~~~~~~
2021-06-25 22:55:52 -05:00
.. code-block:: python
doc = app.active
app.msgbox(doc.type)
2021-07-03 19:23:23 -05:00
Selection
~~~~~~~~~
* If selection is range get LOCalcRange, if selection is shape get LOShape, other selection get original pyuno object.
.. code-block:: python
doc = app.active
selection = doc.selection
app.msgbox(type(selection))
Headers
~~~~~~~
* Hide or show columns and rows headers.
.. code-block:: python
doc = app.active
app.msgbox(doc.headers)
doc.headers = not doc.headers
app.msgbox(doc.headers)
doc.headers = not doc.headers
Tabs
~~~~
* Hide or show tab sheets.
.. code-block:: python
doc = app.active
app.msgbox(doc.tabs)
doc.tabs = not doc.tabs
app.msgbox(doc.tabs)
doc.tabs = not doc.tabs
Sheets
^^^^^^
2021-06-25 22:55:52 -05:00
Active sheet
2021-07-03 19:23:23 -05:00
~~~~~~~~~~~~
.. code-block:: python
sheet = app.active_sheet
app.msgbox(sheet.name)
# or
doc = app.active
sheet = doc.active
Get by index
~~~~~~~~~~~~
.. code-block:: python
doc = app.active
sheet = doc[0]
app.msgbox(sheet.name)
Get by name
~~~~~~~~~~~
.. code-block:: python
doc = app.active
sheet = doc['Sheet1']
app.msgbox(sheet.name)
Contains
~~~~~~~~
.. code-block:: python
doc = app.active
app.msgbox('Sheet1' in doc)
Get tuple with all names
~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: python
doc = app.active
app.msgbox(doc.names)
Count
~~~~~
.. code-block:: python
doc = app.active
app.msgbox(len(doc))
New
~~~
* Always validate if new name not exists.
.. code-block:: python
doc = app.active
sheet = doc.new_sheet()
# CAUTION: If 'NewSheet' exists, reset it to clean sheet.
doc['NewSheet'] = sheet
# ~ or
sheet = doc.insert('NewSheet2')
* Insert multiple, get last insert.
.. code-block:: python
names = ('One', 'Two', 'Three')
sheet = doc.insert(names)
Move
~~~~
* Move by object to last position.
.. code-block:: python
sheet = doc[0]
doc.move(sheet)
* Move by name to last position.
.. code-block:: python
doc.move('Sheet1')
* Move to position.
sheet = doc[0]
doc.move(sheet, 2)
Remove
~~~~~~
* Remove by object
.. code-block:: python
sheet = doc[0]
doc.remove(sheet)
* Remove by name
.. code-block:: python
doc.remove('One')
Copy
~~~~
* Copy inside the same spreadsheet.
* By object
.. code-block:: python
sheet = doc[0]
doc.copy(sheet, 'OtherSheet')
* By name
.. code-block:: python
doc.copy('Sheet1', 'Sheet2')
Copy from
~~~~~~~~~
* Copy sheet from one spreadsheet to other.
.. code-block:: python
doc = app.active
doc_source = app.docs['Contacts.ods']
name_source = 'Names'
name_target = 'Names'
position = 0
doc.copy_from(doc_source, name_source, name_target, position)
Sort
~~~~
* Sort sheets by names.
.. code-block:: python
doc = app.active
doc.sort()
Name
~~~~
* Name visible by the user.
2021-06-25 22:55:52 -05:00
.. code-block:: python
sheet = app.active_sheet
app.msgbox(sheet.name)
2021-07-03 19:23:23 -05:00
sheet.name = 'NewName'
app.msgbox(sheet.name)
Code name
~~~~~~~~~
* Name only accessible by code.
.. code-block:: python
sheet = app.active_sheet
app.msgbox(sheet.code_name)
sheet.code_name = 'my_name'
app.msgbox(sheet.code_name)
Visible
~~~~~~~
* Apply only with spreadsheet with two or more sheets.
.. code-block:: python
sheet = app.active_sheet
app.msgbox(sheet.visible)
sheet.visible = not sheet.visible
app.msgbox(sheet.visible)
sheet.visible = not sheet.visible