python - 用openpyxl进行excel酸洗
问题描述
我已经写了这段代码,但是_ = ws.cell(column == get_column_letter(cll[0][0]), row == (cll[0][1]), value == cll[1])
它返回了一个我不明白的错误!
这是代码:
from openpyxl import Workbook as Wb
from openpyxl.utils import get_column_letter
import dill
def unpickle_exl(file_name, unpkld_file_name):
"""
unpickles a pickled excel file.
for file_name (current file name) suffix the name with .dll
likewise, for unpkld_file_name (file name to be made after unpickling) suffix your name with .xlsx
failiure to do so will result in an error.
please do not leave the second argument empty: please enter '' instead
"""
if file_name[len(file_name)-4:] != '.dll':
raise SyntaxError("file_name does not end with suffix .dll")
if unpkld_file_name != '' and unpkld_file_name[len(unpkld_file_name)-5:] != '.xlsx':
raise SyntaxError("unpkld_file_name does not end with suffix .xlsx")
if unpkld_file_name == '':
unpkld_file_name == unpkld_file_name.replace(".dll", ".xlsx")
try:
with open(file_name, 'rb') as d:
pkld_sprdsht = dill.load(d)
except OSError:
raise ReferenceError("File " + str(filename) + "does not exist.")
print(pkld_sprdsht)
wb = Wb()
for obj in pkld_sprdsht:
ws = wb.create_sheet()
for sht in obj:
for cll in sht:
_ = ws.cell(column == get_column_letter(cll[0][0]), row == (cll[0][1]), value == cll[1])
wb.save(filename = unpkld_file_name)
def test():
unpickle_exl('xlsx_to_dll test sprdsht.dll', 'xlsx_to_dll test sprdsht_copy.xlsx')
我正在尝试一个一个地保存单元格(或者可能一次保存所有单元格),但我不太明白这_ = ...
一点。
注意:如果您需要它,如果有帮助,我可以添加酸洗代码。
解决方案
推荐阅读
- c# - xaml c#中的可观察集合静态资源
- python - 无法理解时间表
- php - 如何在元素属性更改上使用 JQuery 事件委托?
- html - 如何在菜单项悬停时显示或隐藏 div 内容(选择)
- javascript - 如何使用 JavaScript 创建 Chrome 扩展来隐藏或删除页面元素?
- java - Java 网页 - 打开可编辑的 Excel 并保存
- c - 将数组传递给函数。格式错误?C
- postgresql - TypeORM 使用 ST_GeomFromGeoJSON 插入 Geometry 类型
- javascript - JS - 测验将用户重定向到页面取决于他们的测验分数
- java - 1-100,000 的友好数字的总和(AP CS-A)