首页 新闻 会员 周边 捐助

excel导出展示问题

0
悬赏园豆:100 [待解决问题]

就是想把snscode相同的值的年份按照12个月展示到一行上。

查询出snsInfoList集合值:

View Code

 代码:

public List<List<String>> userJoint(List<QuerySnsInfo> snsInfoList) throws NumberFormatException, ParseException {
            List<List<String>> list = new ArrayList<List<String>>();
            Map<String,List<QuerySnsInfo>> map = new HashMap<String,List<QuerySnsInfo>>();
            for(QuerySnsInfo obj :snsInfoList){
                if(map.containsKey(obj.getSnscode()+obj.getTimes().substring(0, 4))){
                    map.get(obj.getSnscode()+obj.getTimes().substring(0, 4)).add(obj);
                }else{
                    List<QuerySnsInfo> list2 = new ArrayList<QuerySnsInfo>();
                    list2.add(obj);
                    map.put(obj.getSnscode()+obj.getTimes().substring(0, 4),list2);
                }
                
            }
            Set<String> set = map.keySet();
            Iterator<String> it = set.iterator();
            while(it.hasNext()){
                String key = it.next();
                List<QuerySnsInfo> list3 = map.get(key);
                String time="";
                for(QuerySnsInfo info :list3){
                    time = time+info.getTimes();
                }
                if(key.contains("2017")){
                    if(!time.contains("2017-01")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-01");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-02")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-02");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-03")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-03");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-04")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-04");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-05")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-05");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-06")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-06");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-07")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-07");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-08")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-08");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-09")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-09");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-10")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-10");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-11")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-11");
                        list3.add(aa);
                    }
                    if(!time.contains("2017-12")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2017-12");
                        list3.add(aa);
                        
                    }
                }
                
                if(key.contains("2018")){
                    if(!time.contains("2018-01")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-01");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-02")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-02");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-03")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-03");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-04")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-04");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-05")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-05");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-06")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-06");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-07")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-07");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-08")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-08");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-09")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-09");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-10")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-10");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-11")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-11");
                        list3.add(aa);
                    }
                    if(!time.contains("2018-12")){
                        QuerySnsInfo  aa = new QuerySnsInfo();
                        aa.setNum(0l);
                        aa.setSnscode(key.substring(0, key.length()-4));
                        aa.setTimes("2018-12");
                        list3.add(aa);
                    }
                }
                Collections.sort(list3, new Comparator<QuerySnsInfo>(){
                    @Override
                    public int compare(QuerySnsInfo o1, QuerySnsInfo o2) {
                        if(o1.getTimes()==null || o2.getTimes()==null){
                          return 0;
                        }
                        return Integer.parseInt(o1.getTimes().substring(5, 7).replace("0", ""))-Integer.parseInt(o2.getTimes().substring(5, 7).replace("0", ""));
                    }

                });
            }
            Set<String> set2 = map.keySet();
            Iterator<String> it2 = set2.iterator();
            while(it2.hasNext()){
                String key = it2.next();
                List<QuerySnsInfo> list3 = map.get(key);
                List<String> li = new ArrayList<String>();
                li.add(list3.get(0).getSnscode());
                li.add(list3.get(0).getTimes().substring(0, 4));
                for(QuerySnsInfo info :list3){
                    li.add(info.getNum().toString());
                }
                list.add(li);
            }
            return list;
        }

自己通过代码导出的样式如下:

 

 

 

 

以上结果显示是错误是的,月份数据对应不上。正确应该是第一条的88888值展示到7月份中,123应该展示到8月份中去,后面的每一条都展示错了。但是上图展示的确错位了。

希望大神能够帮看下!谢谢!

~菜鸟鸡~的主页 ~菜鸟鸡~ | 初学一级 | 园豆:48
提问于:2018-08-24 19:16
< >
分享
所有回答(2)
0

第一次改变结构  {snscode:"aaa",rows:[]}

第二次改变结构 处理 row 变成一行

Постой! | 园豆:1084 (小虾三级) | 2018-08-25 17:52
0

谢谢大神自己解决了

~菜鸟鸡~ | 园豆:48 (初学一级) | 2018-08-28 08:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册