code example for reading local Excel file contents through JavaScript

Source: Internet
Author: User
Tags trim

  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 ”。
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.