Python Error : read excel file(included xlsx, ...)

 An internal security tool caused a problem because xlsx was locked into a security program.
In conclusion, the following method was used, but it could not be solved.

error handling step...

code : occurred openpyxl error  

< zipfile.BadZipFile: File is not a zip file >


import openpyxl

 

if __name__ == "__main__" :

    wb = openpyxl.load_workbook("contents.xlsx")

    print(f"{wb}")

error

zipfile.BadZipFile: File is not a zip file


The following methods were used to solve this problem caused by in-house security tools.


step 1. encoding error 

< UnicodeDecodeError: 'cp949' codec can't decode byte 0xf0 in position 20: illegal multibyte sequence >


import openpyxl

import xlrd #add

if __name__ == "__main__" :

    file = open("contents.xlsx","r")

    wb = xlrd.open_workbook(file_contents=file.read()) #add

    print(f"wb")

 

error

wb = xlrd.open_workbook(file_contents=file.read())

UnicodeDecodeError: 'cp949' codec can't decode byte 0xf0 in position 20: illegal multibyte sequence



step 2. encoding error : add utf-8

< TypeError: an integer is required (got type str) >


import openpyxl

import xlrd

if __name__ == "__main__" :

    file = open("contents.xlsx","r", "utf-8")

    wb = xlrd.open_workbook(file_contents=file.read())

    print(f"wb")

 

error

file = open("contents.xlsx","r","utf-8")

TypeError: an integer is required (got type str)

must be specified Encoding type like "utf-8" as "python2 -> python3".



step 3. ???
< TypeError: an integer is required (got type str) >

import openpyxl

import xlrd

if __name__ == "__main__" :

    file = open("contents.xlsx","r", encoding="utf-8")

    wb = xlrd.open_workbook(file_contents=file.read())

    print(f"wb")

 

error

file = open("contents.xlsx","r", encoding="utf-8")

TypeError: an integer is required (got type str)

"utf-8-> encoding="utf-8"



It still hasn't been resolved.
Does anyone know how to read the Excel file that was locked due to the security tool?


#python error #read excel #openpyxl #zipfile.BadZipFile #encoding error

No comments:

Post a Comment

Apartment Buying Guide 2025: Shocking Red Flags You Should NEVER Ignore!

 🏙️ Apartment Buying Guide 2025: Shocking Red Flags You Should NEVER Ignore! 🚨 Are you thinking about buying an apartment in 2025? 🏢  It’...