从ADO获取未分类的记录集

时间:2014-10-07 14:29:57

标签: c++ excel ado

我使用ADO从excel文件中获取表头列名。问题是数据被返回排序。我需要它的原始顺序。这是代码:

_RecordsetPtr pSchema->m_pCon->OpenSchema(adSchemaColumns);
// pSchema->Sort = ""; // Does not help
// pSchema->Sort = "ORDINAL_POSITION"; // Crashes
while (!pSchema->GetadoEOF()) 
{
    string sheetName = (char*)(_bstr_t)pSchema->Fields->GetItem("TABLE_NAME")->Value.bstrVal;
    if (sheetName == "MySheet")
        string column = (char*)(_bstr_t)pSchema->Fields->GetItem("COLUMN_NAME")->Value.bstrVal;
    pSchema->MoveNext();
}

如何让它返回未分类?

1 个答案:

答案 0 :(得分:0)

int ordinalPosition = (int)pSchema->Fields->GetItem("ORDINAL_POSITION")->Value.dblVal;

然后按ordinalPosition排序(从索引1开始)。