Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

python - excel pickling with openpyxl

I have written this code, but on the line _ = ws.cell(column == get_column_letter(cll[0][0]), row == (cll[0][1]), value == cll[1]) it returns an error that I do not understand!

Here's the code:

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')

I'm trying to save the cells one by one(or maybe everything at once) but I don't really understand the _ = ... bit.

NOTE: If you need it, I can add the pickling code if it helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...