从Excel单元格捕获时间值 [英] Capturing Time Values from an Excel Cell
问题描述
数字格式
或键入'hh:min'(Hour:Min)
我无法获得这个价值。 这是我的代码...
ws [dateTimePicker1。 Value.Day + 1] .get_Range(F+ i.ToString(),Type.Missing);
if(range.Value2!= null)
val + = - + range.Value2.ToString(); //将FXX设置为val
lbHK1.Items.Add(val);
其中...
-
ws
=我的工作表 -
dateTimePicker1
=我的日期时间选择器,可以帮助我决定哪个文件将被打开 -
i
=是一个整数,可以帮助我确定该单元格的行号 -
range
=是从Microsoft.Office.Interop.Excel.Range创建的对象
在我的例子中,当 i = 11
时, F11
是包含时间值为 06:30
(在Excel中, fx:06:30:00
)的单元格。但是,当我尝试获取该值时,它会返回一个 double
类型,例如 0.263888888888889
如何将Excel格式的值正确格式化,而不是无意义的双重值?
Excel内部存储时间为双精度,包含24小时制的小数位数:因此6:30 AM将为0.2708333
I am writing an Excel app that will read and write specified values from an Excel file, and display them to the user. However, when I try to read from a cell which has a Number Format
or a function typed 'hh:min' (Hour:Min)
I cannot obtain that value how exactly I want.
Here is my code...
ws[dateTimePicker1.Value.Day + 1].get_Range("F" + i.ToString(), Type.Missing);
if (range.Value2 != null)
val += " - " + range.Value2.ToString(); //Sets FXX to val
lbHK1.Items.Add(val);
Where...
ws
= my worksheetdateTimePicker1
= my date time picker which helps me decide which file will be openedi
= is an integer that helps me decide Row number of that cellrange
= is an object created from Microsoft.Office.Interop.Excel.Range
In my example, when i = 11
, F11
is the cell that contains the time value which is 06:30
(in Excel, fx : 06:30:00
). However, when I try to get that value, it returns a double
type such as 0.263888888888889
How can I get the value formatted correctly as it is displayed in Excel, rather than a meaningless double value?
Excel stores times internally as doubles containing decimal fractions of a 24-hour day: so 6:30 AM would be 0.2708333
这篇关于从Excel单元格捕获时间值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!