Documentation TYPO3 par Ameos

xls.php

00001 <?php
00002 /* $Id: xls.php,v 2.0 2004/10/13 09:59:56 rabus Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00005 require_once('Spreadsheet/Excel/Writer.php');
00006 
00018 function PMA_exportComment($text) {
00019     return TRUE;
00020 }
00021 
00029 function PMA_exportFooter() {
00030     global $workbook;
00031     global $tmp_filename;
00032 
00033     $res = $workbook->close();
00034     if (PEAR::isError($res)) {
00035         echo $res->getMessage();
00036         return FALSE;
00037     }
00038     if (!PMA_exportOutputHandler(file_get_contents($tmp_filename))) return FALSE;
00039     unlink($tmp_filename);
00040 
00041     return TRUE;
00042 }
00043 
00051 function PMA_exportHeader() {
00052     global $workbook;
00053     global $tmp_filename;
00054 
00055     if (empty($GLOBALS['cfg']['TempDir'])) return FALSE;
00056     $tmp_filename = tempnam(realpath($GLOBALS['cfg']['TempDir']), 'pma_xls_');
00057     $workbook = new Spreadsheet_Excel_Writer($tmp_filename);
00058 
00059     return TRUE;
00060 }
00061 
00071 function PMA_exportDBHeader($db) {
00072     return TRUE;
00073 }
00074 
00084 function PMA_exportDBFooter($db) {
00085     return TRUE;
00086 }
00087 
00097 function PMA_exportDBCreate($db) {
00098     return TRUE;
00099 }
00100 
00114 function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) {
00115     global $what;
00116     global $workbook;
00117 
00118     $worksheet =& $workbook->addWorksheet($table);
00119     $workbook->setTempDir(realpath($GLOBALS['cfg']['TempDir']));
00120 
00121     // Gets the data from the database
00122     $result      = PMA_DBI_query($sql_query, NULL, PMA_DBI_QUERY_UNBUFFERED);
00123     $fields_cnt  = PMA_DBI_num_fields($result);
00124     $col         = 0;
00125 
00126     // If required, get fields name at the first line
00127     if (isset($GLOBALS['xls_shownames']) && $GLOBALS['xls_shownames'] == 'yes') {
00128         $schema_insert = '';
00129         for ($i = 0; $i < $fields_cnt; $i++) {
00130             $worksheet->write(0, $i, stripslashes(PMA_DBI_field_name($result, $i)));
00131         } // end for
00132         $col++;
00133     } // end if
00134 
00135     // Format the data
00136     while ($row = PMA_DBI_fetch_row($result)) {
00137         $schema_insert = '';
00138         for ($j = 0; $j < $fields_cnt; $j++) {
00139             if (!isset($row[$j]) || is_null($row[$j])) {
00140                 $worksheet->write($col, $j, $GLOBALS['xls_replace_null']);
00141             } else if ($row[$j] == '0' || $row[$j] != '') {
00142                 // FIXME: we should somehow handle character set here!
00143                 $worksheet->write($col, $j, $row[$j]);
00144             } else {
00145                 $worksheet->write($col, $j, '');
00146             }
00147         } // end for
00148         $col++;
00149     } // end while
00150     PMA_DBI_free_result($result);
00151 
00152     return TRUE;
00153 }
00154 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6