How to format cell in Aspose.Excel?

Hi all

I am using Aspose.Excel component for few of our web based report in ASP.NET. There is a typical requirement to display few float values in 1.00, 2.30 etc format. If I send float value to excel report it converts them to 1, 2.3 . I can acive this by sending text values, but in that case all cells are marked with some green triangle saying “error in cell” which looks bad. Is there any way to format a cell in Aspose.Excel in C#.

Looking forward your response

Viswabharathy

To format a cell, please check the following article:
Data Formatting

Could you please post your file here to show those green triangle errors?

@viswabharathym,
Aspose.Cells has replaced Aspose.Excel that is no more available now. You can perform data formatting in a variety of ways for numbers and dates. For numbers, you can use built-in number formats as well as custom number formats. Along with the number formatting, you can format selected characters in a cell, and format rows and columns also. Here is an example that can be used to format data in different ways:

// Instantiating a Workbook object
Workbook workbook = new Workbook();

// Obtaining the reference of first worksheet
Worksheet worksheet = workbook.Worksheets[0];

// Adding the current system date to "A1" cell
worksheet.Cells["A1"].PutValue(DateTime.Now);

// Getting the Style of the A1 Cell
Style style = worksheet.Cells["A1"].GetStyle();

// Setting the display format to number 15 to show date as "d-mmm-yy"
style.Number = 15;

// Applying the style to the A1 cell
worksheet.Cells["A1"].SetStyle(style);

// Adding a numeric value to "A2" cell
worksheet.Cells["A2"].PutValue(20);

// Getting the Style of the A2 Cell
style = worksheet.Cells["A2"].GetStyle();

// Setting the display format to number 9 to show value as percentage
style.Number = 9;

// Applying the style to the A2 cell
worksheet.Cells["A2"].SetStyle(style);

// Adding a numeric value to "A3" cell
worksheet.Cells["A3"].PutValue(2546);

// Getting the Style of the A3 Cell
style = worksheet.Cells["A3"].GetStyle();

// Setting the display format to number 6 to show value as currency
style.Number = 6;

// Applying the style to the A3 cell
worksheet.Cells["A3"].SetStyle(style);

// Saving the Excel file
workbook.Save(dataDir + "book1.out.xls", SaveFormat.Excel97To2003);

For more details, refer to the following article:
Data Formatting

Download the latest free trial version of this new product is here:
Aspose.Cells for .NET (Latest Version)

Download an example project here to test the product features.