未处理的异常:文件系统异常:无法打开文件,路径 = “/assets/mood.xlsx”(操作系统错误:没有此类文件或目录,errno = 2)

Unhandled Exception: FileSystemException: Cannot open file, path = '/assets/mood.xlsx' (OS Error: No such file or directory, errno = 2)

提问人:Kaouther 提问时间:7/12/2023 更新时间:7/12/2023 访问量:14

问:

在尝试使用 flutter 保存我在 excel 文件中所做的更改时,出现了此错误,并且未保存更改。

代码如下

_updateExcel() async{
    ByteData data = await rootBundle.load('assets/mood.xlsx');
    var bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
    var excel = Excel.decodeBytes(bytes);
    Sheet sheetObjectAlger = excel['Alger'];
    Sheet sheetObjectOran = excel['Oran'];
    Sheet sheetObjectConst = excel['Alger'];
    Sheet sheetObjectAll = excel['All'];
    var cell = sheetObjectAlger.cell(CellIndex.indexByString('B2'));
    cell.value = cell.value +1;
    print(cell.value);    //to see if the value is picked up 
    excel.updateCell('Alger', CellIndex.indexByString('B2'),cell.value);
    var excelOutput = excel.encode();
    File('/assets/mood.xlsx').writeAsBytesSync(excelOutput!);
  }

我试图在Excel中保存单元格值的更改。 我正在使用这个 excel 包文本

这是反错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: FileSystemException: Cannot open file, path = '/assets/mood.xlsx' (OS Error: No such file or directory, errno = 2)
E/flutter ( 6555): #0      _File.throwIfError (dart:io/file_impl.dart:635:7)
E/flutter ( 6555): #1      _File.openSync (dart:io/file_impl.dart:479:5)
E/flutter ( 6555): #2      _File.writeAsBytesSync (dart:io/file_impl.dart:604:31)
E/flutter ( 6555): #3      _My_MoodState._updateExcel (package:mood_meter/pages/my_Mood.dart:57:31)
E/flutter ( 6555): <asynchronous suspension>
Excel Flutter 错误处理 Saving-Data UpdateException

评论


答: 暂无答案