Closed gonojuarez closed 7 months ago
@gonojuarez Can you add a test for this fix?
sorry I can avoid this suggestion, I will download the code and find the bug, because I see the problem is related to the try-catch exception at class save_file I find this code :
case DoubleCellValue():
final String v = switch (numberFormat) {
NumericNumFormat() => numberFormat.writeDouble(value),
_ => throw Exception(
'${numberFormat} does not work for ${value.runtimeType}'),
};
children = [
XmlElement(XmlName('v'), [], [XmlText(v)]),
];
case DateTimeCellValue():
final String v = switch (numberFormat) {
DateTimeNumFormat() => numberFormat.writeDateTime(value),
_ => throw Exception(
'${numberFormat} does not work for ${value.runtimeType}'),
};
children = [
XmlElement(XmlName('v'), [], [XmlText(v)]),
];
case DateCellValue():
final String v = switch (numberFormat) {
DateTimeNumFormat() => numberFormat.writeDate(value),
_ => throw Exception(
'${numberFormat} does not work for ${value.runtimeType}'),
};
children = [
XmlElement(XmlName('v'), [], [XmlText(v)]),
];
case TimeCellValue():
final String v = switch (numberFormat) {
TimeNumFormat() => numberFormat.writeTime(value),
_ => throw Exception(
'${numberFormat} does not work for ${value.runtimeType}'),
};
children = [
XmlElement(XmlName('v'), [], [XmlText(v)]),
];
case TextCellValue():
children = [
XmlElement(XmlName('v'), [], [
XmlText(_excel._sharedStrings.indexOf(sharedString!).toString())
]),
];
I am thinking that the numberFormat will be null and these throw the exception.
Okay, you can open a new PR if you manage to fix the issue.
I think this change solves the following error:
Error: Exception: null does not work for IntCellValue dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 294:3 throw packages/excel/src/save/save_file.dart 124:16
packages/excel/src/save/save_file.dart 124:13 [_createCell]
packages/excel/src/save/save_file.dart 997:16 [_updateCell]
packages/excel/src/save/save_file.dart 652:9 [_setRows]
packages/excel/src/save/save_file.dart 966:7
dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:7 forEach
packages/excel/src/save/save_file.dart 914:12 [_setSheetElements]
packages/excel/src/save/save_file.dart 544:5 [_save]
packages/excel/src/excel.dart 348:20