Excel C API 相当于 C# 中的互操作 Range.Value

Excel C API equivalent of Interop Range.Value in C#

试图弄清楚如何读取引用的内容并获得与 Interop/COM 的 Range.Value 相同的结果...即对象[] returned包含字符串、日期时间和双精度值。

我正在使用 ExcelDNA(和底层 XlCall.Excel 来调用 C API)并且两者...

ExcelReference.GetValue()XlCall.Excel( XlCall.xlfDeref, reference )

return 和 object[,] 都等同于 Interop/COM 的 Range.Value2...即对象[] returned仅包含字符串和双打。

问题是日期被 return 编辑为双精度值,我无法确定该值应该是 double 还是 DateTime

ExcelReference.GetValue() 永远不会 return 日期时间,因为它永远不是单元格的存储值 - 它只是应用于数字(双精度)值的显示格式。货币和百分比格式设置类似。

您可以使用选项 53 使用 C API 的 xlfGetCell 调用来读取 "Contents of the cell as it is currently displayed, as text, including any additional numbers or symbols resulting from the cell's formatting."。但是,您必须确定该字符串是否表示 date/time 你自己。

也可以阅读 "Number format of the cell, as text (for example, "m/d/yy" 或 "General")"。使用 xlfGetCell 选项 7.