I want to read in values out of a cell in an Excel Spreadsheet that could be
10.50
20.25
41.10
I am using the Excel Interop to retrieve the values.
The following works for values less than 10, but when 10 or greater the value gets set to 0. How can I format this correctly using the NumberFormat action?
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.