【发布时间】:2018-04-07 09:58:38
【问题描述】:
我正在尝试使用
从 Excel 2016 文件中读取strConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 12.0;HDR=YES;\";";.
我正在使用 ActivexObject 和 ADODB.Connection 打开与 excel 文件的连接。我得到了
找不到提供程序。可能没有正确安装
错误。我在 .Net 3.5、Access Database Engine 2010(64 位)和 Office 2016(64 位)以及 windows 7(64 位)和 Visual Studio 2008 中使用 c#。请帮助我。我已经搜索了很多,但找不到任何解决方案。我附上了我的代码和错误图片。ADODB error。
<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>
【问题讨论】: