时间在Office 365中显示为小数

时间:2019-05-29 07:49:25

标签: asp.net excel vb.net office365

我正在使用NPOI将时间列导出为ex​​cel。它在excel 2010中可以完美运行。但是在Office 365中,经过几行后,excel将时间显示为十进制数字。我正在使用'[h]:mm; @'格式格式化时间,并且没有时间值大于24。

Dim Style As ICellStyle = workbook.CreateCellStyle    
Dim df As IDataFormat = workbook.CreateDataFormat
Style.DataFormat = df.GetFormat("[h]:mm;@")
cell.SetCellFormula("TIME(" + ts2.Hours.ToString + "," +             
s2.Minutes.ToString + ",0)")
cell.SetCellType(CellType.Formula)
cell.CellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Medium
cell.CellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Medium
cell.CellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Medium
cell.CellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Medium    
Dim evaluator As IFormulaEvaluator = 
workbook.GetCreationHelper.CreateFormulaEvaluator 
evaluator.EvaluateFormulaCell(cell)
cell.CellStyle = Style

结果如下

6:51        14:51 

6:51        14:51

7:00        0.541666667  

0.875     0.333333333

0.285416667       0.61875

0 个答案:

没有答案