Can someone please post sample code to make an entire column read-only? (Is that even possible in Excel?)
If there is a solution to this, what version of Excel is required for this functionality to work?
Thanks.
Can someone please post sample code to make an entire column read-only? (Is that even possible in Excel?)
If there is a solution to this, what version of Excel is required for this functionality to work?
Thanks.
Following is sample code to make column B read-only.
Excel excel = new Excel();
//Protects the whole worksheet
excel.Worksheets[0].Protect(ProtectionType.All);
//Unlocks all columns except column B
for(int i = 0; i < 256; i ++)
{
if(i != 1)
{
Style style = excel.Worksheets[0].Cells.Columns[(byte)i].Style;
style.IsLocked = false;
excel.Worksheets[0].Cells.Columns[(byte)i].Style = style;
}
}
excel.Save("d:\\test\\abc.xls");
Thanks, Laurence. Does this work only with Excel XP?
It works from Excel97 to Excel2003.
Excellent. Thank you.