首页 新闻 会员 周边 捐助

java excel导出表格问题

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

数据库查询的List数据结构为:

[ QuerySnsInfo (
id = NULL,
snscode = 110931243@qq.com,
times = NULL,
cdate = NULL,
uname = NULL,
num = NULL,
comments = NULL,
STATUS = NULL,
NAME = NULL,
type = NULL,
CODE = NULL,
person = NULL,
phone = NULL,
bdphone = NULL,
province = NULL,
city = NULL,
sort = NULL,
stTime = NULL,
endTime = NULL,
nums = NULL,
dates = NULL,
years = 2017,
months = 11,12,(月份,这里使用,分割)
numss = 11,12(月份对应的num值)
),
QuerySnsInfo (
id = NULL,
snscode = zhanhongjiaoyu,
times = NULL,
cdate = NULL,
uname = NULL,
num = NULL,
comments = NULL,
STATUS = NULL,
NAME = NULL,
type = NULL,
CODE = NULL,
person = NULL,
phone = NULL,
bdphone = NULL,
province = NULL,
city = NULL,
sort = NULL,
stTime = NULL,
endTime = NULL,
nums = NULL,
dates = NULL,
years = 2017,
months = 12,11,
numss = 12,11
) ]


希望导出excel合并一行:实现样式如下:

号码 年份 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月
zhanhongjiaoyu 2017 0 0 0 0 0 0 0 0 0 0 11 12
110931243@qq.com 2017 0 0 0 0 0 0 0 0 0 0 11 12

可是自己做出来的结果样式为:

号码 年份 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月                        
zhanhongjiaoyu 2017 0 0 0 0 0 0 0 0 0 0 0 12 0 0 0 0 0 0 0 0 0 0 11 0
110931243@qq.com 2017 0 0 0 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0 0 12

代码如下:

public List<List<String>> userJoint(List<QuerySnsInfo> snsInfoList) throws NumberFormatException, ParseException {
List<List<String>> list = new ArrayList<List<String>>();
//List<String> info = new ArrayList<String>();


Map<String, List<QuerySnsInfo>> map = snsInfoList.stream().collect(Collectors.groupingBy(QuerySnsInfo::getSnscode));

for (Entry<String, List<QuerySnsInfo>> entry : map.entrySet()) {
List<String> info = new ArrayList<String>();
info.add(entry.getKey());
List<QuerySnsInfo> infoList = entry.getValue();
for(QuerySnsInfo sns : infoList){
info.add(sns.getYears());
String month[] = sns.getMonths().split(",");
String[] num = sns.getNumss().split(",");
for (int k = 0; k <month.length; k++) {

for(int j=1;j<=12;j++){
if(month[k].replace("0", "").equals(String.valueOf(j))){
info.add(num[k]);
}else{
sns.setNumss("0");
info.add(sns.getNumss());
}
}
}
}
list.add(info);
}
return list;
}

求大神指导。谢谢!

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

不知这篇博文(java导出Excel文件)是对你有帮助

dudu | 园豆:30778 (高人七级) | 2018-08-24 14:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册