Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HashMap获取所有值,但只返回最后一个条目_Java_Android_Excel_Apache Poi - Fatal编程技术网

Java HashMap获取所有值,但只返回最后一个条目

Java HashMap获取所有值,但只返回最后一个条目,java,android,excel,apache-poi,Java,Android,Excel,Apache Poi,我正在从hashmap获取数据。我想使用POI将其添加到excel文件中。但问题是程序只添加excel中的最后一项。但在调试时,它会给出所有值。 这是我的密码 for (int j = 0; j < proList.size(); j++) { HashMap hashMap = proList.get(j); Iterator<Object> iterator = hashMap.entrySet().iterator();

我正在从hashmap获取数据。我想使用POI将其添加到excel文件中。但问题是程序只添加excel中的最后一项。但在调试时,它会给出所有值。 这是我的密码

 for (int j = 0; j < proList.size(); j++) {
        HashMap hashMap = proList.get(j);
        Iterator<Object> iterator = hashMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> entry = (Map.Entry<String, String>) iterator.next();
            rows=sheet1.createRow(j+1);
            cc=rows.createCell(j);
            cc.setCellValue(entry.getValue());




        }
    }

看起来您应该在外部循环中创建行。 您可能需要为这些列创建一个单独的索引

for (int j = 0; j < proList.size(); j++) {
    HashMap hashMap = proList.get(j);
    rows=sheet1.createRow(j+1);
    Iterator<Map.Entry<String, String>> iterator = hashMap.entrySet().iterator();
    int col = 0;
    while (iterator.hasNext()) {
        Map.Entry<String, String> entry = iterator.next();       
        cc=rows.createCell(col++);
        cc.setCellValue(entry.getValue());
    }
}

您正在使用j作为索引,它在while循环中从不递增。因此它总是只创建一行


注意:您使用的索引“j”来自while循环外部的for循环声明。其限制将仅为prolist.size!我认为您应该在while循环中使用单独的索引。

返回是什么意思?你确定它正在保存所有的值吗?谢谢你。。这正是我想要的