OWC11 Date formatting ignored

I am creating an Excel document using owc11. I provide dates in the format dd / mm / yyyy. I am doing something like this in code:

for (..looping through results..)
{
    Range c = EmailStats.putCellValue(sheet, row, 1, val);
    c.set_NumberFormat("dd/mm/yyyy");
}

private static Range putCellValue(Worksheet sheet, int row, int col, String val) 
{
    Range cell = (Range) sheet.Cells[row, col];
    cell.set_Value(XlRangeValueType.xlRangeValueDefault, val);
    return cell;
}

Now, when I set the date format to β€œdd / mm / yyyy” for the val argument, or don’t set it at all, the behavior I get is mm / dd / yyyy from the 1st of the month to the 12th and then it returns back to dd / mm / yyyy. So owc11 believes that he knows better and changes the days and months around (as in the American format), and when he is on the 12th day, he adheres to the British format.

Val is declared as String because it may not always be a date. This can be date, day, username, group name, etc. Depending on how we group / sort our data. It can also be a choice of days.

, - yyyy/mm/dd. . , dd/mm/yyyy, , , .

+3
1

val . val DateTime.

cell.set_Value(XlRangeValueType.xlRangeValueDefault, val);
+1

Source: https://habr.com/ru/post/1735915/


All Articles