I saved an an excel file as "Read-only recommended" with name "myfile". Then I want to open it using python xlwings xw.Book(myfile). How do I pass the argument "yes" or "no" ?
Asked
Active
Viewed 909 times
2 Answers
0
The proper answer would be to use the IgnoreReadOnlyRecommended
flag, see here, but I couldn't make that work (but maybe it works for you?).
So the only answer I can give you for now is how to open it in read-only, but not how to open it with read-only=False
:
import xlwings as xw
if not xw.apps:
app = xw.App()
else:
app = xw.apps.active
app.display_alerts = False
wb = xw.Book(r'myfile')
app.display_alerts = True

Felix Zumstein
- 6,737
- 1
- 30
- 62
-
Neither the first nor the second method worked for me – Rudolph Nov 06 '18 at 18:56
0
A better solution turns out to be to go around both Excel and xlwings:
import os
from stat import S_IREAD, S_IRGRP, S_IROTH, S_IWUSR
os.chmod(myfile, S_IWUSR|S_IREAD) # turn the file to write mode
os.chmod(myfile, S_IREAD|S_IRGRP|S_IROTH) # turn back to read only
This has already been discussed elsewhere:

Rudolph
- 1
- 2