Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
132 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.

question from:https://stackoverflow.com/questions/65599006/excel-pickling-with-openpyxl

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...