[英]Format 2 digit value before decimal and 2 digit after decmal, Excel Interop
我想从Excel电子表格中的单元格中读取值,这可能是
10.50
20.25
41.10
我正在使用Excel Interop检索值。
以下内容适用于小于10的值,但是当该值大于或等于10时,该值将设置为0。如何使用NumberFormat操作正确设置其格式?
double doubleHours = 0.0;
if (Extension.IsNumeric(excelWorksheet.Cells[rowCount, columnCount].Text))
{
Excel.Range range = excelWorksheet.Cells[rowCount, columnCount];
range.EntireColumn.NumberFormat = "#,##0.00";
double.TryParse(excelWorksheet.Cells[rowCount, columnCount].Text, out doubleHours);
//continue processing
}
double doubleHours = 0.0;
Excel.Range range = excelWorksheet.Cells[rowCount, columnCount];
string value = range.Value2.ToString();
if (double.TryParse(value, out doubleHours)) {
//continue processing
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.