-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Simple Excel Plugin
World Wide Web Server edited this page Jul 4, 2012
·
8 revisions
Category:Plugin::Data Conversion
This is a simple plugin to create excel output.
[code]<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
- Excel library for Code Igniter applications
- Author: Federico Ramírez a.k.a fedekun a.k.a lenkun - Feb 2010 */
function to_excel($array, $filename='out') { header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename='.$filename.'.xls');
echo '<table><tr>';
foreach($array[0] as $key=>$val)
echo '<th>'.$key.'</th>';
echo '</tr>';
foreach($array as $key=>$val)
_writeRow($val);
echo '</table>';
}
function _writeRow($row, $isHeader=false) { echo '
'; foreach($row as $r) { if($isHeader) echo ''.$r.''; else echo ''.$r.''; } echo ''; }[/code]Example usage
[code]to_excel($this->model->getUsersAsArray());[/code]