0804周一

来源:互联网 发布:网络管理的五大功能 编辑:程序博客网 时间:2024/05/01 17:56
//导入Excel文件
function importXLS(fileName)
{
   try{
     objCon = new ActiveXObject("ADODB.Connection");
     objCon.Provider = "Microsoft.Jet.OLEDB.4.0";
     objCon.ConnectionString = "Data Source=" + fileName + ";Extended Properties=Excel 8.0;";
     objCon.CursorLocation = 1;
     objCon.Open;
     var strQuery;
     //Get the SheetName
     var strSheetName = "Sheet1$";
     var rsTemp =  new ActiveXObject("ADODB.Recordset");
     rsTemp = objCon.OpenSchema(20);
     if(!rsTemp.EOF)
     strSheetName = rsTemp.Fields("Table_Name").Value;
     rsTemp = null
     rsExcel =  new ActiveXObject("ADODB.Recordset");
     strQuery = "SELECT * FROM [" + strSheetName + "]";
     rsExcel.ActiveConnection = objCon;
     rsExcel.Open(strQuery);
     if(rsExcel.Fields.Count!=4){
         alert('文件不规范,请点击EXCEL模板查看');
         objCon.Close;
      objCon =null;
      rsExcel = null;
      return;
     }
     while(!rsExcel.EOF)
     {
      addrow(rsExcel.Fields(0).value,rsExcel.Fields(1).value,rsExcel.Fields(2).value,rsExcel.Fields(3).value);
      rsExcel.MoveNext;
     }
     // Close the connection and dispose the file
     objCon.Close;
     objCon =null;
     rsExcel = null;
     }
   catch(e){
    alert("文件格式不对或没有安装EXCEL或浏览器没有权限,/r/n请安装EXCEL并且允许使用ActiveX控件[建议把本网站设置为信任站点]!");
   }
}