Hi,
I'm using infragistics.excel to export dynamic (lists) data to excel. The date format has to be dd-mmm-yyyy.
This works if system language is english. It doesn't work on german systems, where it would expect tt-mmm-jjjj.
How can I set the correct date format indenpendent of current system culture?
I already tried
Workbook workBook = new Workbook(WorkbookFormat.Excel2007); workBook.Culture = CultureInfo.GetCultureInfo("en-US");
with no success.
the part where I set the dateformat is
...
propertyInfos.ToList().ForEach(p => { if (WriteProperty(p, out displayName)) { if (p.PropertyType == typeof(DateTime) || p.PropertyType == typeof(DateTime?)) { ws.Columns[column].CellFormat.FormatString = "DD-MMM-YYYY"; }
ws.GetCell("R" + row + "C" + column, CellReferenceMode.R1C1).CellFormat.Font.Height = 10 * 20; ws.GetCell("R" + row + "C" + column, CellReferenceMode.R1C1).CellFormat.WrapText = ExcelDefaultableBoolean.True;
if (p.PropertyType == typeof(decimal?) || p.PropertyType == typeof(DateTime?)) { ws.GetCell("R" + row + "C" + column, CellReferenceMode.R1C1).Value = p.GetValue(element, null); } else { ws.GetCell("R" + row + "C" + column, CellReferenceMode.R1C1).Value = Convert.ToString(p.GetValue(element, null)); }
if (Convert.ToString(p.GetValue(element, null)).Length > colWidth[column - 1]) { colWidth[column - 1] = Convert.ToString(p.GetValue(element, null)).Length; }
column++; }});
Hello Tobias,
Thank you for posting in our forum.
If I understand you correctly you need to export a DateTime value to a cell in Excel with Infragistics Excel Engine. I have tested this by setting the same format string as yours and it is working fine for me when my machine regional settings are set to German language and Germany as location. When I export a DateTime value the format in Excel is TT-MMM-JJJJ. If I switch back my regional settings to English/ US Excel automatically changes the format in the exported workbook to DD-MMM-YYYY.
In the attached archive you may find the sample project I have tested with. Please run this sample on your machine and let me know what the result is.
If this sample is not an accurate demonstration of what you are trying to do, please fill free to modify it and send it back, or if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.
Looking forward to your reply.
Hi Miko
could you please attach the archive? ;-)
Hi Tobias,
Here is the archive. Sorry for this overlook from my side.
no problem...
but found mine:
in program.cs, I set
CultureInfo mainCulture; mainCulture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); mainCulture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy"; mainCulture.DateTimeFormat.LongDatePattern = "dd-MMM-yyyy"; mainCulture.DateTimeFormat.LongTimePattern = ""; Thread.CurrentThread.CurrentCulture = mainCulture; Thread.CurrentThread.CurrentUICulture = mainCulture;
to have the correct formatting in grids, datetimeeditors etc
somehow that interferes with the excel export. If I disable the culture/ uiculture, I get the correct values.