2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Microsoft Office Excel 2007 XLSX import plugin for phpMyAdmin
6 * @todo Pretty much everything
8 * @package phpMyAdmin-Import
11 if (! defined('PHPMYADMIN')) {
16 * The possible scopes for $plugin_param are: 'table', 'database', and 'server'
19 if (isset($plugin_list)) {
20 $plugin_list['xlsx'] = array(
21 'text' => 'strImportXLSX',
22 'extension' => 'xlsx',
24 array('type' => 'bool', 'name' => 'col_names', 'text' => 'strImportColNames'),
26 'options_text' => 'strOptions',
28 /* We do not define function when plugin is just queried for information above */
32 ini_set('memory_limit', '256M');
35 /* Append the PHPExcel directory to the include path variable */
36 set_include_path(get_include_path() . PATH_SEPARATOR
. getcwd() . '/libraries/PHPExcel/');
38 require_once './libraries/PHPExcel/PHPExcel.php';
39 require_once './libraries/PHPExcel/PHPExcel/Reader/Excel2007.php';
41 $objReader = new PHPExcel_Reader_Excel2007();
42 $objReader->setReadDataOnly(true);
43 $objReader->setLoadAllSheets();
44 $objPHPExcel = $objReader->load($import_file);
46 $sheet_names = $objPHPExcel->getSheetNames();
47 $num_sheets = count($sheet_names);
54 for ($s = 0; $s < $num_sheets; ++
$s) {
55 $current_sheet = $objPHPExcel->getSheet($s);
57 $num_rows = $current_sheet->getHighestRow();
58 $num_cols = PMA_getColumnNumberFromName($current_sheet->getHighestColumn());
60 if ($num_rows != 1 && $num_cols != 1) {
61 for ($r = 1; $r <= $num_rows; ++
$r) {
62 for ($c = 0; $c < $num_cols; ++
$c) {
63 $cell = $current_sheet->getCellByColumnAndRow($c, $r)->getCalculatedValue();
65 if (! strcmp($cell, '')) {
76 if ($_REQUEST['xlsx_col_names']) {
77 $col_names = array_splice($rows, 0, 1);
78 $col_names = $col_names[0];
79 for ($j = 0; $j < $num_cols; ++
$j) {
80 if (! strcmp('NULL', $col_names[$j])) {
81 $col_names[$j] = PMA_getColumnAlphaName($j +
1);
85 for ($n = 0; $n < $num_cols; ++
$n) {
86 $col_names[] = PMA_getColumnAlphaName($n +
1);
90 $tables[] = array($sheet_names[$s], $col_names, $rows);
103 /* Obtain the best-fit MySQL types for each column */
106 $len = count($tables);
107 for ($i = 0; $i < $len; ++
$i) {
108 $analyses[] = PMA_analyzeTable($tables[$i]);
112 * string $db_name (no backquotes)
114 * array $table = array(table_name, array() column_names, array()() rows)
115 * array $tables = array of "$table"s
117 * array $analysis = array(array() column_types, array() column_sizes)
118 * array $analyses = array of "$analysis"s
120 * array $create = array of SQL strings
122 * array $options = an associative array of options
125 /* Set database name to the currently selected one, if applicable */
128 $options = array('create_db' => false);
130 $db_name = 'XLSX_DB';
134 /* Non-applicable parameters */
137 /* Created and execute necessary SQL statements from data */
138 PMA_buildSQL($db_name, $tables, $analyses, $create, $options);
146 /* Commit any possible data in buffers */
147 PMA_importRunQuery();