Hi Everyone,
I am importing an excel file to the Aspose Grid in an web application. The grid has few sheets. Every sheets got more than 2 columns. My codes, where I am getting the exceptions are as follows.
grdWeb.WebWorksheets.ImportExcelFile(fileName); //grdWeb is the Aspose grid.
WebWorksheet wrksht = grdWeb.WebWorksheets[grdWeb.ActiveSheetIndex];
wrksht.BindColumns[1].IsReadOnly = true; // ==>Throwing Exception
The exception is: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I have data inside the Active Sheet of the excel file and have more columns then represented in the index inside the BindColumns - collection. Am I missing something?
I also had the following code to make the Aspose.Grid column readonly. This functions fine.
wrksht.SetReadonlyRange(0, 0,100, 1);
I commented the above code, because the 100(int rows) are hardcoded. I will be glad to know the way to find the number of rows in an active sheet. So that I can replace the 100 with the variable having the row count.
Regards
Prithiraj Sengupta
Hi,
prithiraj:
I am importing an excel file to the Aspose Grid in an web application. The grid has few sheets. Every sheets got more than 2 columns. My codes, where I am getting the exceptions are as follows.
grdWeb.WebWorksheets.ImportExcelFile(fileName); //grdWeb is the Aspose grid.
WebWorksheet wrksht = grdWeb.WebWorksheets[grdWeb.ActiveSheetIndex];
wrksht.BindColumns[1].IsReadOnly = true; // ==>Throwing Exception
The exception is: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I have data inside the Active Sheet of the excel file and have more columns then represented in the index inside the BindColumns - collection. Am I missing something?
Well, WebWorksheet.BindColumn only works when you are using Data Binding feature of the GridWeb, otherwise, you will get such exception. See the data binding demo for reference:
prithiraj:I also had the following code to make the Aspose.Grid column readonly. This functions fine.
wrksht.SetReadonlyRange(0, 0,100, 1);
I commented the above code, because the 100(int rows) are hardcoded. I will be glad to know the way to find the number of rows in an active sheet. So that I can replace the 100 with the variable having the row count.
Please use WebCells.MaxRow and WebCells.MaxColumn to get the maximum/last row and column indexes which has data / style.
For your need, you can change your code:
..................
Aspose.Grid.Web.Data.WebCells cells = wrksht.Cells;
wrksht.SetReadonlyRange(0, 0, cells.MaxRow+1, 1);
//OR you may use as following:
WebCells cells = wrksht.Cells;
//Set the first column as Read-only.
for (int r = 0; r <= cells.MaxRow; r++)
{
cells[r, 0].IsReadonly = true;
}
Thank you.