Protecting columns

What would be the preferred/recommended method for protecting a column of cells? Should I create a range and manipulate that somehow? I see I can protect individual cells, but it doesn’t make sense I should need to loop through every cell in the column and specifically lock it down.

Is there a way to just protect a column by itself (from resizing/editing, etc).

Thanks,
John

The forums were down yesterday and had asked a similar question. I received the following response…

Yes. Aspose.Excel supports to protect worksheet from being editable. Please refer to

Cheers
Laurence Chen
Lead Developer
Aspose Nanjing Team

While this is somewhat helpful, I need to only lock down specific columns and not the entire spreadsheet. When I use the following line of code…

excel.Worksheets[0].Protect(ProtectionType.All);

The entire sheet becomes locked down from editing. I have marked the cells I need to be locked as IsLocked=true.

How do I make the IsLocked property be in effect?

btw, I am saving my Excel file as Excel 97. That might be germane to the discussion.

Thanks,
John

To lock just a column, you can try these.

1. In MS Excel, manually create a designer spreadsheet(template).
2. Select the whole worksheet and unlock all cells.
3. Select the desired column and lock it.
4. Save the file.
5. Use Aspose.Excel to import it.
6. Call this line of code:excel.Worksheets[0].Protect(ProtectionType.All);
7.Save the result file.

Then you can get it.

@jeljeljel,
Aspose.Excel is discarded and replaced by Aspose.Cells which is much advanced and rich in terms of features and performance. This new product also supports protecting columns as depicted in the following sample code:

// Create a new workbook.
Workbook wb = new Workbook();

// Create a worksheet object and obtain the first sheet.
Worksheet sheet = wb.Worksheets[0];

// Define the style object.
Style style;

// Define the styleflag object.
StyleFlag flag;

// Loop through all the columns in the worksheet and unlock them.
for (int i = 0; i <= 255; i++)
{
    style = sheet.Cells.Columns[(byte)i].Style;
    style.IsLocked = false;
    flag = new StyleFlag();
    flag.Locked = true;
    sheet.Cells.Columns[(byte)i].ApplyStyle(style, flag);

}

// Get the first column style.
style = sheet.Cells.Columns[0].Style;

// Lock it.
style.IsLocked = true;

// Instantiate the flag.
flag = new StyleFlag();

// Set the lock setting.
flag.Locked = true;

// Apply the style to the first column.
sheet.Cells.Columns[0].ApplyStyle(style, flag);

// Protect the sheet.
sheet.Protect(ProtectionType.All);

// Save the excel file.
wb.Save(dataDir + "output.out.xls", SaveFormat.Excel97To2003);

You can get more information about protecting worksheet in the following document:
Protecting Worksheets

Give a try to this new product by downloading it from the following link:
Aspose.Cells for .NET (Latest Version)

A ready to run solution is available here that can be used to test the variety of features of this new product.