Free Support Forum - aspose.com

Unlock all the cells


#1

Hi,
when i try to unlock all the cells of a worksheet with the code below, only the first 255 columns are unlocked ?!
thanks in advance for your help.

namespace testExcel
{
class Program
{
static void Main(string[] args)
{
License lic = new License();
lic.SetLicense(“Aspose.Total.lic”);
Workbook doc = new Workbook();
WorksheetCollection sheets = doc.Worksheets;
Worksheet sheet;
Style style;
StyleFlag styleflag;

        // Loop through all the columns in the worksheet and unlock them.
        sheet = sheets[0];
        for (int j = 0; j <= 16385; j++)
        {
            style = sheet.Cells.Columns[(byte)j].Style;
            style.IsLocked = false;
            styleflag = new StyleFlag();
            styleflag.Locked = true;
            sheet.Cells.Columns[(byte)j].ApplyStyle(style, styleflag);
        }
        doc.Save("result.xlsx");
    }
}

}


#2

@tparassin,

Thanks for the sample code and details.

See the updated sample code which works fine as I tested. For your information, a sheet can have a maximum of 16384 columns. Also parsing column indices using byte type won’t go beyond 256:
e.g
Sample code:

Workbook doc = new Workbook();
            WorksheetCollection sheets = doc.Worksheets;
            Worksheet sheet;
            Style style;
            StyleFlag styleflag;
            
            // Loop through all the columns in the worksheet and unlock them.
        sheet = sheets[0];
        for (int j = 0; j < 16384; j++)
        {
            style = sheet.Cells.Columns[j].Style;
            style.IsLocked = false;
            styleflag = new StyleFlag();
            styleflag.Locked = true;
            sheet.Cells.Columns[j].ApplyStyle(style, styleflag);
        }
        doc.Save("e:\\test2\\out1.xlsx");

Hope, this helps a bit.


#3

thank you for the reply.
it works fine !

i had got the code from one of your sample and hadn’t noticed the byte conversion.


#4

@tparassin,

Good to know that your issue is sorted out by the suggested code.

Yes, may be the sample code suited for XLS (Excel 97-2003) file format.