Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
690
Howto set date format in infragistics excel independent of current culture?
posted

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++;
  }
});