Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
openpyxl Output .xlsx Not Opening
Post Body

My Python script uses openpyxl to open an Excel template .xlsx file and fills in what I need before saving as a new .xlsx file. However when I try to open the file I get a prompt that reads:

"Excel cannot open the file because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file."

However, when I change the output file format to .xls I get a prompt that reads:

"The file you are trying to open is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?"

From the .xls output all script executions are there. I'm just not sure why the output format file extension isn't working. Furthermore, if I try to save that .xls file as a .xlsx it generates the initial prompt. On my end, I've checked that my openpyxl is updated, my friend ran the script and the Numbers App didn't care about the extension and was able to open it without issue.

Below is my function that interacts with Excel:

    def to_excel():
        import openpyxl
        srcfile = openpyxl.load_workbook('Worksheet.xlsx',read_only=False, keep_vba= True)
        sheetname = srcfile['Sheet1']
        sheetname['F5'] = str(patient.last_name   ', '   patient.first_name)
        sheetname['F6'] = str(patient.sample_id)
        sheetname['C6'] = str(today_date)
        sheetname['D8'] = str(patient.factor)
        sheetname['D17'] = tech_initials

        if patient.form == "Clotting":
            sheetname['G17'] = "Y"
        else:
            sheetname['G18'] = "Y"

        filename = 'Nijmegen ' patient.form '.'   patient.sample_id   '.'   today_date   '.xlsx'
        filename = str(filename)

        srcfile.save(filename)

Author
User Suspended
Account Strength
0%
Suspended 6 months ago
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
n/a
Link Karma
1,491
Comment Karma
5,378
Profile updated: 4 days ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago