Hi i wnat to block a specific cell sellection i know theres an option
to block cell sellection on excel level "xlNoSelection"
who can i do the same thing with aspose?
thanks
Hi i wnat to block a specific cell sellection i know theres an option
to block cell sellection on excel level "xlNoSelection"
who can i do the same thing with aspose?
thanks
Hi,<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” />
Thank you for considering Aspose.
Well, you can use different worksheet and cells protection option provided by Aspose.Cells to achieve your desired results. Following sample code protects the worksheet contents from getting edited and also sets the advance protection option of not allowing cells to be selected (as per xlNoSelection option).
``
Sample Code:
//Instantiating a Workbook object
Workbook excel = new Workbook();
//Opening the Excel file
excel.Open("C:\\book1.xls");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = excel.Worksheets[0];
//protecting a worksheet with password
worksheet.Protect(ProtectionType.Contents, "aspose", "");
//disallowing users to select locked cells of the worksheet
worksheet.Protection.IsSelectingLockedCellsAllowed = false;
//disallowing users to select unlocked cells of the worksheet
worksheet.Protection.IsSelectingUnlockedCellsAllowed = false;
//Saving the modified Excel file Excel XP format
excel.Save("C:\\output.xls");
Also, to stop the selection of a specific cell, you can use the Cell.Style.isLock = true and use worksheet.Protection.IsSelectingLockedCellsAllowed = false. But in this scenario please remember that by default all the cells in a worksheet have the Style.isLocked property set to true, so if you want any of the cell to get selected you have to set its isLocked property to false manually through the code. Also, Excel’s advance protection only takes effect when you protect the worksheet.
Please see the following links for different other advance protection options,
Thank You & Best Regards,
Save Edit
Thank you for the fast replay
but wont this code lock the hole page ?
i want to lock a single cell
Hi,
Thank you for considering Aspose.
Well, to restrict the selection of a specific cell, you can use the Cell.Style.isLock = true and use worksheet.Protection.IsSelectingLockedCellsAllowed = false. But in this scenario please remember that by default all the cells in a worksheet have the Style.isLocked property set to true, so you have to set the isLocked property of the cells you want to get selected to false manually through the code. Also, Excel’s advance protection only takes effect when you protect the worksheet. Please see the following Sample code in this regard,<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” />
Sample Code:
Workbook excel = new Workbook();
//Opening the Excel file
excel.Open(“C:\book1.xls”);
//Accessing the first worksheet in the Excel file
Worksheet worksheet = excel.Worksheets[0];
//Style Object
Style style;
//Style Flag
StyleFlag flag;
//Making all the Cells un-Locked
for (int i = 0; i <= 255; i++)
{
style = worksheet.Cells.Columns[(byte)i].Style;
style.IsLocked = false;
flag = new StyleFlag();
flag.Locked = true;
worksheet.Cells.Columns[(byte)i].ApplyStyle(style, flag);
}
style = worksheet.Cells.Rows[0].Style;
style.IsLocked = true;
flag = new StyleFlag();
flag.Locked = true;
worksheet.Cells[“A10”].Style.IsLocked = true;
//protecting a worksheet with password
worksheet.Protect(ProtectionType.Contents, “aspose”, “”);
//disallowing users to select locked cells of the worksheet
worksheet.Protection.IsSelectingLockedCellsAllowed = false;
//Saving the modified Excel file
excel.Save(“C:\output.xls”);
Please see the following links for different other advance protection options,
Also, please see the following thread for more details on your issue,
Thank You & Best Regards,