⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Export data via Excel, pdf...



midnigther

midnigther
  • profile picture
  • Member

Posted 29 August 2012 - 01:24 AM

Hey folks, I saw a grid with buttons to export data from GroceryCrud API List (here).
Somebody could post any example how to do that.

carlinchisart

carlinchisart
  • profile picture
  • Member

Posted 29 August 2012 - 02:56 AM

see this for pdf

http://domain-script-donzruth.blogspot.com/2011/01/exsport-to-pdf-with-dompdf-in-code.html

and for excel I create a one library bassed in this code


<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ficheroexcel{

function crearFichero($datos,$nombre){
header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: filename=$nombre.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $datos;
}

}

and use the jquery code in the view,


<form action="<?php echo site_url('informes/generarExcel/anticipos');?>" method="post" target="_blank" id="FormularioExportacion">
<p>Exportar a Excel <img src="<?php echo base_url().'images/excel.jpg';?>" class="botonExcel" /></p>
<input type="hidden" id="datos_a_enviar" name="datos_a_enviar" />


see this

http://webintenta.com/exportar-tablas-html-a-excel-con-php-y-jquery.html

and the controller function


function generarExcel($ruta){
$datos=$_POST['datos_a_enviar'];
$this->load->library('ficheroexcel');
$this->ficheroexcel->crearFichero($datos,$ruta);
}