3 // vim: expandtab sw=4 ts=4 sts=4:
5 require_once('Spreadsheet/Excel/Writer.php');
8 * Set of functions used to build MS Excel dumps of tables
14 * @param string Text of comment
16 * @return bool Whether it suceeded
18 function PMA_exportComment($text) {
23 * Outputs export footer
25 * @return bool Whether it suceeded
29 function PMA_exportFooter() {
33 $res = $workbook->close();
34 if (PEAR
::isError($res)) {
35 echo $res->getMessage();
38 if (!PMA_exportOutputHandler(file_get_contents($tmp_filename))) return FALSE;
39 unlink($tmp_filename);
45 * Outputs export header
47 * @return bool Whether it suceeded
51 function PMA_exportHeader() {
55 if (empty($GLOBALS['cfg']['TempDir'])) return FALSE;
56 $tmp_filename = tempnam(realpath($GLOBALS['cfg']['TempDir']), 'pma_xls_');
57 $workbook = new Spreadsheet_Excel_Writer($tmp_filename);
63 * Outputs database header
65 * @param string Database name
67 * @return bool Whether it suceeded
71 function PMA_exportDBHeader($db) {
76 * Outputs database footer
78 * @param string Database name
80 * @return bool Whether it suceeded
84 function PMA_exportDBFooter($db) {
89 * Outputs create database database
91 * @param string Database name
93 * @return bool Whether it suceeded
97 function PMA_exportDBCreate($db) {
102 * Outputs the content of a table in CSV format
104 * @param string the database name
105 * @param string the table name
106 * @param string the end of line sequence
107 * @param string the url to go back in case of error
108 * @param string SQL query for obtaining data
110 * @return bool Whether it suceeded
114 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
118 $worksheet =& $workbook->addWorksheet($table);
119 $workbook->setTempDir(realpath($GLOBALS['cfg']['TempDir']));
121 // Gets the data from the database
122 $result = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED
);
123 $fields_cnt = PMA_DBI_num_fields($result);
126 // If required, get fields name at the first line
127 if (isset($GLOBALS['xls_shownames']) && $GLOBALS['xls_shownames'] == 'yes') {
129 for ($i = 0; $i < $fields_cnt; $i++
) {
130 $worksheet->write(0, $i, stripslashes(PMA_DBI_field_name($result, $i)));
136 while ($row = PMA_DBI_fetch_row($result)) {
138 for ($j = 0; $j < $fields_cnt; $j++
) {
139 if (!isset($row[$j]) ||
is_null($row[$j])) {
140 $worksheet->write($col, $j, $GLOBALS['xls_replace_null']);
141 } else if ($row[$j] == '0' ||
$row[$j] != '') {
142 // FIXME: we should somehow handle character set here!
143 $worksheet->write($col, $j, $row[$j]);
145 $worksheet->write($col, $j, '');
150 PMA_DBI_free_result($result);