The branch, QA_3_3 has been updated
via 6648c620d917300bfddf6d90555976589844ec19 (commit)
from 8b8562b435c81d72c02e38e1135d5fe0fa48d711 (commit)
- Log -----------------------------------------------------------------
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 1 +
libraries/import.lib.php | 30 ++++++++++++++++++++++--------
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e793238..d6c9af2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,7 @@ master, todo: update PHP excel?)
- bug #3023507 [core] No result set display from stored procedure SELECT
- bug [export] CSV for MS Excel (Windows) should have semi-colon as separator
- [core] Update library PHPExcel to version 1.7.3c
+- bug #2994885 [import] Convert Excel column name correctly
3.3.4.0 (2010-06-28)
- bug #2996161 [import] properly escape import value
diff --git a/libraries/import.lib.php b/libraries/import.lib.php
index 56caeeb..70e5f13 100644
--- a/libraries/import.lib.php
+++ b/libraries/import.lib.php
@@ -344,28 +344,42 @@ function PMA_getColumnAlphaName($num)
/**
* Returns the column number based on the Excel name.
- * So "A" = 1, "AZ" = 27, etc.
+ * So "A" = 1, "Z" = 26, "AA" = 27, etc.
*
- * @author Derek Schaefer (derek.schaefer(a)gmail.com)
+ * Basicly this is a base26 (A-Z) to base10 (0-9) conversion.
+ * It iterates through all characters in the column name and
+ * calculates the corresponding value, based on character value
+ * (A = 1, ..., Z = 26) and position in the string.
*
* @access public
*
* @uses strtoupper()
* @uses strlen()
- * @uses count()
* @uses ord()
* @param string $name (i.e. "A", or "BC", etc.)
* @return int The column number
*/
function PMA_getColumnNumberFromName($name) {
- if (strlen($name) != 0) {
+ if (!empty($name)) {
$name = strtoupper($name);
- $num_chars = count($name);
- $number = 0;
+ $num_chars = strlen($name);
+ $column_number = 0;
for ($i = 0; $i < $num_chars; ++$i) {
- $number += (ord($name[$i]) - 64);
+ // read string from back to front
+ $char_pos = ($num_chars - 1) - $i;
+
+ // convert capital character to ASCII value
+ // and subtract 64 to get corresponding decimal value
+ // ASCII value of "A" is 65, "B" is 66, etc.
+ // Decimal equivalent of "A" is 1, "B" is 2, etc.
+ $number = (ord($name[$char_pos]) - 64);
+
+ // base26 to base10 conversion : multiply each number
+ // with corresponding value of the position, in this case
+ // $i=0 : 1; $i=1 : 26; $i=2 : 676; ...
+ $column_number += $number * pow(26,$i);
}
- return $number;
+ return $column_number;
} else {
return 0;
}
hooks/post-receive
--
phpMyAdmin