This article mainly introduces the code example of reading the contents of local Excel files through JavaScript, but requires certain conditions to use JS to operate local files, the need for friends to refer to the next bar
JavaScript code to read the contents of a local Excel file: code is as follows: <script type= "Text/javascript" > Function Read_excel () { & nbsp var filepath= "D:abcd9.com.xls"; XLS var sheet_id=2 to read; Read Table 2nd VAR row_start=3; Read var tempstr= ' from line 3rd; try{ var oXL = new ActiveXObject ("Excel.Application");//Create Excel.Application Objects & nbsp }catch (Err) { alert (err); } var owb = Oxl.wor Kbooks.open (FilePath); Owb.worksheets (sheet_id). Select (); var osheet = Owb.activesheet; var colcount=oxl.worksheets (sheet_id). UsedRange.Cells.Rows.Count; for (Var i=row_start;i<=colcount;i++) { typeof if (Osheet.cells (i,8). Value) = = ' Date ' {/////////= read problem with date format for part 8th column cell content d= new Date (Osheet.cells (i,8). Value ); Temp_time=d.getfullyear () + "-" + (D.getmonth () + 1) + "-" +d.getdate (); } else Temp_time=$.trim ( Osheet.cells (i,7). value.tostring ()); tempstr+= ($.trim (Osheet.cells (i,2). Value) + "+$.trim (Osheet.cells (i,4). Value) +" "+$.trim (Osheet.cells (i,6). Value.tostring ()) + "" +temp_time+ "n"); /Read 2nd, 4, 6, 8 column content } return tempstr; return oxl.quit (); CollectGarbage (); {</script> must be conditional: 1, the client must have the Microsoft Excel ActiveX control installed (complete Microsoft Office installed), and The browser pops up "This site needs to run the following add-ins ..." When prompted to run, otherwise the JS code will have an error creating the Excel.Application object. 2, JS read the local Excel file involves security issues, the default settings Microsoft Excel ActiveX control does not have permission to execute. The solution is as follows: A. Click on the browser "tools"-> "Internet Options"-> "secure" and select "Trusted Sites". B. Click on the "site (S)" button to add this site to the list; c. Click "Custom Level" (c) ..., and in the security settings, locate the ActiveX controls that are not marked as safe to execute scripts under the ActiveX controls and plugins node and set them to Enabled ”。