Я пытался сделать, это создать файл Excel и сохранить файл Excel, но когда я пытаюсь сохранить его, выдает ошибку.
Я попытался openpyxl, чтобы сохранить файл Excel.
import openpyxl
wb = openpyxl.Workbook()
print(type(wb))
wb.save('balances.xlsx')
C:\Main\python.exe "C:/Users/owly/OneDrive/Desktop/python project case1.py"
Traceback (most recent call last):
File "C:/Users/owly/OneDrive/Desktop/python project case1.py", line 21, in <module>
<class 'openpyxl.workbook.workbook.Workbook'>
wb.save('balances.xlsx')
File "C:\Main\lib\site-packages\openpyxl\workbook\workbook.py", line 408, in save
save_workbook(self, filename)
File "C:\Main\lib\site-packages\openpyxl\writer\excel.py", line 293, in save_workbook
writer.save()
File "C:\Main\lib\site-packages\openpyxl\writer\excel.py", line 275, in save
self.write_data()
File "C:\Main\lib\site-packages\openpyxl\writer\excel.py", line 67, in write_data
archive.writestr(ARC_APP, tostring(props.to_tree()))
File "C:\Main\lib\zipfile.py", line 1773, in writestr
"Can't write to ZIP archive while an open writing handle exists."
ValueError: Can't write to ZIP archive while an open writing handle exists.
Exception ignored in: <function ZipFile.__del__ at 0x0C6E85D0>
Traceback (most recent call last):
File "C:\Main\lib\zipfile.py", line 1789, in __del__
self.close()
File "C:\Main\lib\zipfile.py", line 1798, in close
raise ValueError("Can't close the ZIP file while there is "
ValueError: Can't close the ZIP file while there is an open writing handle on it. Close the writing handle before closing the zip.
Process finished with exit code 1