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.
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)
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...