Excel output with codeigniter Excel output with codeigniter codeigniter codeigniter

Excel output with codeigniter


I'll refer you to this wiki article from the codeIgniter site, or to this tutorial


use PHPExcel Library

put the class folder in your codeigniter application library and call the PHPExcel class

this works fine with codeigniter


If you need something quick and dirty (and potentially working in FF only), I use this JS solution:

function exportExcel(html) {window.open('data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent('<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=ProgId content=Excel.Sheet><style>body {font-family:Arial} .ean {mso-number-format:0000000000000;}</style></head><body><table>'+html.replace(/[♫^]/gi,'')+'</table></body></html>'));}

And then following link in caption tag of the table

<a href="#" onclick="javascript:exportExcel($(this).parents(".table1").html());">Excel</a>

It will open as HTML Worksheet, which works for me. As you can see in JS funciton code, you can add styles to columns and/or replace some chars you don't need in the output.