Format cell to display percentage and currency symbol

I was wondering if there is a way to set style on a cell when using Aspose.Cells to display a percentage symbol and a currency symbol?

Thanks.

Stefan


This message was posted using Aspose.Live 2 Forum

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

You may use Style.Number & Style.Custom properties to set different display styles of cells. Please see the following sample code in this regard:

//Instantiating a Workbook object

Workbook workbook = new Workbook();

//Obtaining the reference of the newly added worksheet by passing its sheet index

Worksheet worksheet = workbook.Worksheets[0];

//Adding the value to "A1" cell

worksheet.Cells["A1"].PutValue(200);

//Get Cell Style

Style style = worksheet.Cells["A1"].GetStyle();

//Setting the display format of the cell as currency

style.Number = 5;

//Set Style

worksheet.Cells["A1"].SetStyle(style);

//Adding the value to "A2" cell

worksheet.Cells["A2"].PutValue(0.2);

style = worksheet.Cells["A2"].GetStyle();

//Setting the display format of the cell as percentage

style.Number = 9;

worksheet.Cells["A2"].SetStyle(style);

//Adding the value to "A3" cell

worksheet.Cells["A3"].PutValue(200);

style = worksheet.Cells["A3"].GetStyle();

//Setting the display format of the cell with currency and percentage sign as Custom Style

style.Custom = "$#,##0%";

worksheet.Cells["A3"].SetStyle(style);

//Saving the Excel file

workbook.Save("D:\\book1.xls");

For Further details, you may check the following documentation link:

http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/setting-display-formats-of-numbers-dates.html

Thank You & Best Regards,