use Cubist\Backpack\Magic\Fields\SelectFromArray;
use Cubist\Backpack\Magic\Fields\StandardFile;
+use Cubist\Backpack\Magic\Fields\Text;
use Cubist\Backpack\Magic\Form;
use Cubist\Excel\ExcelToArray;
use Symfony\Component\HttpFoundation\File\UploadedFile;
{
return [
'excelToArray' => ['label' => __('Conforme à la source'), 'function' => 'excelToArrayRaw'],
- 'excelToArrayFirstSheet' => ['label' => __('Conforme à la source') . ' (' . __('Première feuille uniquement') . ')', 'function' => 'excelToArrayFirstSheet'],
+ 'excelToArrayFirstSheet' => ['label' => __('Conforme à la source') . ' (' . __('Une feuille uniquement') . ')', 'function' => 'excelToArrayFirstSheet'],
'excelToArrayKeyVars' => ['label' => __('Liste nommée par le titre de colonne') . ' (' . __('Clés = valeur de la colonne A') . ')'],
'excelToArrayIndexKeyVars' => ['label' => __('Liste nommée par le titre de colonne') . ' (' . __('Clés = nombres séquentiels') . ')'],
'excelToArrayKeyVal' => ['label' => __('Couples clé (colonne A) / valeur (colonne B)')],
}
$form->addField('dataorg', SelectFromArray::class, __('Type'), ['allows_null' => false, 'default' => 'excelToArray', 'options' => $options]);
+ $form->addField('sheet', Text::class, __('Feuille'), ['hint' => __('Laisser vide pour utiliser la première feuille'), 'when' => ['dataorg' => ['excelToArrayFirstSheet', 'excelToArrayIndexKeyVars', 'excelToArrayIndexKeyVars', 'excelToArrayKeyVal', 'excelToArrayKeyValMulti']]]);
$form->addField('format', SelectFromArray::class, __('Format de sortie'), ['allows_null' => false, 'default' => 'json', 'options' =>
[
'json' => 'JSON',
]
]
);
+ $form->addField('varname', Text::class, __('Nom de la variable'), ['when' => ['format' => 'js'], 'default' => 'DATA']);
return view('tools.form', ['form' => $form]);
}
}
$function = $dataOrgs[$dataorg]['function'] ?? $dataorg;
- $res = ExcelToArray::$function($file->getPathname());
+ $res = ExcelToArray::$function($file->getPathname(), request()->input('sheet', ''));
if ($format === 'json') {
return response()->json($res);
}
if ($format === 'js') {
- return response('var DATA=' . json_encode($res) . ';')->header('Content-Type', 'text/plain');
+ return response('var ' . request()->input('varname', 'DATA') . '=' . json_encode($res) . ';')->header('Content-Type', 'text/plain');
}
}
}