导入: 复制代码 代码如下: 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>