When I add a worksheet via a DataTable
, I would expect the date formats to follow the locale/culture of the application but it appears to take that from the computer.
string culture = "en-GB";
var newCulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentCulture = newCulture;
Thread.CurrentThread.CurrentUICulture = newCulture; //probably unnecessary?
CultureInfo.DefaultThreadCurrentCulture = newCulture;
// ... select myDateColumn, myIntCol, myString
workBook.AddWorksheet(myDataTableThatContainsQueryResults, tabName);
Now, you'd expect the first column (myDateColumn
) to format using the short date format of the en-GB
locale which should be '31/10/2017'
but it's coming out as '10/31/2017'
instead.
I checked the locale in the DataTable once I get it back from the SQLDataAdapter and it's correct as are the nested date formats. Note that there are multiple queries and I won't know where the dates are in advance.
Appreciate any direction someone can provide!