Easyui how to combine JS to export Excel files

Source: Internet
Author: User

Nonsense I said less, directly into the business. Simple JS can export Excel is rare, generally need to invoke the client installed Office Excel components to complete this work. Here I mainly talk about the DataGrid in Easyui how to combine JS to export Excel files

The core Code snippet for exporting Excel is shown below

function Exproter () {
            //Get datagride column
            var rows = $ (' #test '). DataGrid (' GetRows ');
            var oXL = new ActiveXObject ("Excel.Application"); Create Ax Object Excel 
            var owb = OXL.Workbooks.Add ();//Get Workbook object 
            var osheet = Owb.activesheet;//Activate current sheet for
            ( var i = 0; i < rows.length; i++) {
                Osheet.cells (i + 1, 1). Value = Rows[i]. o_name;
            }
            oXL.Visible = true; Set Excel visible Properties
}

Second, the above JS method can be successfully implemented the premise is

1. Excel has been installed on the machine.

2.Internet Option => Security =>internet

\ "Initialize and script ActiveX controls that are not marked as safe, set to enable \"

Reproduced from: http://www.stepday.com/topic/?247


//easyui DataGrid dynamically export Excel function Exporterexcel () {//Get datagride column var
            rows = $ (' #tt '). DataGrid (' GetRows ');
            var columns = $ ("#tt"). DataGrid ("Options"). Columns[0]; var oXL = new ActiveXObject ("Excel.Application"); Create Ax object Excel var oWB = OXL.Workbooks.Add (); Gets the Workbook object var osheet = Owb.activesheet;
            Activates the current sheet//Set workbook name osheet.name = "Export Excel Report"; Sets the table header for (var i = 0; i < columns.length i++) {osheet.cells (1, i+1). Value = columns[i].t
            Itle;
                }//Set Content section for (var i = 0; i < rows.length i++) {//dynamically get data values for each column in each row for (var j = 0; J < Columns.length J + +) {osheet.cells (i + 2, j+1). Value = row
                S[i][columns[j].field]; } oxl.visible = true; Set Excel Visible Properties} 


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.