所以我有一个函数,它接受一个Cell
对象并吐出一个处理过的cell
:
from openpyxl.cell.cell import Cell
cell = Cell(ws)
def process_cell(cell):
# Add style to cell
return cell
但是我不能这样做:
cell = process_cell(cell)
ws['A1'] = cell
错误为:
raise ValueError("Invalid column index {0}".format(idx))
ValueError: Invalid column index None
问题在于:cell = Cell(ws)
这将创建一个绑定到特定工作表的单元格,但没有任何必须提供的坐标。如果您处于只写模式,则必须使用WriteOnlyCell
并将其传递给工作表的append()
方法。