Question

I can either use NumberFormat.DateFormat.MonthDayYearHourMinute24 or NumberFormat.TimeFormat.HourMinuteSecond24 but nothing that will give me the date and the time together along with the seconds :(

Was it helpful?

Solution

[Disclaimer: I am the product owner of OfficeWriter]

If you need a custom date format that is not included in the list of built-in NumberFormat.DateFormat enumerations, you can set Style.NumberFormat to any formatting string you want. In this case, the formatting string needs to be modified to include the second variables:

//Get NumberFormat
string numFormat = style.NumberFormat;

//Set NumberFormat
style.NumberFormat = "m/d/yy h:mm:ss AM/PM";

The formatting strings accepted by OfficeWriter are the same as those in Excel. To find a new formatting string, you can look up the number format in Excel under Format Cells > Number. Select 'Custom' to find the exact formatting string for a particular number format. More information is available in the OfficeWriter documentation under Number Formats.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top