Skip to content

Commit

Permalink
allowing access to data through column index
Browse files Browse the repository at this point in the history
  • Loading branch information
julienmru committed Feb 26, 2016
1 parent 72f52a9 commit 84fe065
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -8,6 +8,8 @@ Ce plugin permet d’utiliser des fichiers XLS, XLSX ou ODS dans des boucles DAT
<BOUCLE_fichier_openoffice(DATA){source ods,monfichier.ods}>
```

La première ligne est considérée comme le titre des colonnes. Vous pouvez ensuite accéder aux données via #TITRE_DE_LA_COLONNE (si le titre est "Titre de la colonne") ou #COL_A (pour la colonne A).

## Librairies tierces utilisées

### [spreadsheet-reader](https://github.com/nuovo/spreadsheet-reader) de Martins Pilsetnieks
Expand Down
12 changes: 11 additions & 1 deletion iterateur_xls_options.php
Expand Up @@ -18,7 +18,9 @@ function iterateur_xls_convert(&$reader) {
$v = preg_replace('/__+/', '_', $v);
$v = trim($v, '_');
$header[$v] = $k;
$header['col_'.iterateur_xls_num2alpha($k)] = $k;
}

} else {
$data = [];
foreach($header as $k => $v) {
Expand All @@ -30,4 +32,12 @@ function iterateur_xls_convert(&$reader) {
}

return $datas;
}
}

// Source : http://stackoverflow.com/questions/3302857/algorithm-to-get-the-excel-like-column-name-of-a-number
function iterateur_xls_num2alpha($n)
{
for($r = ""; $n >= 0; $n = intval($n / 26) - 1)
$r = chr($n%26 + 0x61) . $r;
return $r;
}
4 changes: 2 additions & 2 deletions paquet.xml
@@ -1,8 +1,8 @@
<paquet
prefix="iterateur_xls"
categorie="outil"
version="1.0.2"
etat="dev"
version="1.0.3"
etat="test"
compatibilite="[3.0.0;3.1.*]"
documentation="http://contrib.spip.net/iterateur_xls"
logo="images/logo_iterateur_xls_32.png"
Expand Down

0 comments on commit 84fe065

Please sign in to comment.