This project is no longer maintained!
Sorry...
PyLOcalc
Python interface for manipulating LibreOffice Calc spreadsheets
DISCLAIMER: This is not production software! Backup your document before trying it!
About
LibreOffice/OpenOffice has API for many languages including Python, thanks to the Universal Network Objects (UNO).
But its API is all but Pythonic!
I took inspiration from this article and created simple wrapper around this API.
PyLOcalc also automatically opens a headless LibreOffice Calc document with basic read, write, and save functionality. Therefore, it can be used as a library for other scripts that manipulate spreadsheets.
Requirements
-
python>=3.8
-
You have to have LibreOffice with "python support" installed. In Ubuntu it's (apparently)
sudo apt install libreoffice-script-provider-python, in Arch Linux I didn't have to do anything.You can try running
python -m unoand it should not produce any output or error. -
Macro security - Medium. Follow this article.
Installation
pip install pylocalc
Basic usage
import pylocalc
doc = pylocalc.Document('path/to/calc/spreadsheet.ods')
# You have to connect first
doc.connect()
# Get the sheet by index
sheet = doc[2]
# Or by name
sheet = doc[doc.sheet_names[1]]
# Get the cell by index
cell = sheet[10, 14]
# Or by "name"
cell = sheet['B12']
# Read and set cell value
print(cell.value)
> 'Some value'
cell.value = 12.2
print(cell.value)
> '12.2'
cell.value = 'Other value'
print(cell.value)
> 'Other value'
# Don't forget to save and close the document!
doc.save()
doc.close()
Append rows and columns
PyLOcalc can append row and column values to the first available row or column.
It looks at the cell at the offset (default 0) and if the cell is empty it adds values there.
import decimal
import pylocalc
doc = pylocalc.Document('path/to/calc/spreadsheet.ods')
doc.connect()
sheet = doc['Totals']
sheet.append_row(('2021-01-01', 123, 12.3, decimal.Decimal("0.111"), 'Yaaay'), offset=1)
sheet.append_column(('New column header'))
doc.save()
doc.close()
Context manager
PyLOcalc Document can be used as context manager that automatically connects and closes the document.
If no error is raised in the context block it also saves the document.
import pylocalc
with pylocalc.Document('path/to/calc/spreadsheet.ods') as doc:
doc[0][1,10].value = 'I ❤️ context managers'
Metadata
Release files for pylocalc 0.5.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pylocalc-0.5.2.tar.gz | 6.2 kB | Without provenance | Details for pylocalc-0.5.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pylocalc-0.5.2-py3-none-any.whl | Python 3 | none | any | Details for pylocalc-0.5.2-py3-none-any.whl |
Total release size: 12.2 kB
Release files / pylocalc-0.5.2.tar.gz
| Download URL | pylocalc-0.5.2.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2aa17e93431c7e9dc9886938a940959bb659c75c4c1c0b409066195bfbb0c2c3
|
|
BLAKE2b-256 checksum How to use checksums |
a261a9c015f0db71dc55c850686fe4b17851e58b50e9f5a64191451466f46239
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.1 Darwin/21.2.0
|
Release files / pylocalc-0.5.2-py3-none-any.whl
| Download URL | pylocalc-0.5.2-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2fcdf7de8faf7897ec42b25971bc3eb190f0a4f9f3bd8dcd71b2b3808924bd3
|
|
BLAKE2b-256 checksum How to use checksums |
3b49ac85ed46d4e0a7d1ecc776491561f76f1272b6ff026ea4c648a6250bea62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.10.1 Darwin/21.2.0
|
Security for pylocalc 0.5.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.