简体   繁体   English

openpyxl保存只读工作簿

[英]openpyxl save read-only workbook

I can't seem to find a solution to that problem. 我似乎找不到解决这个问题的办法。

How can I close a workboook I opened using openpyxl? 如何关闭我使用openpyxl打开的workboook?

I opened a workbook in read-only mode in order to read the information, not change it. 我以只读模式打开了一个工作簿,以便读取信息,而不是更改它。 Now when my code runs it is impossible to save the excel document if someone is using it at the same time. 现在,当我的代码运行时,如果有人同时使用它,则无法保存excel文档。 I get the following mistake: 我得到以下错误:

'path + filename' is currently in use. 'path + filename'目前正在使用中。 Try again later. 稍后再试。

The way to close the workbook seems to be wb.save("filename") . 关闭工作簿的方法似乎是wb.save("filename") But this doesn't apply to me because I open it in read-only mode. 但这不适用于我,因为我以只读模式打开它。

What can I do? 我能做什么?

Thank you for your help! 谢谢您的帮助!

From the documentation: OpenPyXL documentation 从文档: OpenPyXL文档

close() Close workbook file if open. close()如果打开则关闭工作簿文件。 Only affects read-only and write-only modes. 仅影响只读和只写模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM