问题
Using the interop classes in C# I was able to protect a workbook for reading and writing with a password.

But I want users to be able to open the sheet as read-only.

Is this possible without using the Workbook.SaveAs method?
Protecting a workbook with a password (picture 1) I'm using the Workbook.Password property.
回答1:
According to MSDN, the only way to change the Workbook.ReadOnlyRecommended
property is with the Workbook.SaveAs
method.
In needed precisely what you're looking for a while ago (i.e. setting it without saving), but had to give in and use SaveAs
. To my knowledge it's the only way.
回答2:
Use Workbook.Open()
. The 3rd parameter is the read only property.
Plus a link to to the MSDN
来源:https://stackoverflow.com/questions/13138099/excel-protect-workbook-with-password-but-allow-readonly