python - 通过 python 将工作表添加到 ods 文件

标签 python python-2.7 ods

我从 simpleodspy 包开始

它工作得很好,直到我想将新工作表添加到 ods 文件中。

我发现 simpleodspy 只是 odfpy 的一个更好的包装器,可以简化 api。所以我猜他们是添加了一个表部分。

所以我试图弄清楚如何使用 odfpy 来做到这一点。

但我卡住了。

有人知道是否可以向 ods 文件添加工作表吗?

如果是的话怎么办?

最佳答案

以下是添加新工作表的示例代码:

from odf.opendocument import load
from odf.table import Table
from odf.table import TableCell
from odf.table import TableRow
from odf.text import P

#loading it
book = load('your.ods')
#create a new sheet in memory
sheet = Table(name="test sheet")
#create a new row
tablerow=TableRow()
#create a new cell
cell=TableCell()
#fill-in a cell
cell.addElement(P(text="hello world"))
#add a cell to the row
tablerow.addElement(cell)
#add the row to the sheet
sheet.addElement(tablerow)
#adding the new to the book
book.spreadsheet.addElement(sheet)
#save it
book.save('your_new.ods')

关于python - 通过 python 将工作表添加到 ods 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28793819/

相关文章:

python - 在 NLTK 中实现词袋朴素贝叶斯分类器

python - Scrapy View 返回空白页

python - Python 中是否有相当于 Unix 中 vfork 的工具?

python - 将文件上传到保管箱时的进度条

toolkit - ODF工具包: Get string value from cell without the comment from ods or odf dodument

java - .ods 电子表格到 JTable

python - 设计我的票务 API

python - 如何获得多类分类问题中每个类的精度分数?

使用自定义名称创建 Python 动态函数

pdf - 为什么 varnum 停止 sas 中的 proc 内容?