diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7454923f94a..fc743889b28 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -183,6 +183,21 @@ function isASecretKey($keyname) return preg_match('/(_pass|password|_pw|_key|securekey|serverkey|secret\d?|p12key|exportkey|_PW_[a-z]+|token)$/i', $keyname); } + +/** + * 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 + */ +function num2Alpha($n) +{ + for ($r = ""; $n >= 0; $n = intval($n / 26) - 1) + $r = chr($n % 26 + 0x41) . $r; + return $r; +} + + /** * Return information about user browser * diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index b96e6706550..a7fcf6f0d0f 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', $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 427e6a4dea6..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 ''; @@ -2349,20 +2349,6 @@ function show_elem($fieldssource, $pos, $key, $var, $nostyle = '') } -/** - * Return a numeric into an Excel like column number - * - * @param string $n Numeric value - * @return string Column in Excel format - */ -function num2Alpha($n) -{ - for ($r = ""; $n >= 0; $n = intval($n / 26) - 1) - $r = chr($n%26 + 0x41) . $r; - return $r; -} - - /** * Return not used field number * diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 9dc400f91f7..c6dd04fd488 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -82,7 +82,7 @@ SelectFormat=Choose this import file format RunImportFile=Import Data NowClickToRunTheImport=Check the results of the import simulation. Correct any errors and re-test.
When the simulation reports no errors you may proceed to import the data into the database. DataLoadedWithId=The imported data will have an additional field in each database table with this import id: %s, to allow it to be searchable in the case of investigating a problem related to this import. -ErrorMissingMandatoryValue=Mandatory data is empty in the source file for field %s. +ErrorMissingMandatoryValue=Mandatory data is empty in the source file in column %s. TooMuchErrors=There are still %s other source lines with errors but output has been limited. TooMuchWarnings=There are still %s other source lines with warnings but output has been limited. EmptyLine=Empty line (will be discarded) @@ -92,9 +92,9 @@ YouCanUseImportIdToFindRecord=You can find all the imported records in your data NbOfLinesOK=Number of lines with no errors and no warnings: %s. NbOfLinesImported=Number of lines successfully imported: %s. DataComeFromNoWhere=Value to insert comes from nowhere in source file. -DataComeFromFileFieldNb=Value to insert comes from field number %s in source file. -DataComeFromIdFoundFromRef=Value that comes from field number %s of source file will be used to find the id of the parent object to use (so the object %s that has the ref. from source file must exist in the database). -DataComeFromIdFoundFromCodeId=Code that comes from field number %s of source file will be used to find the id of the parent object to use (so the code from source file must exist in the dictionary %s). Note that if you know the id, you can also use it in the source file instead of the code. Import should work in both cases. +DataComeFromFileFieldNb=Value to insert comes from column %s in source file. +DataComeFromIdFoundFromRef=Value that comes from column %s of source file will be used to find the id of the parent object to use (so the object %s that has the ref. from source file must exist in the database). +DataComeFromIdFoundFromCodeId=Code that comes from column %s of source file will be used to find the id of the parent object to use (so the code from source file must exist in the dictionary %s). Note that if you know the id, you can also use it in the source file instead of the code. Import should work in both cases. DataIsInsertedInto=Data coming from source file will be inserted into the following field: DataIDSourceIsInsertedInto=The id of the parent object, that was found using the data in the source file, will be inserted into the following field: DataCodeIDSourceIsInsertedInto=The id of the parent line, that was found from code, will be inserted into the following field: 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 *