简体   繁体   中英

How can I get the desired data in the list in flutter?

I have a list that I read from excel. Here I want to get data with index number 1 and 3 of the lists. For example, I just want to get "ad" and "name" values.

example: [tr, ad, en, name]= [ad, name]

debug=I/flutter (25765): ([Dil1, Kelime1, Dil2, Kelme2], [tr, ad, en, name], [tr, öğrenci, en, student], [en, teach, tr, öğren])

row type is Iterable<List>

Future readExcel() async {
        var excelfileDetails = new Word();
    
        var file = excelPath;
        var bytes = File(file).readAsBytesSync();
        var excel = Excel.decodeBytes(bytes);
        print('${excel}');
    
        print(excel.tables.keys); //sheet Name
        print(excel.tables[excel.tables.keys.first]!.maxCols);
        print(excel.tables[excel.tables.keys.first]!.maxRows);
        final row = excel.tables[excel.tables.keys.first]!.rows
            .map((e) => e.map((e) => e!.value).toList());
        print(row);

You need to parse to List before:

final row = excel.tables[excel.tables.keys.first]!.rows
        .map((e) => e.map((e) => e!.value).toList()).toList();

And then:

row.forEach((e){
          int index = row.indexOf(e);
          row[index].removeAt(0);
          row[index].removeAt(1);
        });

Output:

[Kelime1, Kelme2], [ad, name], [öğrenci, student], [teach, öğren]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM