Reputation: 81
I am having a problem while converting text into the format [hh:mm:ss].
When I double click, formatting is fixed and cell value is automatically aligned to the right.
I am using [SpreadsheetStreams.net] NuGet package to create an excel file.
Here what I have already tried:
writer.AddCell(TimeSpan.Parse(columnNames[i].ToString()))
Style test = new Style();
NumberFormat format = new NumberFormat(NumberFormatType.Custom);
format.Custom = "hh:mm";
test.NumberFormat = format;
writer.AddCell(TimeSpan.Parse(columnNames[i].ToString()), test) OR
writer.AddCell(columnNames[i].ToString(), test)
Please refer to this image:
How can I format the cell to [hh:mm:ss]?
Upvotes: 0
Views: 580
Reputation: 81
After trying many solutions I found a way : Create a Style object having a custom type like below :
Style timeStyle = new Style();
NumberFormat format = new NumberFormat(NumberFormatType.Custom);
format.Custom = "hh:mm";
timeStyle.NumberFormat = format;
Then pass this as the second parameter and first parameter as a day (in double)
writer.AddCell(TimeSpan.Parse(columnNames[i]).TotalSeconds / 86400, timeStyle );
Upvotes: 1