Need to save my file with readonly recommended.

55 views
Skip to first unread message

steveo

unread,
Feb 2, 2012, 12:43:50 PM2/2/12
to python-excel
This is getting critical for us. We have files that need to be saved
with readonly recommended. The manual approach is to say:

File -> SaveAs -> Tools -> General -> Then check the ReadOnly
Recommended box.

I'm not the guy coding this up but I'm ok with python. I need to
either know how to create a new file that has this setting, or how to
copy from a blank file that has this setting that I can then write to.

Does this make sense?

Help would be greatly appreciated.

TIA

Steve Orr

John Machin

unread,
Feb 5, 2012, 1:57:20 AM2/5/12
to python...@googlegroups.com


On Friday, February 3, 2012 4:43:50 AM UTC+11, steveo wrote:
This is getting critical for us. We have files that need to be saved
with readonly recommended. The manual approach is to say:

File -> SaveAs -> Tools -> General -> Then check the ReadOnly
Recommended box.

I'm not the guy coding this up but I'm ok with python. I need to
either know how to create a new file that has this setting, or how to
copy from a blank file that has this setting that I can then write to.

If you are driving Excel yourself e.g with pywin32 COM,  then you should find that there is a ReadOnlyRecommended optional arg on the workbook SaveAs method.

If you are using xlwt:

option 1: There's a release being made real soon now. After the release I'll add not only the read_only_recommended caper but also the write_reservation password and user_name caper -- this latter prompts the user for a password if they want to open the workbook in modify mode; the idea is that the file creator hands out the password only to trusted users. Seems a much better idea to me. The two capers use the same record (FILESHARING) in the xls file so it's better to do both at once.

option 2: You get your boss to donate some brass to buy tranquilisers for the folk who want a release real soon, and I'll do it in the current release.

option 3: You do a gross hack on Workbook.py:

between these two lines:

        before += self.__write_access_rec()
        before += self.__codepage_rec()

insert the following:

        before += struct.pack('<5H', 0x005B, 6, getattr(self, 'read_only_recommended', 0), 0, 0) # untested

Then you can use it like this:

wb = xlwt.Workbook()
...
wb.read_only_recommended = True
...
wb.save('foo.xls')

HTH,
John



John Machin

unread,
Feb 5, 2012, 4:03:15 AM2/5/12
to python...@googlegroups.com

 # tested:

        if getattr(self, 'read_only_recommended', 0):
            import struct
            before += struct.pack('<5H', 0x005B, 6, 1, 0, 0)

Steven W. Orr

unread,
Feb 14, 2012, 3:40:27 PM2/14/12
to python...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups
> "python-excel" group.
> To view this discussion on the web, visit
> https://groups.google.com/d/msg/python-excel/-/NaG6rH9aIE8J.
> To post to this group, send an email to python...@googlegroups.com.
> To unsubscribe from this group, send email to
> python-excel...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/python-excel?hl=en-GB.

I just wanted to thank you for the patch. I ramrodded it to the people who
needed it, it was applied to the code and used by the application. It worked
first time. Looking forward to the next release where it will be incorporated.

Isn't the internet great?

:-)


--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net

John Machin

unread,
Feb 14, 2012, 4:37:04 PM2/14/12
to python...@googlegroups.com


On Wednesday, February 15, 2012 7:40:27 AM UTC+11, steveo wrote:
On 2/5/2012 4:03 AM, John Machin wrote:
>
> # tested:
>
> if getattr(self, 'read_only_recommended', 0):
>     import struct
>     before += struct.pack('<5H', 0x005B, 6, 1, 0, 0)

 
I just wanted to thank you for the patch. I ramrodded it to the people who

needed it, it was applied to the code and used by the application. It worked
first time. Looking forward to the next release where it will be incorporated.

Thanks for the thanks.

It wasn't a patch; it was a gross hack. It won't be incorporated. Instead there will be a principled enhancement, which will include the write protection password facility.

Cheers,
John
 

Reply all
Reply to author
Forward
0 new messages