一个用于导入/导出ODF文档的库。
项目描述
Odio
一个用于导入/导出ODF文档(.ods和.odt)的纯Python库。
安装
- 创建虚拟环境:
python3 -m venv venv
- 激活虚拟环境:
source venv/bin/activate
- 安装:
pip install odio
快速入门
创建电子表格
>>> import odio
>>> import datetime
>>>
>>>
>>> # Create the spreadsheet.
>>> # Version is ODF version. Can be '1.1' or '1.2'. The default is '1.2'.
>>> # Default for 'compressed' is True.
>>> with open('test.ods', 'wb') as f, odio.create_spreadsheet(
... f, version='1.2', compressed=True) as sheet:
...
... # Add a table (tab) to the spreadsheet
... sheet.append_table(
... 'Plan',
... [
... [
... "veni, vidi, vici", 0.3, 5, odio.Formula('=B1 + C1'),
... datetime.datetime(2015, 6, 30, 16, 38),
... ],
... ]
... )
导入电子表格
>>> import odio
>>>
>>>
>>> # Parse the document we just created.
>>> # Version is ODF version. Can be '1.1' or '1.2'. The default is '1.2'.
>>> with open('test.ods', 'rb') as f:
... sheet = odio.parse_spreadsheet(f)
>>>
>>> table = sheet.tables[0]
>>> print(table.name)
Plan
>>> for row in table.rows:
... print(row)
['veni, vidi, vici', 0.3, 5.0, odio.Formula('=B1 + C1'), datetime.datetime(2015, 6, 30, 16, 38)]
创建文本文档
>>> from odio import create_text, P, H, Span
>>>
>>>
>>> # Create the text document. The ODF version string can be '1.2' or '1.1'
>>> with open('test.odt', 'wb') as f, create_text(f, '1.2') as txt:
...
... txt.append(
... P("The Meditations", text_style_name='Title'),
... H("Book One", text_style_name='Heading 1'),
... P(
... "From my grandfather ",
... Span("Verus", text_style_name='Strong Emphasis'),
... " I learned good morals and the government of my temper."
... ),
... P(
... "From the reputation and remembrance of my father, "
... "modesty and a ", Span("manly", text_style_name='Emphasis'),
... " character."
... )
... )
解析文本文档
>>> import odio
>>>
>>>
>>> # Parse the text document we just created. Can be ODF 1.1 or 1.2 format.
>>> txt = odio.parse_text(open('test.odt', "rb"))
>>>
>>> # Find a subnode
>>> subnode = txt.nodes[2]
>>> print(subnode.name)
text:p
>>> print(subnode.attributes['text_style_name'])
Text Body
>>> print(subnode)
odio.P(' From my grandfather ', odio.Span('Verus', text_style_name='Strong Emphasis'), ' I learned good morals and the government of my temper. ')
回归测试
- 安装
tox
:pip install tox
- 运行
tox
:tox
发布Odio
运行tox
确保所有测试通过,然后更新发布说明,然后执行:
git tag -a x.y.z -m "版本 x.y.z"
rm -r build; rm -r dist
python -m build
twine upload --sign dist/*
发布说明
版本 0.0.23,2024-05-22
- 在写入电子表格时,将
decimal.Decimal
解释为数字。
版本 0.0.22,2021-02-08
- 将
<text:line-break/>
替换为换行符。
版本 0.0.21,2021-02-05
- 查找文本不应该导致返回值为
None
。
版本 0.0.20,2021-02-04
- 文本应出现在单元格内的
<text:p>
元素的content中。
版本 0.0.19,2021-02-04
- 在文本元素的content中出现换行符时,现在它们被替换为
<text:line-break/>
元素。这意味着换行符现在在电子表格中显示,而之前则不会。
版本 0.0.18,2019-11-29
- 性能改进:而不是使用
xml.sax.saxutils
版本的escape
和quoteattr
,我已经将它们复制到Odio的源代码中,但删除了不需要的实体代码。
版本 0.0.17,2018-08-19
- 当解析文本类型的电子表格单元格时,如果值不在属性中,则递归地使用元素内容中的下一个节点。
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分发
odio-0.0.23.tar.gz (104.1 kB 查看哈希值)
构建分发
odio-0.0.23-py3-none-any.whl (11.2 kB 查看哈希值)
关闭
odio-0.0.23.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ffa0b977db3aa6af095c29bb48ebbeb109e807db634bc581bf5d162fd3b5a6e1 |
|
MD5 | 337f8756b53cae5f6be991027183eb76 |
|
BLAKE2b-256 | 44a0a9d8aa8d3d0029774861c0c163ab0ed02e426640e7ffe6873bfab51bba22 |
关闭
odio-0.0.23-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 15c923f35027da15051c977f256fa0891f2e0d74a8adf42dbcc620c3515a8f30 |
|
MD5 | e058b503905624fb4cf452e376ab6d6c |
|
BLAKE2b-256 | 9b965a09ffff31bb728d5cff4cfffc46daf49026f1d8822fab3c7189cc789d75 |