Excel 文件(来自 DataGridView)未显示 'Zero' 值 < 1

Excel file (from DataGridView) not showing 'Zero' for values < 1

我正在将 DataGridView 导出到 Excel 文件。

DGV 包含一个包含货币 (€) 的列,因此我使用此代码来格式化 Excel Sheet 列:

With xlSheet
    .Range(.Cells(1, C + 1), .Cells(1, C + 1)).EntireColumn.NumberFormat = "€ #,###,###.00"
End With

但是,当我打开保存的 excel 文件时,如果值小于 1(即 0,25),我得到:

€ ,25

而不是

€ 0,25

我该如何解决?

在您的数字格式中的小数点前添加一个零:

With xlSheet
    .Range(.Cells(1, C + 1), .Cells(1, C + 1)).EntireColumn.NumberFormat = "€ #,###,##0.00"
End With

由此link - https://support.office.com/en-us/article/Create-or-delete-a-custom-number-format-78f2a361-936b-4c03-8772-09fab54be7f4

0 (zero) -- This digit placeholder displays insignificant zeros if a number has fewer digits than there are zeros in the format. For example, if you type 8.9, and you want it to be displayed as 8.90, use the format #.00.