using xlrd: Error attempting to delete file after wb.release_resources()
OS: Windows 10
This is more of a Jython question that pure Sikuli, but I have not had success in finding answers elsewhere. Hoping that you guys here may be able to help!
My script is attempting to do the following:
1.) Download an Excel workbook (XLSX)
2.) Move the file from the WIndows "downloads" folder to a shared folder
3.) Split the individual worksheets from the original workbook into their own workbooks
4.) Delete the original XLSX file
The error that I am getting is at step #4. It is an error type of "OSError" that says this:
"unlink(): an unknown error occurred: C:\screenshots\SS Case Cancellation Monthly Report.xlsx"
Note that the worksheet splitting is successful. The only failure is the file deletion.
I am using the xlrd library to manipulate the Excel files. The error always occurs on the "os.remove" line.
Here is the portion of my function that is handling the worksheet splits and file deletion:
def SplitWorksheets
import xlrd
from xlutils.copy import copy
print "Attempting to split worksheets..."
try:
x = 0
base = os.path.
#print base
if not os.path.
wb = xlrd.open_
for sheet in wb.sheets(): #cycles through each sheet in the workbook
x += 1
#Closes the workbook, allowing it to be deleted.
wb = None
print "Preparing to delete file: " + self.NewFile
#Delete original file.
print "Workbook deleted -> " + self.NewFile
except:
print ErrorText
else:
dpmsg = "=*=*=*=*=* " + str(x) + " Worksheets Split from Workbook *=*=*=*=*="
print dpmsg
finally:
#######
Any help is greatly appreciated!
Best regards,
Ron Turrentine
Question information
- Language:
- English Edit question
- Status:
- Expired
- For:
- SikuliX Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply: