|
|
|
@ -103,13 +103,16 @@ void _showExcelCompatibilityError() { |
|
|
|
|
|
|
|
Future<void> _downloadExcelTemplate() async { |
|
|
|
try { |
|
|
|
// Créez un nouveau fichier Excel |
|
|
|
final excel = Excel.createExcel(); |
|
|
|
excel.delete('Sheet1'); |
|
|
|
excel.copy('Sheet1', 'Produits'); |
|
|
|
|
|
|
|
// Supprimez la feuille par défaut si elle existe |
|
|
|
excel.delete('Sheet1'); |
|
|
|
|
|
|
|
// Créez une nouvelle feuille nommée "Produits" |
|
|
|
final sheet = excel['Produits']; |
|
|
|
|
|
|
|
// Ajoutez les en-têtes |
|
|
|
final headers = ['Nom', 'Prix', 'Catégorie', 'Description', 'Stock']; |
|
|
|
for (int i = 0; i < headers.length; i++) { |
|
|
|
final cell = sheet.cell(CellIndex.indexByColumnRow(columnIndex: i, rowIndex: 0)); |
|
|
|
@ -120,6 +123,7 @@ Future<void> _downloadExcelTemplate() async { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// Ajoutez des exemples de données |
|
|
|
final examples = [ |
|
|
|
['Croissant', '1.50', 'Sucré', 'Délicieux croissant beurré', '20'], |
|
|
|
['Sandwich jambon', '4.00', 'Salé', 'Sandwich fait maison', '15'], |
|
|
|
@ -134,12 +138,14 @@ Future<void> _downloadExcelTemplate() async { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Définissez la largeur des colonnes |
|
|
|
sheet.setColWidth(0, 20); |
|
|
|
sheet.setColWidth(1, 10); |
|
|
|
sheet.setColWidth(2, 15); |
|
|
|
sheet.setColWidth(3, 30); |
|
|
|
sheet.setColWidth(4, 10); |
|
|
|
|
|
|
|
// Sauvegardez le fichier Excel |
|
|
|
final bytes = excel.save(); |
|
|
|
|
|
|
|
if (bytes == null) { |
|
|
|
@ -147,6 +153,7 @@ Future<void> _downloadExcelTemplate() async { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Demandez à l'utilisateur où sauvegarder le fichier |
|
|
|
final String? outputFile = await FilePicker.platform.saveFile( |
|
|
|
fileName: 'modele_import_produits.xlsx', |
|
|
|
allowedExtensions: ['xlsx'], |
|
|
|
@ -155,6 +162,7 @@ Future<void> _downloadExcelTemplate() async { |
|
|
|
|
|
|
|
if (outputFile != null) { |
|
|
|
try { |
|
|
|
// Écrivez les données dans le fichier |
|
|
|
await File(outputFile).writeAsBytes(bytes); |
|
|
|
Get.snackbar( |
|
|
|
'Succès', |
|
|
|
@ -173,6 +181,7 @@ Future<void> _downloadExcelTemplate() async { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Future<void> _importFromExcel() async { |
|
|
|
try { |
|
|
|
final result = await FilePicker.platform.pickFiles( |
|
|
|
|