I am developing a spreadsheet application. In the application, spreadsheet control loads Excel file using the following lines of code in the loading event.
Loading event works fine.
Also the application doesn't allow a user to edit any cells. So I added a code like this (I had to loop through worksheets since the workbook has many worksheets):
private void Spreadsheet1_WorkbookLoaded(object sender, WorkbookLoadedEventArgs args)
string keyName = string.Empty;
for (int i = 0; i < spreadsheet1.Workbook.Worksheets.Count; i++)
spreadsheet1.ProtectSheet(spreadsheet1.Workbook.Worksheets[i], "", ExcelSheetProtection.All);
keyName = spreadsheet1.Workbook.Worksheets[i].Name;
spreadsheet1.GridCollection[keyName].AllowEditing = false;
But when I edit the cell values in the run-time, sometimes exception occurs saying object reference not set.
The code for editing is as following:
for (int i = 0; i < 15; i++)
this.spreadsheet1.Workbook.Worksheets["Sheet3"].Range[i + 1, 1].Value2 = i;
I appreciate any opinion or suggestion.