简体   繁体   English

如何在颤振中获取列表中所需的数据?

[英]How can I get the desired data in the list in flutter?

I have a list that I read from excel.我有一个从 excel 中读取的列表。 Here I want to get data with index number 1 and 3 of the lists.在这里,我想获取列表中索引号为 1 和 3 的数据。 For example, I just want to get "ad" and "name" values.例如,我只想获得“ad”和“name”值。

example: [tr, ad, en, name]= [ad, name]示例:[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]) debug=I/flutter (25765): ([Dil1, Kelime1, Dil2, Kelme2], [tr, ad, en, name], [tr, öğrenci, en, student], [en,教学, tr, öğren])

row type is Iterable<List>行类型是 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:您需要先解析为 List:

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让列表框在列表中的所需起点初始化? - How to get a list box to initialize at a desired starting point in the list? 如何更改我的数据透视表以便以所需方式显示数据? - How can I alter my PivotTable so that it displays the data in the desired way? 如何将数据框转换为所需的结构和形式? - How do I transform a data frame to the desired structure and form? 如何将 pivot 样式数据转换为列表数据? - How can I convert pivot style data into list data? 对列表进行排序时,如何使按钮移动? - How can I get buttons to move when I sort a list? 来自 Excel 中类似列的日期在 R 中以不同方式导入。如何获得所需的日期格式:%d-%m-%Y? - Dates from similar columns in Excel are imported differently in R. How can I get the desired date format: %d-%m-%Y? 如何从MsExcel的下拉列表中获取值? - How can I get the values from Dropdown list in MsExcel? 如何获取使用特定共享工作簿的用户列表? - How can I get list of users using specific shared workbook? 如何从Excel获取列表名称? - How can I get list name from Excel? 如何获取当前excel表中其他用户的列表? - How can I get a list of other users in the current excel sheet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM