This project has moved. For the latest updates, please go here.

Apply culture formats from CulterInfo

Nov 25, 2011 at 5:57 AM

Hi,

I want to apply culture to my data. I am retriving data from MYSQL database and checking datatype of each column. And according to datatype apply the culture. However I tried to  do like 

((ExcelRange)worksheet.Cells[6, dc.Ordinal + 1, table.Rows.Count + 6, dc.Ordinal + 1]).Style.Numberformat.Format = "mm/dd/yyyy"; 

But I want to apply these formats (date, currency, time) from CultureInfo. My CultureInfo is not fixed.  It may change according to user.

 

Code:

public static CultureInfo customCulture = new CultureInfo("en-US");

foreach (DataColumn dc in table.Columns)           

{               

if (dc.DataType.Name == "DateTime")     

          {
                   ((ExcelRange)worksheet.Cells[6, dc.Ordinal + 1, table.Rows.Count + 6, dc.Ordinal + 1]).Style.Numberformat.Format =

  Apply Culture from customculture

}

}

Coordinator
Nov 28, 2011 at 5:48 AM

If you use the standard datetime and numeric formats they will change according to the culture of the computer they are opened on.

If you are not happy with that, I think you can specifiy the culture like...

[$-1083C]dd/mm/yyyy;@" depending on your culture. Check the OOXML documentation for details...

http://www.ecma-international.org/publications/standards/Ecma-376.htm