首页 > 解决方案 > 用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')

我正在尝试一个一个地保存单元格(或者可能一次保存所有单元格),但我不太明白这_ = ...一点。

注意:如果您需要它,如果有帮助,我可以添加酸洗代码。

标签: pythonexcelautomationopenpyxl

解决方案


推荐阅读