removing the password from an XLSB file with Python

118 Views Asked by At

I have an excel file in XLSB format and I need to remove the password from the file (I know the password that is configured), at this moment I have this code but it is generating an error.

import win32com.client
import os
import shutil

Archivo_Destino  = 'M:\\Ejemplo\\Nombre_Archivo.xlsb'

pw_str  = 'Cardif2023'
pw_none = ''
excel = win32com.client.Dispatch('Excel.Application')
#excel.visual = True
excel.DisplayAlerts = False

wb = excel.Workbooks.Open(Archivo_Destino, False, False, None, pw_str)

#Establezca la contraseña de acceso al guardar.
wb.SaveAs(Archivo_Destino, None, pw_none, pw_none)
wb.close()`

El error que me esta arrojando es el siguiente

(0, 'Microsoft Excel', 'Cannot be saved under this name. The document has been opened in read-only mode.', 'xlmain11.chm', 0, -2146827284), None)

The expected result is to be able to open the protected file, remove the password and save it again

0

There are 0 best solutions below