[Phpmyadmin-git] [SCM] phpMyAdmin branch, master, updated. RELEASE_3_3_4-5363-ge31dcc1
Dieter Adriaenssens
ruleant at users.sourceforge.net
Wed Jul 14 22:34:12 CEST 2010
The branch, master has been updated
via e31dcc11ef49bec67b2d89774116449928a56c5f (commit)
via dbe5daaad3ffa049497c18030ca1f12628fa9057 (commit)
from a038d59f7a0524a00682e8a7e2f3e4cda781f98a (commit)
- Log -----------------------------------------------------------------
commit e31dcc11ef49bec67b2d89774116449928a56c5f
Merge: a038d59f7a0524a00682e8a7e2f3e4cda781f98a dbe5daaad3ffa049497c18030ca1f12628fa9057
Author: Dieter Adriaenssens <ruleant at users.sourceforge.net>
Date: Wed Jul 14 22:32:10 2010 +0200
Merge branch 'QA_3_3'
Conflicts:
libraries/import.lib.php
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 2 +-
libraries/import.lib.php | 68 ++++++++++++++++++++++++++++-----------------
2 files changed, 43 insertions(+), 27 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c8ac8a2..83c2860 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -100,7 +100,7 @@ $Id$
- 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
+- bug #2994885, bug #3029168 [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 cd8741c..85d6870 100644
--- a/libraries/import.lib.php
+++ b/libraries/import.lib.php
@@ -304,7 +304,19 @@ function PMA_importGetNextChunk($size = 32768)
/**
* Returns the "Excel" column name (i.e. 1 = "A", 26 = "Z", 27 = "AA", etc.)
- * This algorithm only works up to ZZ. it fails on AAA (up to 701 columns)
+ *
+ * This functions uses recursion to build the Excel column name.
+ *
+ * The column number (1-26) is converted to the responding ASCII character (A-Z) and returned.
+ *
+ * If the column number is bigger than 26 (= num of letters in alfabet),
+ * an extra character needs to be added. To find this extra character, the number is divided by 26
+ * and this value is passed to another instance of the same function (hence recursion).
+ * In that new instance the number is evaluated again, and if it is still bigger than 26, it is divided again
+ * and passed to another instance of the same function. This continues until the number is smaller than 26.
+ * Then the last called function returns the corresponding ASCII character to the function that called it.
+ * Each time a called function ends an extra character is added to the column name.
+ * When the first function is reached, the last character is addded and the complete column name is returned.
*
* @access public
*
@@ -314,31 +326,35 @@ function PMA_importGetNextChunk($size = 32768)
*/
function PMA_getColumnAlphaName($num)
{
- /* ASCII value for capital "A" */
- $A = 65;
- $sCol = "";
- $iRemain = 0;
-
- /* This algorithm only works up to ZZ. it fails on AAA */
-
- if ($num > 701) {
- return $num;
- } elseif ($num <= 26) {
- if ($num == 0) {
- $sCol = chr(($A + 26) - 1);
- } else {
- $sCol = chr(($A + $num) - 1);
- }
- } else {
- $iRemain = (($num / 26)) - 1;
- if (($num % 26) == 0) {
- $sCol = PMA_getColumnAlphaName($iRemain) . PMA_getColumnAlphaName($num % 26);
- } else {
- $sCol = chr($A + $iRemain) . PMA_getColumnAlphaName($num % 26);
- }
- }
-
- return $sCol;
+ $A = 65; // ASCII value for capital "A"
+ $col_name = "";
+
+ if ($num > 26) {
+ $div = (int)($num / 26);
+ $remain = (int)($num % 26);
+
+ // subtract 1 of divided value in case the modulus is 0,
+ // this is necessary because A-Z has no 'zero'
+ if ($remain == 0) {
+ $div--;
+ }
+
+ // recursive function call
+ $col_name = PMA_getColumnAlphaName($div);
+ // use modulus as new column number
+ $num = $remain;
+ }
+
+ if ($num == 0) {
+ // use 'Z' if column number is 0,
+ // this is necessary because A-Z has no 'zero'
+ $col_name .= chr(($A + 26) - 1);
+ } else {
+ // convert column number to ASCII character
+ $col_name .= chr(($A + $num) - 1);
+ }
+
+ return $col_name;
}
/**
hooks/post-receive
--
phpMyAdmin
More information about the Git
mailing list