我从 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/