excel icon indicating copy to clipboard operation
excel copied to clipboard

Cannot delete sheets

Open horvathAdam285 opened this issue 1 year ago • 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

horvathAdam285 avatar Apr 18 '24 15:04 horvathAdam285

I am facing this issue while using the rename function. It tries to delete the old named sheet

bahadirarslan avatar Apr 27 '24 19:04 bahadirarslan

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

Another-Chris avatar May 30 '24 10:05 Another-Chris

Could anyone please confirm if that issue continues on 4.0.x?

luizgpa avatar Jul 11 '24 17:07 luizgpa

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 (*)

mikeloomisgg avatar Jul 25 '24 00:07 mikeloomisgg

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?

mikeloomisgg avatar Jul 25 '24 01:07 mikeloomisgg

I upgraded to v4.0.3 and this was fixed, even for Sheet1.

mikeloomisgg avatar Jul 25 '24 01:07 mikeloomisgg