We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Lock and formatting cells

Hi,

I have 2 questions

1. I would like to set column formatting to text.

I got an answer in the forum how to set it for specific cell, and i need this formatting to all column.
I can do it or i need to make this treatment to all cells till max int for this column?

2. How can i lock column for editing?
The lock should disable typing and paste values to cell

Thanks

Shemesh




Hi,

1) Yes, you may set formatting for a complete column in the worksheet. You should create a Style object, specify your formatting attribute for the Style object, create StyleFlag object and make the relevant attributes on with respect to Style formattings. Now use Column.ApplyStyle(style, flag) method to set the formatting for the column. Repeat this procedure (or loop through your desired column indexes in the sheet).

See the topic for your reference:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/formatting-rows-columns.html

2) Please see the topic (especially check the description under “Protect a Column in the Worksheet” sub-topic): http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/protecting-worksheets.html

Also for advanced protection settings, see the topic:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/advanced-protection-settings-since-excel-xp.html

Thank you.

hi amjad,
i tried the follow:

Style colStyle = sheet.Cells.Columns[colIndex].Style;
StyleFlag flag= new StyleFlag();
flag.NumberFormat = false;
//Set the formating on the as text formating
colStyle.Number = 49;
sheet.Cells.Columns[colIndex].ApplyStyle(colStyle, flag);

and its not working , when i type "00" i get only one zero because its not a text.
you have another way to set all column as text?

Thanks
Shemesh

Hi Shemesh,

You are doing a mistake in your code, the valid code should be (please correct it):

Style colStyle = sheet.Cells.Columns[colIndex].Style;
StyleFlag flag= new StyleFlag();
flag.NumberFormat = true; // you need to on the number formatting flag else it will not work.
//Set the formating on the as text formating
colStyle.Number = 49;
sheet.Cells.Columns[colIndex].ApplyStyle(colStyle, flag);


Thank you.

Hi,

I have received a message via mail in which you have told me that your issue is resolved after adjusting your code now.

Good to know that.

Have a good day!