2
/* $Id: xls.php 9438 2006-09-21 14:28:46Z cybot_tm $ */
3
// vim: expandtab sw=4 ts=4 sts=4:
5
// Check if we have native MS Excel export using PEAR class Spreadsheet_Excel_Writer
6
if (!empty($GLOBALS['cfg']['TempDir'])) {
7
@include_once('Spreadsheet/Excel/Writer.php');
8
if (class_exists('Spreadsheet_Excel_Writer')) {
19
if (isset($plugin_list)) {
20
$plugin_list['xls'] = array(
21
'text' => 'strStrucNativeExcel',
23
'mime_type' => 'application/vnd.ms-excel',
26
array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
27
array('type' => 'text', 'name' => 'columns', 'text' => 'strPutColNames'),
28
array('type' => 'hidden', 'name' => 'data'),
30
'options_text' => 'strStrucNativeExcelOptions',
35
* Set of functions used to build MS Excel dumps of tables
41
* @param string Text of comment
43
* @return bool Whether it suceeded
45
function PMA_exportComment($text)
51
* Outputs export footer
53
* @return bool Whether it suceeded
57
function PMA_exportFooter()
62
$res = $workbook->close();
63
if (PEAR::isError($res)) {
64
echo $res->getMessage();
67
if (!PMA_exportOutputHandler(file_get_contents($tmp_filename))) {
70
unlink($tmp_filename);
76
* Outputs export header
78
* @return bool Whether it suceeded
82
function PMA_exportHeader()
87
if (empty($GLOBALS['cfg']['TempDir'])) {
90
$tmp_filename = tempnam(realpath($GLOBALS['cfg']['TempDir']), 'pma_xls_');
91
$workbook = new Spreadsheet_Excel_Writer($tmp_filename);
97
* Outputs database header
99
* @param string Database name
101
* @return bool Whether it suceeded
105
function PMA_exportDBHeader($db)
111
* Outputs database footer
113
* @param string Database name
115
* @return bool Whether it suceeded
119
function PMA_exportDBFooter($db)
125
* Outputs create database database
127
* @param string Database name
129
* @return bool Whether it suceeded
133
function PMA_exportDBCreate($db)
139
* Outputs the content of a table in CSV format
141
* @param string the database name
142
* @param string the table name
143
* @param string the end of line sequence
144
* @param string the url to go back in case of error
145
* @param string SQL query for obtaining data
147
* @return bool Whether it suceeded
151
function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
156
$worksheet =& $workbook->addWorksheet($table);
157
$workbook->setTempDir(realpath($GLOBALS['cfg']['TempDir']));
159
// Gets the data from the database
160
$result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED);
161
$fields_cnt = PMA_DBI_num_fields($result);
164
// If required, get fields name at the first line
165
if (isset($GLOBALS['xls_columns']) && $GLOBALS['xls_columns'] == 'yes') {
167
for ($i = 0; $i < $fields_cnt; $i++) {
168
$worksheet->write(0, $i, stripslashes(PMA_DBI_field_name($result, $i)));
174
while ($row = PMA_DBI_fetch_row($result)) {
176
for ($j = 0; $j < $fields_cnt; $j++) {
177
if (!isset($row[$j]) || is_null($row[$j])) {
178
$worksheet->write($col, $j, $GLOBALS['xls_null']);
179
} elseif ($row[$j] == '0' || $row[$j] != '') {
181
* @todo we should somehow handle character set here!
183
$worksheet->write($col, $j, $row[$j]);
185
$worksheet->write($col, $j, '');
190
PMA_DBI_free_result($result);