使用C#读取excel数据目标平台64位office也是201064位没问题,但是在其他电脑上office为32位出现错误
使用的是vs2010CLR窗体程序,不是C#但是和C#非常类似,代码如下:
public: DataTable ^ getData(String^ path)
{
String^ filename=path;
//String^ filename1=filename->Substring(filename->LastIndexOf("\\")+1);//获取用户选择的不带路径的文件名
String ^fileSuffix=System::IO::Path::GetExtension(filename);//获取文件扩展名
/*if(String::IsNullOrEmpty(fileSuffix))
return nullptr ;*/
DataSet ^ds=gcnew DataSet();
String^ connString;
if(fileSuffix==".xls")
connString="Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source="+filename+";"+
"Extended Properties='Excel 8.0;HDR=No;IMEX=1';";
else connString="Provider=Microsoft.ACE.OLEDB.12.0;"+"Data Source="+filename+";"+
"Extended Properties='Excel 12.0;HDR=No;IMEX=1';";
String ^sql_select="SELECT * FROM [Sheet1$]";
OleDbConnection ^conn=gcnew OleDbConnection(connString);
OleDbDataAdapter^ cmd=gcnew OleDbDataAdapter(sql_select,conn);
conn->Open();
cmd->Fill(ds);
conn->Close();
/*if(ds==nullptr||ds->Tables->Count<=0)
return nullptr;
return ds;*/
DataTable ^dt=ds->Tables[0];
return ds;
}
如题,我在自己电脑上可以运行vs和office都是64的,但是其他电脑是2010office32位的就会出错,运行到conn->Open();这句直接跳出返回空值或报错,System.Reflection.TargetInvocationException”类型的未经处理的异常在 mscorlib.dll 中发生;请问64位的项目平台不能读取32位的Excel文件吗(我不想改项目目标平台为32位),如果有办法请指教。