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

Free Support Forum - aspose.com

Format a cell to dollar format

Hi <br>I have a requirement in which I need to format a cell to $ format and round it off to 2 decimal places and also I need to display the value in the cell as $150.54.<br>I hope I am making some sense.<br>Thanks<br><br>

Hi,

Thank you for considering Aspose.

You may set Cell.Style.Number = 7 to get your desired display format. Please see the following sample code:

//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(150.54);

//Setting the display format to number 17 to show currency with two decimals

worksheet.Cells["A1"].Style.Number = 7;

//Saving the Excel file

workbook.Save("C:\\book1.xls", FileFormatType.Default);

You may check the following documentation link for further details and sample codes for different display formats.

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

Thank You & Best Regards,