I am beginner in flutter,i have need convert my response data to excel & after that i can download it. I am already use this package to convert my response data to excel https://pub.dev/packages/excel/versions/2.0.0-null-safety-3, but the problem i dont know how to download it to my device/emulator device.
here my try implementation
import 'dart:io';
import 'package:excel/excel.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
...
void _Download() async {
final status = await Permission.storage.request();
if (status.isGranted) {
var excel = Excel.createExcel();
Sheet sheetObject = excel['sheet1'];
CellStyle cellStyle = CellStyle(
backgroundColorHex: "#1AFF1A",
fontFamily: getFontFamily(FontFamily.Calibri));
cellStyle.underline = Underline.Single; // or Underline.Double
var cell = sheetObject.cell(CellIndex.indexByString("A1"));
cell.value = 8; // dynamic values support provided;
cell.cellStyle = cellStyle;
// printing cell-type
print("CellType: " cell.cellType.toString());
///
/// Inserting and removing column and rows
// insert column at index = 8
sheetObject.insertColumn(8);
// remove column at index = 18
sheetObject.removeColumn(18);
// insert row at index = 82
sheetObject.insertRow(82);
// remove row at index = 80
sheetObject.removeRow(80);
var fileBytes = excel.save();
var directory = await getApplicationDocumentsDirectory();
File(directory.path "/dongle.xlsx")
..createSync(recursive: true)
..writeAsBytesSync(fileBytes ?? []);
} else {
print('no permission');
}
}
output for directory.path
/data/user/0/com.example.myproject/app_flutter
CodePudding user response:
You can copy that file to the Download folder by that you can have that file in your download folder.
File file = File(directory.path "/dongle.xlsx")
..createSync(recursive: true)
..writeAsBytesSync(fileBytes ?? []);
file.copy('/storage/emulated/0/Download/dongle.xlsx')