导入: 复制代码 代码如下: Untitled Page <BR>function importXLS(fileName)<BR>{ <BR> objCon = new ActiveXObject("ADODB.Connection");<BR> objCon.Provider = "Microsoft.Jet.OLEDB.4.0";<BR> objCon.ConnectionString = "Data Source=" + fileName + ";Extended Properties=Excel 8.0;";<BR> objCon.CursorLocation = 1;<BR> objCon.Open;<BR> var strQuery;<BR> //Get the SheetName<BR> var strSheetName = "Sheet1$";<BR> var rsTemp = new ActiveXObject("ADODB.Recordset");<BR> rsTemp = objCon.OpenSchema(20);<BR> if(!rsTemp.EOF)<BR> strSheetName = rsTemp.Fields("Table_Name").Value;<BR> rsTemp = null;<BR> rsExcel = new ActiveXObject("ADODB.Recordset");<BR> strQuery = "SELECT * FROM [" + strSheetName + "]";<BR> rsExcel.ActiveConnection = objCon;<BR> rsExcel.Open(strQuery);<BR> while(!rsExcel.EOF)<BR> {<BR> for(i = 0;i<rsExcel.Fields.Count;++i)<BR> {<BR> alert(rsExcel.Fields(i).value);<BR> }<BR> rsExcel.MoveNext; <BR> }<BR> // Close the connection and dispose the file<BR> objCon.Close;<BR> objCon =null;<BR> rsExcel = null;<BR>}<BR>