Getting time values from an Excel sheet

后端 未结 1 901
眼角桃花
眼角桃花 2021-01-16 12:34
      Microsoft.Office.Interop.Excel.Application app = 
                                new Microsoft.Office.Interop.Excel.Application();

      Workbook wb = app.Wo         


        
1条回答
  •  时光取名叫无心
    2021-01-16 13:10

    MS Excel stores the dates as float values. The integer part represents the days and the fractional part keeps the hours, minutes and seconds.

    Check this code that extracts the hours and also the minutes and seconds, maybe you need them:

    float excelValue = 0.4f;
    
    int miliseconds = (int)Math.Round(excelValue*86400000);
    int hour = miliseconds/( 60/*minutes*/*60/*seconds*/*1000 );
    miliseconds = miliseconds - hour*60/*minutes*/*60/*seconds*/*1000;
    int minutes = miliseconds/( 60/*seconds*/*1000 );
    miliseconds = miliseconds - minutes*60/*seconds*/*1000;
    int seconds = miliseconds/1000;
    

    0 讨论(0)
提交回复
热议问题