我想知道如何获取 _variant_t 类型的值。
我已经知道使用 GetItems() 的方法值,例如:
_variant_t var = pRs->Fields->GetItem(i)->GetValue();
在 Excel 文件 (.xls) 中,我找不到整行数据的方法。
有一组提取器可用于从变体类型中提取数据。只需将其转换为变体所代表的类型。要获取内部类型,请检查“vt”成员。
这是MSDN上的一篇文章。
示例代码:
#include <Windows.h>
#include <comutil.h>
#include <cassert>
#pragma comment(lib, "comsuppw.lib")
int main()
{
_variant_t v(10.0);
assert(v.vt == VT_R8); // inner type is double
double value = static_cast<double>(v); // 10.0
return 0;
}