diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c3227489507..fc743889b28 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -185,7 +185,7 @@ function isASecretKey($keyname) /** - * Return a numeric value into an Excel like column number. So 1 return 'A', 2 returns 'B'..., 27 return 'AA' + * Return a numeric value into an Excel like column number. So 0 return 'A', 1 returns 'B'..., 26 return 'AA' * * @param int|string $n Numeric value * @return string Column in Excel format diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index a058fd0174a..c3339a0a138 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -1,6 +1,6 @@ - * Copyright (C) 2009-2012 Regis Houssin +/* Copyright (C) 2006-2012 Laurent Destailleur + * Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2012 Christophe Battarel * Copyright (C) 2012-2016 Juanjo Menent * @@ -446,7 +446,7 @@ class ImportXlsx extends ModeleImports // Is it a required field ? if (preg_match('/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval == '')) { - $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', num2Alpha($key)); + $this->errors[$error]['lib'] = $langs->trans('ErrorMissingMandatoryValue', num2Alpha($key - 1)); $this->errors[$error]['type'] = 'NOTNULL'; $errorforthistable++; $error++; diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 4209b5e9e96..bf335b9714b 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -1743,7 +1743,7 @@ if ($step == 5 && $datatoimport) { } //print $code.'-'.$label; $alias = preg_replace('/(\..*)$/i', '', $label); - $listfields[$i] = $langs->trans("Field").' '.$code.'->'.$label; + $listfields[$i] = $langs->trans("Column").' '.num2Alpha($code - 1).' -> '.$label; } print count($listfields) ? (join(', ', $listfields)) : $langs->trans("Error"); print ''; diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 1bf3b6378fb..82205369c86 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -166,6 +166,26 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; } + /** + * testNum2Alpha + * + * @return void + */ + public function testNum2Alpha() + { + $result = num2Alpha(0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'A', 'Check num2Alpha 0'); + + $result = num2Alpha(5); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'F', 'Check num2Alpha 5'); + + $result = num2Alpha(26); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'AA', 'Check num2Alpha 26'); + } + /** * testIsValidEmail *