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

How can I lock the value of cells and change the width of the column at the same time?

Last post 06-22-2009, 12:22 PM by Amjad Sahi. 3 replies.
Sort Posts: Previous Next
  •  06-22-2009, 4:58 AM 184798

    How can I lock the value of cells and change the width of the column at the same time?

     

    Hi Admin:

     

          

    I want the value of some cells can be changed by user in the Aspose.Grid.Web and othders can't;At the same time,the width of column can be changed.

    So, I do it as following step:

    1.set some cells to lock and some cells to unlock.
    2.load the Excel file in Aspose.Grid.Web.
    3.set sheet.IsProtected = true;

    result:  the value of some cells can be changed by user in the Aspose.Grid.Web and othders can't;But the width of column can't be changed.

    if I set sheet.IsProtected = false;the width of column can be changed,but the value of all cells can be changed!

     

    How can achieve my request,and which attribute has this feature;

     

     
  •  06-22-2009, 9:34 AM 184885 in reply to 184798

    Re: How can I lock the value of cells and change the width of the column at the same time?

    Hi,

    Well, when you protect a sheet, you cannot change the width or format columns / rows, this behavior is same as MS Excel.

    I think you may try the following code for your task, you set all the cells read-only first then you may specify your editable range of cells, you may change the code accordingly:

    WebWorksheets sheets = GridWeb1.WebWorksheets;

    // Sets all cells readonly first.

    sheets[0].SetAllCellsReadonly();

    // Starts from row 3, column 2, 11 rows 1 colum i.e., C4:C13.... total 10 cells.

    sheets[0].SetEditableRange(3, 2, 11, 1);

    WebCells cells = sheets[0].Cells;

    //Set the A1 cell editable as well.

    cells["A1"].IsReadonly = false;

     

     

    Thank you.


    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  06-22-2009, 11:49 AM 184911 in reply to 184885

    Re: How can I lock the value of cells and change the width of the column at the same time?

    Well, I see your way.

    But in my system flow,I dont't know which cells need be edit by user in advance;

    The user need to set  the formart of cells(e.g A1:Unlock;B1:Unlock;C1:Lock) in this Excel file before I load this file in my system by aspose.grid.web.

    As your talk, If I want change the width of the clounm, I need set sheet.IsProtected = false;So,When I set sheet.IsProtected = false, How can I  know which cell's attribute is "Lock" or "Unlock"?

    By the way, If I set the sheet.IsProtected = true, the user will can't change the value of cell when the cell is "Lock" in the Excel file.

     

     
  •  06-22-2009, 12:22 PM 184915 in reply to 184911

    Re: How can I lock the value of cells and change the width of the column at the same time?

    pingmic:

    As your talk, If I want change the width of the clounm, I need set sheet.IsProtected = false;So,When I set sheet.IsProtected = false, How can I  know which cell's attribute is "Lock" or "Unlock"?

    Well, you may loop through all the cells and use WebCell.IsLocked property to check whether a cell is locked or not, see the following sample code:

    WebWorksheet sheet = GridWeb1.WebWorksheets[0];

    WebCells cells = sheet.Cells;

    for (int i = 0; i <= cells.MaxRow; i++)

    {

    for (int j = 0; j <= cells.MaxColumn; j++)

    {

    WebCell cell = cells[i, j];

    Response.Write("Cell:"+ cell.Name + ",Lock:" + cells[i,j].IsLocked.ToString() + "; ");

    }

    }

     

    pingmic:

    By the way, If I set the sheet.IsProtected = true, the user will can't change the value of cell when the cell is "Lock" in the Excel file.

    Yes, that is true for MS Excel.

     

    Thank you.


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