Cell Locking - Alternatives for Readonly effect?

Hi everyone, we’re currently trialing Aspose.Excel for an Excel
import/export process and we’re concerned about its support for
protecting individual cells.



What we’d like to achieve is to be able to set individual cells as
‘readonly’ without effecting the overall usability of the spreadsheet.



eg. using the Style.IsLocked property requires the worksheet to
be protected. Fair enough, but when the worksheet protection is
set to ProtectionType.All or Content, then also:

  • cell grouping becomes locked
  • resizing columns becomes locked
  • all cells default to IsLocked = true



    This is not the behaviour we want. We must be able to prevent a
    user from modifying the values of certain cells while preserving the
    ability to group cells, resize columns, without every cell defaulting
    to ‘IsLocked = true’.



    Any ideas? I was thinking that perhaps there may be a way to use validation instead of worksheet protection…



    Thanks,

    Seb

Please try this following sample code:

Excel excel = new Excel();
excel.Worksheets[0].Cells["A1"].PutValue(123);
excel.Worksheets[0].Cells["A1"].Style.IsLocked = false;
excel.Worksheets[0].Protect(ProtectionType.All);
excel.Save("d:\\test\\abc.xls");

You can see that A1 is editable though the worksheet is protected.

If you want to resize and group columns while the worksheet is protected, please use Protection class to set it and save the file as ExcelXP or Excel2003 format.

For more information, please check