Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

Column Readonly

Last post 06-18-2009, 2:02 AM by Amjad Sahi. 1 replies.
Sort Posts: Previous Next
  •  06-17-2009, 9:03 PM 184358

    Column Readonly .NET

    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
    Filed under: column readonly.
     
  •  06-18-2009, 2:02 AM 184373 in reply to 184358

    Re: Column Readonly

    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:  http://www.aspose.com/demos/visual-components/aspose.grid/csharp/demos/data-bind/databind2.aspx

    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.


    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
View as RSS news feed in XML