python - 在 Openpyxl 中,如何用工作表中的 Cell 对象替换单元格?
问题描述
所以我有一个函数,它接受一个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)
这将创建一个绑定到特定工作表但没有您必须提供的任何坐标的单元格。如果您处于只写模式,则必须使用 aWriteOnlyCell
并将其传递给工作表的append()
方法。
推荐阅读
- autodesk-forge - Forge Viewer 作为另一个查看器的扩展
- android - 如何在 Android TV Box (Android 9) 上使用 camera2 API 使用双 USB 摄像头
- ios - 类型错误 null 不是 React Native FBSDK 中的对象(评估“ShareDialog.canShow”)
- java - 如何“模块化”我的 Bamboo Specs Java 文件的部分?
- node.js - 使用 Jest 测试框架调用 fetch(url) 时如何根据 url 模拟变量响应?
- java - Transport.send 不适用于 javax.mail 库
- node.js - Cosmos DB 触发器绑定未注册?
- batch-file - 无法在批处理脚本中正确设置变量
- c++ - C++ 中的树实现:无法将节点转换为 int* 问问题
- java - 显示文本中最常用的词