source: www/mysql/libraries/export/xls.php@ 1

Last change on this file since 1 was 1, checked in by george, 17 years ago

Prvotní import všeho

File size: 4.5 KB
Line 
1<?php
2/* $Id: xls.php 9438 2006-09-21 14:28:46Z cybot_tm $ */
3// vim: expandtab sw=4 ts=4 sts=4:
4
5// Check if we have native MS Excel export using PEAR class Spreadsheet_Excel_Writer
6if (!empty($GLOBALS['cfg']['TempDir'])) {
7 @include_once('Spreadsheet/Excel/Writer.php');
8 if (class_exists('Spreadsheet_Excel_Writer')) {
9 $xls = TRUE;
10 } else {
11 $xls = FALSE;
12 }
13} else {
14 $xls = FALSE;
15}
16
17if ($xls) {
18
19 if (isset($plugin_list)) {
20 $plugin_list['xls'] = array(
21 'text' => 'strStrucNativeExcel',
22 'extension' => 'xls',
23 'mime_type' => 'application/vnd.ms-excel',
24 'force_file' => true,
25 'options' => array(
26 array('type' => 'text', 'name' => 'null', 'text' => 'strReplaceNULLBy'),
27 array('type' => 'text', 'name' => 'columns', 'text' => 'strPutColNames'),
28 array('type' => 'hidden', 'name' => 'data'),
29 ),
30 'options_text' => 'strStrucNativeExcelOptions',
31 );
32 } else {
33
34/**
35 * Set of functions used to build MS Excel dumps of tables
36 */
37
38/**
39 * Outputs comment
40 *
41 * @param string Text of comment
42 *
43 * @return bool Whether it suceeded
44 */
45function PMA_exportComment($text)
46{
47 return TRUE;
48}
49
50/**
51 * Outputs export footer
52 *
53 * @return bool Whether it suceeded
54 *
55 * @access public
56 */
57function PMA_exportFooter()
58{
59 global $workbook;
60 global $tmp_filename;
61
62 $res = $workbook->close();
63 if (PEAR::isError($res)) {
64 echo $res->getMessage();
65 return FALSE;
66 }
67 if (!PMA_exportOutputHandler(file_get_contents($tmp_filename))) {
68 return FALSE;
69 }
70 unlink($tmp_filename);
71
72 return TRUE;
73}
74
75/**
76 * Outputs export header
77 *
78 * @return bool Whether it suceeded
79 *
80 * @access public
81 */
82function PMA_exportHeader()
83{
84 global $workbook;
85 global $tmp_filename;
86
87 if (empty($GLOBALS['cfg']['TempDir'])) {
88 return FALSE;
89 }
90 $tmp_filename = tempnam(realpath($GLOBALS['cfg']['TempDir']), 'pma_xls_');
91 $workbook = new Spreadsheet_Excel_Writer($tmp_filename);
92
93 return TRUE;
94}
95
96/**
97 * Outputs database header
98 *
99 * @param string Database name
100 *
101 * @return bool Whether it suceeded
102 *
103 * @access public
104 */
105function PMA_exportDBHeader($db)
106{
107 return TRUE;
108}
109
110/**
111 * Outputs database footer
112 *
113 * @param string Database name
114 *
115 * @return bool Whether it suceeded
116 *
117 * @access public
118 */
119function PMA_exportDBFooter($db)
120{
121 return TRUE;
122}
123
124/**
125 * Outputs create database database
126 *
127 * @param string Database name
128 *
129 * @return bool Whether it suceeded
130 *
131 * @access public
132 */
133function PMA_exportDBCreate($db)
134{
135 return TRUE;
136}
137
138/**
139 * Outputs the content of a table in CSV format
140 *
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
146 *
147 * @return bool Whether it suceeded
148 *
149 * @access public
150 */
151function PMA_exportData($db, $table, $crlf, $error_url, $sql_query)
152{
153 global $what;
154 global $workbook;
155
156 $worksheet =& $workbook->addWorksheet($table);
157 $workbook->setTempDir(realpath($GLOBALS['cfg']['TempDir']));
158
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);
162 $col = 0;
163
164 // If required, get fields name at the first line
165 if (isset($GLOBALS['xls_columns']) && $GLOBALS['xls_columns'] == 'yes') {
166 $schema_insert = '';
167 for ($i = 0; $i < $fields_cnt; $i++) {
168 $worksheet->write(0, $i, stripslashes(PMA_DBI_field_name($result, $i)));
169 } // end for
170 $col++;
171 } // end if
172
173 // Format the data
174 while ($row = PMA_DBI_fetch_row($result)) {
175 $schema_insert = '';
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] != '') {
180 /**
181 * @todo we should somehow handle character set here!
182 */
183 $worksheet->write($col, $j, $row[$j]);
184 } else {
185 $worksheet->write($col, $j, '');
186 }
187 } // end for
188 $col++;
189 } // end while
190 PMA_DBI_free_result($result);
191
192 return TRUE;
193}
194
195 }
196}
197?>
Note: See TracBrowser for help on using the repository browser.