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