代码如下,我想问一下怎么封装list

try {
File excelFile2 = new File("C:\Users\Administrator\Desktop\luyan/LTE逻辑站点查询_2015070815.xlsx"); // 创建文件对象

FileInputStream in = new FileInputStream(excelFile2); // 文件流

ExcelUtil.checkExcelVaild(excelFile2);
Workbook workbook=ExcelUtil.getWorkbok(in, excelFile2);//读取excel文件获取Workbook
workbook.getNumberOfSheets();
//System.out.println("Sheet的数量 ="+sheetCount);
Sheet sheet = workbook.getSheetAt(0);// 遍历第一个Sheet
System.out.println("数据量2"+sheet.getLastRowNum());
Row row=sheet.getRow(0);

        System.out.println(row.getCell(0)+","+row.getCell(1)+","+row.getCell(2)+","
        +row.getCell(3)+","+row.getCell(14)+","+row.getCell(15)+","+row.getCell(21)+","+row.getCell(25));
        for(int i=1;i<1000;++i){
            Row trow2=sheet.getRow(i);
            Cell name=trow2.getCell(0);
               Cell city=trow2.getCell(1);
               Cell netWork_type =trow2.getCell(2);
               Cell Site_type =trow2.getCell(3);
               Cell longitude=trow2.getCell(14);
               Cell latitude=trow2.getCell(15);
               Cell manufacturers =trow2.getCell(21);
               Cell Station_name=trow2.getCell(25);
               list.add(Cell);
            System.out.println(trow2.getCell(0)+","+trow2.getCell(1)+","+trow2.getCell(2)+","
                    +trow2.getCell(3)+","+trow2.getCell(14)+","+trow2.getCell(15)+","+trow2.getCell(21)+","+trow2.getCell(25));

        }
       System.out.println(list+"222222222222"); 
    } catch (Exception e) {
        System.out.println("出错"+e.toString());
    }

1个回答

    List<Map> list = new ArrayList<Map>();

    for (int i = 1; i < 1000; ++i) {
        Map map = new HashMap();
        Row trow2 = sheet.getRow(i);
        map.put("name", trow2.getCell(0));
        map.put("city", trow2.getCell(1));
        map.put("netWork_type", trow2.getCell(2));
        map.put("Site_type", trow2.getCell(3));
        map.put("longitude", trow2.getCell(14));
        map.put("latitude", trow2.getCell(15));
        map.put("manufacturers", trow2.getCell(21));
        map.put("Station_name", trow2.getCell(25));

        list.add(map);
        System.out.println(trow2.getCell(0) + "," + trow2.getCell(1) + "," + trow2.getCell(2) + ","
                + trow2.getCell(3) + "," + trow2.getCell(14) + "," + trow2.getCell(15) + "," + trow2.getCell(21)
                + "," + trow2.getCell(25));

    }
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐