I was wondering if someone could help me. I'm pulling my hair out on this one. I'm currently populating a predifined excel spreadsheet that has a few fields that has a format of :mm:ss, Style.Number = 46. When i put the data, a string, into the field it doesn't keep the format even if I define it. Here's a section of the code:
Well, We checked your code a bit, I think your data is not coverted into DateTime format. You have provided string values to the cells on which you want to apply Time format. DataTime Number Format won't work on string data. I think that 's the problem with your code.
Please convert all your concerning data to DateTime format first and then put into the related cells. Or you may use Cell.PutValue(string, bool) method for the task.
If you still have some problems please let us know.
The problem is the time data is cumlitive so it may be over 24 hrs. The format of the data is h:mm. The thing is when the user opens the report and double clicks on the cell it goes to the proper format.
The % is not vaild. But when I change it to mod I get the following error: Operator ‘+’ is not defined for types ‘Date’ and ‘System.TimeSpan’. Also I want to keep the time if it’s greator than 24.
This is the file that I have. If you notice when you select the cell with the time format it shows it as it appears. If you were to double click that cell it will format it correctly.
it seems to error with data less than 13 hours. The results are wrong 37:50:00 (Tested code) v. 13:50:00 ( Actual). For some reason it’s adding a day. Is there a way to not include the day?
Dim day As Integer = hourValue \ 24 Dim hour As Integer = hourValue Mod 24
Dim dateTime As DateTime If day = 0 Then dateTime = New DateTime(1899, 12, 31, hour, 20, 0) Else dateTime = New DateTime(1900, 1, day, hour, 20, 0) End If cell.PutValue(dateTime) cell.Style.Custom = ":mm:ss"