I have attached a very simple excel file that can be used to test. Here is some sample vb.net code to test with:
- Code: Select all
Imports Spire.Xls
Module Module1
Sub Main()
Dim workbook As New Workbook
workbook.LoadFromFile("c:\locked.xls")
workbook.Worksheets("FirstSheet").Unprotect("test")
workbook.SaveToFile("c:\unlocked.xls", ExcelVersion.Version97to2003)
workbook = New Workbook
workbook.LoadFromFile("c:\unlocked.xls")
workbook.Worksheets("FirstSheet").Protect("test")
workbook.SaveToFile("c:\lock.xls", ExcelVersion.Version97to2003)
End Sub
End Module
If you try to run this code on my sample excel file, it will throw an error on the line with: workbook.LoadFromFile("c:\unlocked.xls"). The error is: ArgumentOutOfRangeException – The Number must be between 10 and 400. Parameter name: ZoomScaleNormal.
I am not making any changes to ZoomScaleNormal field, in fact I tried to set it to 100 in a couple places to try and work around this problem but it doesn’t seem to help.
The other interesting thing is that it doesn’t seem to have anything to do with the locking/unlocking that I intend to do. If you comment out the lines that do the lock and unlock, the same error occurs, even though the application is only opening the file and then saving it without doing anything. This leads me to believe that for some reason the Spire.XLS component only allows a particular excel file to be opened and saved once with the dll, as after that point it will give the ZoomScaleNormal error.
I really don't think I am doing anything too complicated. I assume this is a bug because I never touch the ZoomScaleNormal field, but maybe if someone can help me find a workaround or else show me what I am doing wrong so that I can get on with my project!
Thanks!