我从包 simpleodspy 开始
在我想向 ods 文件添加新工作表之前,它工作得很好。
比我发现 simpleodspy 只是 odfpy 简化 api 的更好包装器。所以我猜他们对添加工作表部分进行了说明。
所以我试图弄清楚如何用 odfpy 做到这一点。
但我卡住了。
那么有人知道是否可以将工作表添加到 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')