Hi,
To import different ranges of data, I have made a generic formatting and importing method. However, when it sets the Column format to "yyyy-mm-dd", it becomes a Custom format in Excel. In order for it to import properly in SPSS, I need it to be a DateTime format.
public void PrepExcel<T>(List<T> allRows, List<string> headers, int column)
{
//Apply BodyStyle
var properties = typeof(T).GetProperties();
if (allRows.Count > 0) _worksheet.Range[2, column, allRows.Count + 1, column + properties.Length - 1].CellStyle = _bodyStyle;
// apply column formatting
for (var i = 0; i < properties.Length; i++)
{
var property = properties[i];
_worksheet.Range[1, column + i].Text = headers[i];
if (property.PropertyType == typeof(int) || property.PropertyType == typeof(int?))
_worksheet.Columns[i + column - 1].NumberFormat = "0";
if (property.PropertyType == typeof(DateTime) || property.PropertyType == typeof(DateTime?))
_worksheet.Columns[i + column - 1].NumberFormat = "yyyy-mm-dd"; //this gets applied as Custom Format, not as Date Time
if (property.Name.IndexOf("Credit") >= 0 || property.Name.IndexOf("Prijs") >= 0)
_worksheet.Columns[i + column - 1].NumberFormat = "€#,##0.00";
}
//Import data to worksheet.
_worksheet.ImportData(allRows, 2, column, false);
}
The above is used with a List of items, of which at least one is a DateTime. The data gets imported in Excel as 2020-09-05 as expected, but as mentioned as Custom format, which is not recognized by SPSS.
Attached a small subset of the output data file. It does not contain sensitive data . It also contains a screenshot of the format setting Date, with Type 2012-03-14 that does what I need.
But I don't know how to achieve that.
Attachment:
syncfusion_date_format_custom_110469b3.zip