0

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" ?

Rudolph
  • 1
  • 2

2 Answers2

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
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:

Change file to read-only mode in Python

Rudolph
  • 1
  • 2