Cannot delete sheets
Opened this issue · 6 comments
Calling excel.delete(sheetName) can throw this error:
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unsupported operation: Cannot remove from an unmodifiable list
E/flutter (20043): #0 UnmodifiableListMixin.removeWhere (dart:_internal/list.dart:139:5)
The problem seems to be trying to delete from _archive.files, which is an UnmodifiableListView
I am facing this issue while using the rename
function.
It tries to delete the old named sheet
Apparently they are trying to call removeWhere()
on _archive.files
, which is an UnmodifiableListView
I am not sure why they make _archive.files
unmodifiable but also call removeWhere on it. Dart documentation clearly says it is not supported. removeWhere method
- Dart: 2.19.6
- excel: 3.0.0
Could anyone please confirm if that issue continues on 4.0.x?
I'm able to rename sheets that I create.
This is on windows 11, lib version v4.0.2
Excel excel = Excel.createExcel();
var sheet = excel['OLD_NAME'];
excel.rename("OLD_NAME", "NEW_NAME");
I cannot delete "Sheet1", however. It gives me this error:
Unhandled exception:
Unsupported operation: Cannot remove from an unmodifiable list
#0 UnmodifiableListMixin.removeWhere (dart:_internal/list.dart:139:5)
#1 Excel.delete (package:excel/src/excel.dart:279:22)
#2 main (*)
If I remove the block of code that is throwing an exception then I can delete Sheet1:
// _archive.files.removeWhere((file) {
// return file.name.toLowerCase() == _xmlSheetId[sheet]?.toLowerCase();
// });
What is the purpose of deleting from the unmodifiable list?
I upgraded to v4.0.3 and this was fixed, even for Sheet1.