question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

unable to close(); saves a corrupted workbook

See original GitHub issue
import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')

workbook.close()

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: ‘C:\Users\DOUGHE~1.ROS\AppData\Local\Temp\tmpnpp39a_c’


I was able to write excel files yesterday; today my day began with this issue and I was not able to resolve.  I was hoping someone here may be of assistance.  

If I run workbook.close() again, I do not receive the error, but the .xlsx file does not open and says it is corrupted.

I'm not sure what happened.  I may have have closed/exited the program incorrectly.  I've read of the importance of using workbook.close(), did I create a 'write to excel ghost' living in the purgatory of my temp folder?  This issue now extends to pandas .to_excel() as well.  I am able to write to csv.   

I've restarted, reinstalled anaconda +packages, deleted all the tmp files in the temp folder, however I still receive this error.  Any help would be greatly appreciated. Thank you.



windows 10
python 2.7, 3.6, 3.7 (I had base install of anaconda py 2.7, with an additional environment of 3.6.  Reinstalled anaconda with python 3.7, 64bit.  Issue happened with all three)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
jefdoughcommented, Nov 18, 2018

The file doesn’t appear to be open in Excel. At least, excel doesn’t seem to be running in task manager and I’ve not opened it. Here is the trace of the error:

PermissionError                           Traceback (most recent call last)
<ipython-input-1-94860028b04f> in <module>()
      6 worksheet.write('A1', 'Hello world')
      7 
----> 8 workbook.close()

~\AppData\Local\conda\conda\envs\py36\lib\site-packages\xlsxwriter\workbook.py in close(self)
    304         if not self.fileclosed:
    305             self.fileclosed = 1
--> 306             self._store_workbook()
    307 
    308     def set_size(self, width, height):

~\AppData\Local\conda\conda\envs\py36\lib\site-packages\xlsxwriter\workbook.py in _store_workbook(self)
    676 
    677                 xlsx_file.write(os_filename, xml_filename)
--> 678                 os.remove(os_filename)
    679 
    680         xlsx_file.close()

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\DOUGHE~1.ROS\\AppData\\Local\\Temp\\tmpnpp39a_c'
0reactions
jmcnamaracommented, Nov 26, 2018

Thanks for the feedback. I’ll close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Repairing a corrupted workbook - Microsoft Support
Recover data from a corrupted workbook · Click the File tab, and then click Save As. · In the Save as type list,...
Read more >
Fix Excel File Error 'Unable to Save Excel Workbook'
Methods to fix ?Unable to Save Excel Workbook? error: · Open a blank Excel File. Go to File and Click Open · Go...
Read more >
How to diagnose Excel file corruption and repair workbooks
If a user opens a corrupted workbook in Excel 2013, while being oblivious that the file is damaged, the malfunction could be attributed...
Read more >
Unable to Quit Excel - Small Business - Chron.com
If you have scanned your computer for viruses and malware and determined that add-ins are not preventing Excel from closing, you should perform...
Read more >
Openpyxl Workbook.save function creates a corrupt and un ...
Openpyxl Workbook.save function creates a corrupt and un-openable Excel (.xlsx) file · The issue appears to be related to writing out ws. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found