【问题标题】:DataGridView showing extra digits after importing excel sheet in windows application在 Windows 应用程序中导入 excel 工作表后 DataGridView 显示额外的数字
【发布时间】:2012-06-26 20:24:55
【问题描述】:

Excel 单元格仅包含 $248.40 并且设置为货币格式。但它在 DataGridView 中显示 284.3899。

能否请您帮助我如何显示 DataGridView 中包含的 Excel 工作表。

【问题讨论】:

  • 使用的数据类型是什么?您可以使用0.00 之类的格式,或者说N2

标签: c# excel datagridview


【解决方案1】:

转到 DataGridView Columns 属性。选择要格式化的Column(Cell)。在Appearances 部分,浏览DefaultCellStyle 的按钮。将打开一个对话框。在这里,您可以在Format 属性中设置单元格的格式。

在此处设置十进制格式属性'#.##'。这将在设计时设置属性。如果您想在运行时设置属性而不是查看 Vok 的答案。

有关数字格式的更多信息,请阅读MSDN

【讨论】:

  • 在 Excel 工作表中,我在地址栏中看到特定单元格值。它没有显示 4 位数字。我需要弄清楚没有设置 datagirdview 的格式。我希望 Excel 工作表格式有问题。
【解决方案2】:

电子表格中的基础值可能包含更多数字。

您需要对 datagridview 应用格式

DataGridView.Columns[0].DefaultCellStyle.Format = "#.##"

【讨论】:

  • 感谢您的回复!我需要在 Excel 表中显示多少位数。不完全是两位数。
猜你喜欢
  • 2016-06-19
  • 1970-01-01
  • 2020-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-30
相关资源
最近更新 更多