EasyUI
Home
Demo
Tutorial
Documentation
Download
Extension
Contact
Forum
EasyUI Forum
May 04, 2024, 08:44:48 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
:
Home
Help
Search
Login
Register
EasyUI Forum
>
General Category
>
General Discussion
>
I want to share with you, my export to excel (csv) method.
Pages: [
1
]
« previous
next »
Print
Author
Topic: I want to share with you, my export to excel (csv) method. (Read 6613 times)
jmansur
Newbie
Posts: 31
I want to share with you, my export to excel (csv) method.
«
on:
August 31, 2015, 08:35:50 AM »
Hi.
I want to share with you, my export to excel method.
Regardssssss
// ******************************************************************************
// Extiende la fucnionalidad de un datagrid para que exporte a excel
// ******************************************************************************
$.extend($.fn.datagrid.methods, {
toExcel
: function(jq, filename){
return jq.each(function(){
// *****************************************************************
// Remueve y agrega un formulario al BODY con los siguientes campos
// REP_FILENAME : Nombre del archivo a exportar
// REP_TITULOS : Nombre de las columnas
// REP_DATOS : TextArea donde se almacenan los datos de datagrid
// *****************************************************************
$('#idDescargar').remove();
var strForm = '<form id="idDescargar" action="descargar.asp" method="post"><input type="text" name="REP_EASYUI" value="SI"><input type="text" id="REP_FILENAME" name="REP_FILENAME" value=""><input id="REP_TITULOS" type="text" name="REP_TITULOS" value=""><textarea id="REP_DATOS" name="REP_DATOS" cols="" rows=""></textarea></form>';
var WinDiv = $(strForm).appendTo('body');
// *****************************************
// Toma los nombres de las columnas del GRID
// *****************************************
var Titulos = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields',false));
// ***************************
// Separador de los datos
// ***************************
var RepTitulos = Titulos.join(';');
// ***************************
// Toma los datos del datagrid
// ***************************
var data = $(this).datagrid('getData');
var strRow = '';
for(var i=0; i<data.rows.length; i++){
row = data.rows
;
for(var j=0; j<Titulos.length; j++){
if( typeof Titulos[j] == 'undefined' )
col = '""';
else
col = '"' + row[Titulos[j]].replace(/"/g, '""') + '"';
strRow = strRow + col + ';';
}
strRow = strRow + String.fromCharCode(13);
}
// ***************************
// Completa los campos
// ***************************
$('#REP_FILENAME').val(filename);
$('#REP_TITULOS').val(RepTitulos);
$('#REP_DATOS').val(strRow);
// ***************************
// Submit del formulario
// ***************************
$("#idDescargar").submit();
})
}
});
descargar.asp
<%
strFileName = Request.Form("REP_FILENAME")
Response.ContentType = "application/csv"
Response.AddHeader "Content-Disposition", "attachment;filename="&strFileName&";"
REP_TITULOS = Request.Form("REP_TITULOS")
REP_DATOS = Request.Form("REP_DATOS")
Response.Write( REP_TITULOS )
Response.Write(CHR(13))
Response.Write( REP_DATOS )
Response.Write(CHR(13))
response.End()
%>
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> News
=> General Discussion
=> EasyUI for jQuery
=> EasyUI for Angular
=> EasyUI for Vue
=> EasyUI for React
=> Bug Report
Loading...