如何获得_variant_t的值?

我想知道如何获得_variant_ttypes的值。

我已经知道使用GetItems()方法的值,例如:

_variant_t var = pRs->Fields->GetItem(i)->GetValue(); 

在Excel文件(.xls)中,我找不到整行数据的方法。

您可以使用一组提取器来从变体types中提取数据。 只需将其转换为变体代表的types即可。 获取内部types,检查'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; }