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}