Foros del Web » Programando para Internet » PHP »

Php + jqgrid + excel

Estas en el tema de Php + jqgrid + excel en el foro de PHP en Foros del Web. HOLA AMIGOS, NECESITO DE SU AYUDA..... TENGO UNA PAGINA EN "PHP" DONDE MUESTRO MIS DATOS QUE TENGO EN LA BASE DE DATOS "POSTGRESQL" MEDIANTE UN ...
  #1 (permalink)  
Antiguo 06/08/2013, 14:43
 
Fecha de Ingreso: agosto-2013
Mensajes: 10
Antigüedad: 10 años, 8 meses
Puntos: 0
Php + jqgrid + excel

HOLA AMIGOS, NECESITO DE SU AYUDA..... TENGO UNA PAGINA EN "PHP" DONDE MUESTRO MIS DATOS QUE TENGO EN LA BASE DE DATOS "POSTGRESQL" MEDIANTE UN JQUERY LLAMADO "JQGRID", EL PROBLEMA ES QUE TENGO QUE PASAR ESTOS DATOS DE LA GRILLA A UN ARCHIVO EXCEL.

EN ESTOS MOMENTOS FUNCIONA, PERO EL PROBLEMA ESTA EN EL EXCEL QUE MUESTRA LOS DATOS TODOS JUNTOS (SIN SEPARACIÓN DE FILAS). A CONTINUACIÓN MUESTRO EL CÓDIGO PARA VER SI ALGUIEN PUEDE AYUDARME:

"ACA CREO MI GRILLA"

var creaGrillaActivos = function(){
jQuery("#grillaListado").jqGrid({
url:'validaciones.php?accion=20&q='+$("#id_proyect o").val(),
datatype: "xml",
colNames:[
'Descripcion',
'Nombre Etapa',
'Tarea Afectada',
'Dias Impacto',
'Dias Atraso',
'Fecha',
'Solucion',
'Fecha Solucion',
'Visibilidad',
'Estado',
'Opciones'],
colModel:[
{name:'descripcion',index:'descripcion', align:'left', width:130, sortable:true, resizable:false, title:false},
{name:'nombre_etapa',index:'nombre_etapa', align:'left', width:440, sortable:true, resizable:false, title:false},
{name:'tarea_afectada',index:'tarea_afectada', align:'center', width:120, sortable:true, resizable:false, title:false},
{name:'dias_impacto',index:'dias_impacto', align:'center', width:110, sortable:true, resizable:false, title:false},
{name:'dias_atraso',index:'dias_atraso', align:'center', width:140, sortable:true, resizable:false, title:false},
{name:'fecha_identificacion',index:'fecha_identifi cacion', align:'center', width:160, sortable:true, resizable:false, title:false},
{name:'solucion',index:'solucion', align:'center', width:160, sortable:true, resizable:false, title:false},
{name:'fecha_solucion',index:'fecha_solucion', align:'center', width:160, sortable:true, resizable:false, title:false},
{name:'ind_visibilidad',index:'ind_visibilidad', align:'center', width:160, sortable:true, resizable:false, title:false},
{name:'estado',index:'estado', align:'center', width:160, sortable:true, resizable:false, title:false},
{name:'opciones',index:'opciones', align:'center', width:90, resizable:false}],
shrinkToFit: true,
rowNum:17,
loadtext:'Cargando datos...',
height: "394",
hidegrid: false,
//rowList:[10,20,30],
ignoreCase:true,
sortname: 'descripcion',
viewrecords: false,
pgbuttons:true,
pgtext: null,
recordtext: null,
title:false,
loadonce: true,
sortorder: "asc",
caption:"Listado de Incidencias",
pager: 'pagerListado',

//editurl:"validaciones.php?accion=16",
gridComplete: function(){
var ids = jQuery("#grillaListado").jqGrid('getDataIDs');
for (var i=0;i < ids.length;i++){
var cl = ids[i];
de = "<span class='ui-icon ui-icon-trash' id='eli' title='Eliminar Incidencia' style='display:inline-block' onclick=\"modalEliminaIncidencia("+cl+");\"></span>";
se = "<span class='ui-icon ui-icon-gear' title='Modificar Incidencia' style='display:inline-block' onclick=\"location.href='ingIncidencia.php?id_inci dente="+cl+"'\"></span>";
jQuery("#grillaListado").jqGrid('setRowData',ids[i],{opciones:se+de});
}
}
}).navGrid("#pagerListado",{edit:false,add:false,d el:false,excel:true, search:false, refresh:false}
).navButtonAdd('#pagerListado',{
//caption:"Ingresar Incidencia",
//buttonicon:"ui-icon-document",
//onClickButton: function(){
//location.href='ingIncidencia.php?id_proyecto='+$(" #id_proyecto").val();
caption:"Export to Excel",
buttonicon:"ui-icon-save",
onClickButton: function(){
exportExcel();
},
position:"last"

//}
}

);
}

"LA FUNCIÓN QUE VA A LA PAGINA QUE CONTIENE EL ENCABEZADO DEL EXCEL"

function exportExcel()
{
var mya=new Array();
mya=$("#grillaListado").getDataIDs(); // Get All IDs
var data=$("#grillaListado").getRowData(mya[0]); // Get First row to get the labels
var colNames=new Array();
var ii=0;
for (var i in data){colNames[ii++]=i;} // capture col names
var html="";
for(k=0;k<colNames.length;k++)
{
html=html+colNames[k]+"\t"; // output each Column as tab delimited
}
html=html+"\n"; // Output header with end of line
for(i=0;i<mya.length;i++)
{
data=$("#grillaListado").getRowData(mya[i]); // get each row
for(j=0;j<colNames.length;j++)
{
html=html+data[colNames[j]] + "\t"; // output each Row as tab delimited
}
html=html+"\n"; // output each row with end of line

}
html=html+"\n"; // end of line at the end
document.form1.csvBuffer.value=html;
document.form1.method='POST';
document.form1.action='<?php echo $baseurl;?>csvExport.php'; // send it to server which will open this contents in excel file
document.form1.target='_blank';
document.form1.submit();
}

"Y FINALMENTE LA PAGINA QUE PERMITE ABRIR EL EXCEL"
<?
require "comun.inc.php"; //codigo comun a todas las paginas.


if ($privilegio=='usuario') { // si es usuario no puede ver esta pagina
Util::pagina_mensaje("Usted no tiene acceso a esta pagina", "login.php");
exit;
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Proyectos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script src="js/jquery-latest.js"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>


</head>
<body text="#000000" link="#000000" vlink="#000000" alink="#000000" class="bodyCCIgris">


<?
header('Content-type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=file.xls");
header("Pragma: no-cache");

$buffer = $_POST['csvBuffer'];

try{
echo $buffer;
}catch(Exception $e){

}
?>
</body>
</html>

POR FAVOR SI ALGUIEN PUEDE AYUDARME CON ESTO, SE LOS AGRADECERÍA MUCHO.
  #2 (permalink)  
Antiguo 06/08/2013, 15:20
 
Fecha de Ingreso: agosto-2013
Mensajes: 10
Antigüedad: 10 años, 8 meses
Puntos: 0
Respuesta: Php + jqgrid + excel

Amigos les cuento que reemplace en la función "exportExcel()" el "\n" por "<br>" y me funciono los saltos de linea.. ahora mi problema es que muestra los datos desordenados en excel.. no los muestra por celdas, alguna idea de como poder mostrar los datos por ordenados por celdas??... por favor alguien que me pueda ayudarrrrr....

Última edición por calbo; 07/08/2013 a las 07:52

Etiquetas: excel, html, jqgrid, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:48.