buildExcel method

Future<Uint8List?> buildExcel(
  1. List<String> keys,
  2. List<List> values, {
  3. String? sheetName,
})

Implementation

Future<Uint8List?> buildExcel(List<String> keys, List<List<dynamic>> values, {String? sheetName} ) async {
  try {
    var excel = Excel.createExcel();
    Sheet sheetObject = excel[sheetName ?? 'Sheet1'];

    sheetObject.appendRow(keys); // Agregar encabezados
    for (var value in values) { sheetObject.appendRow(value); } // agregar filas

    List<int>? bytes = excel.encode(); // Guardar archivo en almacenamiento temporal
    if (bytes == null) throw 'base64 null';
    return Uint8List.fromList(bytes);
  } catch (e) {
    throw 'buildExcel: ${e.toString()}';
  }
}