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

Free Support Forum - aspose.com

Setting Danish Krone custom currency formatting in Excel using C#.NET

Hi,

I need to set a cell to currency. I’d like to it be Danish Krone, I found the correct format, but I’m unsure how to apply this in the code:

Danish Krone

DKK

208

krone

øre

2

#.###,##

I would like to format two separate columns in my worksheet.

Any suggestions as to how I can achieve this please?

Hi Andy,


Thank you for contacting Aspose support.

You can use the Style.Custom property to specify the desired format and set the style object to as many columns as you like. For instance, please check the following piece of code that applies the currency format to 2 columns (B & C).

Please note, as you have not specified the platform of interest so I have posted the C# code. Let me know if you need Java code instead.

C#

Workbook book = new Workbook(fileName);
Style style = book.CreateStyle();
style.Custom = “[$kr.-406] #,##0.00”;
Worksheet sheet = book.Worksheets[0];
sheet.Cells.Columns[1].ApplyStyle(style, new StyleFlag(){NumberFormat = true});
sheet.Cells.Columns[2].ApplyStyle(style, new StyleFlag(){NumberFormat = true});

Hi,


Thanks for providing us some details.

Here is another way to accomplish the task, see the sample code on how to format a column with DKK currency for your requirements:
e.g
Sample code:

Workbook wb = new Workbook();

//Input some number into a cell.
wb.Worksheets[0].Cells[“A1”].PutValue(-2423);

int colIndex = 0;
Style style;
StyleFlag flag;
style = wb.CreateStyle();
style.Custom = “[$DKK] #,##0.00”; //Apply DKK currency formatting
flag = new StyleFlag();
flag.NumberFormat = true;
//Apply the formatting to the first column cells.
wb.Worksheets[0].Cells.ApplyColumnStyle(colIndex, style, flag);

wb.Save(“e:\test2\out1.xlsx”);

Also, please see the document on how to apply (custom) numbers formatting for your complete reference:
http://www.aspose.com/docs/display/cellsnet/Setting+Display+Formats+of+Numbers+and+Dates

Hope, this helps a bit.

Thank you.

Thanks, that’s great, do you have the same example for Euros please?

Hi,


Sure, you may just change the line of code (from my previous code segment)
i.e.,
style.Custom = “[$DKK] #,##0.00”; //Apply DKK currency formatting

to:
style.Custom = “[$€-2] #,##0.00”; //Apply Euro currency formatting


Thank you.