2

有很多 CSV 示例可以列出 Flutter 应用程序,我面临着 Flutter Web 和文件转换的问题。

某些 CSV 无法正常工作,我猜这是格式问题 这是用户上传文件时的转换功能

Future _openFileExplorer() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles(
        allowMultiple: false,
        withData: true,
        type: FileType.custom,
        allowedExtensions: ['csv']);
    if (result != null) {
      //decode bytes back to utf8
      final bytes = utf8.decode((result.files.first.bytes)!.toList());
      setState(() {
        //from the csv plugin
        employeeData = CsvToListConverter().convert(bytes);
      });
    }
  }

工作 CSV 文件转换

工作 CSV 文件转换,

不工作csv文件转换,结构不一样,这是一个大块

不工作csv文件转换,结构不一样,这是一个大块,

如果你想尝试,我做了一个完整的项目回购,在自述文件中添加了一些照片,

https://github.com/valentincx/csv_to_list_for_web

4

1 回答 1

1

你应该添加eol: "\r\n",fieldDelimiter: ","CsvToListConverter(). 你的代码将是这样的:

employeeData = CsvToListConverter(eol: "\r\n",fieldDelimiter: ",").convert(bytes);
于 2022-02-03T08:58:12.467 回答