Question about making a column read-only


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?



Following is sample code to make column B read-only.

Excel excel = new Excel();

//Protects the whole worksheet

//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;


Thanks, Laurence. Does this work only with Excel XP?


It works from Excel97 to Excel2003.


Excellent. Thank you.