Free Support Forum - aspose.com

How to set cell format to Currency number?

Hello,

I have a question about setting cell format. for example I have:

Cells cell = wb.worksheets[0].Cells;

cell[0, 0].PutValue = "1000";

How can I set the cell format to currency number format to show the value like "$1,000.00"?

I can't find an example to tell me if there's any way to set the format like that.

Thanks so much!

Hi,

Thanks for considering Aspose.

Please use Style.Custom property to set your desired currency format.

May the following sample code help you for your requirement, kindly check it out:

Workbook wb = new Workbook();
Cells cell = wb.Worksheets[0].Cells;
//cell[0, 0].PutValue("1000",true);
//or
cell[0, 0].PutValue(1000);
Style style = wb.Styles[wb.Styles.Add()];
style.Custom = "$#,##0.00";
cell[0,0].SetStyle(style);
wb.Save("d:\\test\\currencystyle2.xls");

Thank you.

It works, thanks so much!! :)