如题。
首先从http://stock.gtimg.cn/data/index.php?appn=detail&action=download&c=sh601006&d=20110321下载一个Excel文件,请问如何用Vc6.0打开并读取其中数据,以前用以下代码可以,现在打不开了,报“外部表不是预期的格式”错,应如何解决?是不是Excel的版本变了,应该如何配置本机环境?
URLDownloadToFile(NULL,"http://stock.gtimg.cn/data/index.php?appn=detail&action=download&c=sh601006&d=20110321","c:\\a.xls",0,0);
//创建Excel连接
ConnectionString = _T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=");
ConnectionString += "C:\\a.xls"; //excel file name
ConnectionString += _T(";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=0\"");
_ConnectionPtr pExcelCnn;
try
{
BSTR resultsString = ConnectionString.AllocSysString();
pExcelCnn.CreateInstance(__uuidof(Connection));
resultsString = ConnectionString.AllocSysString();
pExcelCnn.CreateInstance("ADODB.Connection");
pExcelCnn->Open(resultsString,"","",adModeUnknown);
}
catch (_com_error &e1)
{
_bstr_t str = e1.Description();
MessageBox(e1.Description());
return ;
} //打开Excel表中数据
CString ExcelTable = "a"; _bstr_t bstrSqlExcel = "SELECT * FROM [" + ExcelTable + "$]";
_RecordsetPtr pExcelRs;
pExcelRs.CreateInstance(_uuidof(Recordset));
try
{
pExcelRs->Open(bstrSqlExcel,pExcelCnn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
pExcelRs->MoveFirst();
}
catch(_com_error &e)
{
_bstr_t str = e.Description();
MessageBox(e.Description());
return ;
}
for(int i = 1; i < 7; i++)
{
_bstr_t t = pExcelRs->GetCollect(_variant_t((long)(i-1))); CString sValue;
sValue.Format("%s",(LPCTSTR)t);
}
首先从http://stock.gtimg.cn/data/index.php?appn=detail&action=download&c=sh601006&d=20110321下载一个Excel文件,请问如何用Vc6.0打开并读取其中数据,以前用以下代码可以,现在打不开了,报“外部表不是预期的格式”错,应如何解决?是不是Excel的版本变了,应该如何配置本机环境?
URLDownloadToFile(NULL,"http://stock.gtimg.cn/data/index.php?appn=detail&action=download&c=sh601006&d=20110321","c:\\a.xls",0,0);
//创建Excel连接
ConnectionString = _T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=");
ConnectionString += "C:\\a.xls"; //excel file name
ConnectionString += _T(";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=0\"");
_ConnectionPtr pExcelCnn;
try
{
BSTR resultsString = ConnectionString.AllocSysString();
pExcelCnn.CreateInstance(__uuidof(Connection));
resultsString = ConnectionString.AllocSysString();
pExcelCnn.CreateInstance("ADODB.Connection");
pExcelCnn->Open(resultsString,"","",adModeUnknown);
}
catch (_com_error &e1)
{
_bstr_t str = e1.Description();
MessageBox(e1.Description());
return ;
} //打开Excel表中数据
CString ExcelTable = "a"; _bstr_t bstrSqlExcel = "SELECT * FROM [" + ExcelTable + "$]";
_RecordsetPtr pExcelRs;
pExcelRs.CreateInstance(_uuidof(Recordset));
try
{
pExcelRs->Open(bstrSqlExcel,pExcelCnn.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
pExcelRs->MoveFirst();
}
catch(_com_error &e)
{
_bstr_t str = e.Description();
MessageBox(e.Description());
return ;
}
for(int i = 1; i < 7; i++)
{
_bstr_t t = pExcelRs->GetCollect(_variant_t((long)(i-1))); CString sValue;
sValue.Format("%s",(LPCTSTR)t);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货