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

Free Support Forum - aspose.com

Put TimeSpan value without seconds

hi

I have a TimeSpan object which I want to write to a cell.
I gave the cell style format of “hh:mm”.
For some reason when I write the value of the object to the cell (Excel 2007 xlsm)
I get also the seconds. meaning I see ‘10:20:00’. I don’t want to see the seconds
what should I do?
Thanks

Hi,

Well, I tested and it works fine with my sample code given below:
Sample code:
int Num1 = 1;
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
DateTime value1 = DateTime.Now;
DateTime value2 = DateTime.Now;
TimeSpan DuurItem = value2 - value1;
worksheet.Cells[“I” + Num1].PutValue(String.Format("{0}:{1}", DuurItem.TotalHours.ToString(“02”), DuurItem.Minutes.ToString(“30”)),true);
Style style = worksheet.Cells[“I” + Num1].GetStyle();
style.Custom = “hh:mm”;
worksheet.Cells[“I” + Num1].SetStyle(style);
workbook.Save(“e:\test\outputtimespace.xls”);


Which version of the product you are using? I am using v5.1.2.7 (latest fix).
If you still find the issue, kindly do post a sample code (same as above) and sample file to show the issue, we will check it soon.

Thank you.