I have searched and searched and I cannot find what is wrong with my script. I keep getting an error that openpyxl only works on certain types of file extensions. I am trying to add a column to an xlsx file. Here is my script. What is wrong here?
filename1 =r"C:\Users\user1\Documents\test.xlsx"
wb8 = openpyxl.load_workbook("filename1")
ws8 = wb8.worksheets["Sheet1"]
ws8.insert_cols(21)
wb8.save(str(filename1))
You are creating a
filename1
variable that is the location of your Excel file. When you use it, you don't use a string version of it. Just callfilename1
.