/ Published in: PHP
URL: http://www.thosecleverkids.com/blog/2009/02/23/php-excel-exporter/
Expand |
Embed | Plain Text
require_once("data-class.php"); class ExcelExporter { var $date_format = "m/d/y"; var $debug = false; var $filename = "export.xls"; var $timestamp_file = false; var $_conn = false; function ExcelExporter() { $this->_conn = new DataConnection(); } function set_filename($name) { $this->_filename = $name; } function export($sql) { $this->_conn->query($sql); if (!$this->debug) { $this->_serve_excel_headers(); } if ($this->_conn->getNumberOfRows() == 0) { return $this->_get_table(false); } return $this->_get_table($this->_conn->getResultSet()); } /* INTERNALS */ function _get_table($results) { $table = "<table border=\"1\">\n"; $table .= $this->_get_header_row(); if ($results) { foreach($results as $info) { $table .= "\n<tr>"; foreach($info as $k => $v) { } $table .= "\n</tr>"; } } $table .= "\n</table>"; return $table; } function _get_header_row() { $output = "\n<tr>"; foreach ($this->column_heads as $header) { } $output .= "\n</tr>"; return $output; } function _format_field($name, $value) { { return $value; } } function _serve_excel_headers() { } function _get_filename() { $name = $this->filename; if (!$this->timestamp_file) { return $name; } $stamped_name = $pieces[0].$now; { $stamped_name .= ".".$pieces[1]; } return $stamped_name; } }
You need to login to post a comment.
