问题描述
我正在尝试使用 var strConnString =" Provider = Microsoft.ACE.OLEDB.12.0; Data Source ="来读取Excel 2016文件+ strXLPath +" ;;扩展属性= \" Excel 12.0; HDR = YES; \" ;;" ;;
我正在使用ActivexObject和ADODB.Connection打开与excel文件的连接。我收到"提供商无法找到。它可能没有正确安装。"错误。我在.Net 3.5,Access数据库引擎2010(64位)和Office 2016(64
位)和Windows 7(64位)和Visual Studio 2008中使用c#。请帮助我。我搜索了这么多,但找不到任何解决方案。我附上了我的代码和错误图片。
I am trying to read from Excel 2016 file using var strConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 12.0;HDR=YES;\";";
I am using ActivexObject and ADODB.Connection to open the connection to excel file. I am getting "Provider cannot be found. It may not be properly installed." error. I am using c# in .Net 3.5, Access Database Engine 2010 (64 bit) and Office 2016(64 Bit) and windows 7(64 bit) and Visual Studio 2008. Please help me. I've searched so much but couldn't find any solution for this. I'm attaching my code and the error image.
<script type="text/javascript" language="javascript">
function IsXLValid() {
var strXLPath = document.getElementById('<% =FileUpload.ClientID%>').value
var len = strXLPath.length;
if (len == 0) {
alert("Please select batch control numbers spreadsheet to upload.");
return false;
}
//var regex = "^(([a-zA-Z]:)|(\\\\{2}\\w+)\\$?)(\\\\(\\w[\\w].*))(.(X|x)(L|l)(S|s))$";
var regex = "^(([a-zA-Z]:)|(\\\\{2}\\w+)\\$?)(\\\\(\\w[\\w].*))(.(X|x)(L|l)(S|s)(M|m))$";
if (!(strXLPath.match(regex))) {
alert(strXLPath + " is not a valid excel file.");
return false;
}
//var strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 8.0;HDR=YES\"";
var strConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 12.0;HDR=YES;\";";
var conn = new ActiveXObject("ADODB.Connection");
conn.open(strConnString, "", "");
var rs = new ActiveXObject("ADODB.Recordset");
var rsrowCount = new ActiveXObject("ADODB.Recordset");
var schemaRS = new ActiveXObject("ADODB.Recordset");
var adSchemaTables = 20;
schemaRS = conn.OpenSchema(adSchemaTables);
strdatatype = schemaRS.fields(2).value;
var datatype = "ERISAREQ$";
if (strdatatype !== datatype) {
alert(strXLPath + " is not a valid spreadsheet with the numbers: " + strdatatype + "");
rs = null;
rsSheet = null;
conn.close();
conn = null;
return false
}
rs = conn.execute("select * from ZRangeValid");
if (rs.fields(0).value != 'YES') {
alert(strXLPath + " requested numbers spreadsheet is not valid.\nPlease validate the spreadsheet data and retry.")
rs = null;
rsSheet = null;
conn.close();
conn = null;
return false
}
rsrowCount = conn.execute("SELECT COUNT([Control Number]) from [ERISAREQ$]");
if (rsrowCount.fields(0).value < 70)
{
var answer = confirm("Uploaded Spreadsheet has less than 70 Numbers, would you like to proceed..?")
if (answer)
{
rsrowCount = null;
rsSheet = null;
conn.close();
conn = null;
return true;
}
else
{
return false;
}
}
return true
rs = null;
rsSheet = null;
conn.close();
conn = null;
}
function trim(str) {
return str.replace(/^\s*|\s*$/g, "");
}
</script>
推荐答案
这篇关于无法找到提供商。它可能没有正确安装。连接excel 2016的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!