We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Date format in Excel

Hello!
I try to set cell format using AsposeCell API (C#):

var cell = worksheet.Cells[i, j];
Style style = cell.GetStyle();
style.Number = 21;
cell.SetStyle(style);

var time = new TimeSpan(1, 2, 3);
cell.PutValue(time);
This cell is displayed correctly, but has format: “all formats” (not “Time”). That is to say, style property did not work. What’s wrong?

Thank you!

@SeminDm,

Do you mean to say after opening the output file into MS Excel, when we right click on the cell to display Format Cells… dialog, it selects “Custom” instead of “Time” under the “Number” tab? But it shows correct formatting string “h:mm:ss”. So, this is correct behavior.

We recommend you to kindly convert TimeSpan string to proper data type when inputting into the cell via Aspose.Cells API, so you may use the following line of code instead:
e.g
Sample code:

cell.PutValue(time.ToString(), true);//true specifies that the data will be converted to proper data type.

Thank you.

Thank you very much! it works!

@SeminDm,

Good to know that it figures out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.