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

Free Support Forum - aspose.com

Write number as text

hi,


i am trying to set cell format as text.

i did the follow as written on manual

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 still in the excel when i am writing 00 i get only 0.

if i change the cell format manually to text its OK.

is there problem to set cell as text with aspose???

Thanks
Shemesh

Hi Shemesh,

Please use the following code snippet to achive the required functionality.

Code snippet:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

Style style = worksheet.Cells["A1"].GetStyle();
style.Number = 49;
worksheet.Cells["A1"].SetStyle(style);
worksheet.Cells["A1"].PutValue("00000000000000000");
workbook.Save("C:\\celltest.xls", SaveFormat.Excel97To2003);

If there is any thing needs further explanation, please feel free to reach us.

Thanks,

hi ,


your code will work on single cell,

i want to declare that all the column wiil have the same text format, thats why i tried the columns.applyStyle(style,flag) as mentioned on the first message.

there is a way to declare that all the column will be text formatted?

Thanks

Shemesh

Hi,

If you need to set formatting for the whole column, please use:
Style colStyle = sheet.Cells.Columns[colIndex].Style;

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


Thank you.

Its working.


Thanks