首页新闻找找看学习计划

java用POI写Excel按列数据

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

写第二行数据:
for (int i = 0; i < dictInfo.size(); i++) {
HSSFRow dataRow = sheet.createRow(i + 1);
dataRow.setHeight((short) (15 * 20));
JavaList l = (JavaList) dictInfo.getKeys();
String s = (String) l.get(i);
JavaList ll = (JavaList) dictInfo.get(s); //获取列数据
for (int j = 0; j < ll.size(); j++) {
Cell dataCell = dataRow.createCell(j);
HSSFFont dataFont = wb.createFont();
dataFont.setFontName("华文细黑");
dataFont.setFontHeightInPoints((short) 10);
dataFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
HSSFCellStyle dataStyle = wb.createCellStyle();
dataStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
dataStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
dataStyle.setFont(dataFont);
dataCell.setCellStyle(dataStyle);
dataCell.setCellValue(ll.get(j).toString());
}
}
dictInfo中数据:
{
"ordercode":["订单号0","订单号1"],
"tradeno":["交易号0","交易号1"],
"procode":["技术产品代码0","技术产品代码"],
"proname":["技术产品名称0","技术产品名称1"]
}

借你耳朵说爱你的主页 借你耳朵说爱你 | 初学一级 | 园豆:199
提问于:2019-09-19 16:36
< >
分享
所有回答(2)
1

listInfo和JavaList I 顺序反了吧,你这是逻辑错误吧,自己debug一下不就知道了

森离九 | 园豆:201 (菜鸟二级) | 2019-09-19 16:46

刚刚上传错了代码,l是需要从dictInfo中取数据

支持(0) 反对(0) 借你耳朵说爱你 | 园豆:199 (初学一级) | 2019-09-19 17:08
0

用二维数组解决问题:
int dictsize = dictInfo.size();
int listsize = ((JavaList) dictInfo.get(dictInfo.getKeys().get(0))).size();
//数据处理
String[][] parameter = new String[dictsize][listsize];
for (int i = 0; i < dictsize; i++) {
JavaList list = (JavaList) dictInfo.getKeys();
JavaList listInfo = (JavaList) dictInfo.get(list.get(i)); //获取列数据
for (int j = 0; j < listsize; j++) {
parameter[i][j] = listInfo.get(j).toString();
}
}
//写第二行……
for (int i = 0; i < listsize; i++) {
HSSFRow dataRow = sheet.createRow(i + 1);
dataRow.setHeight((short) (15 * 20));
for (int j = 0; j < dictsize; j++) {
Cell dataCell = dataRow.createCell(j);
HSSFFont dataFont = wb.createFont();
dataFont.setFontName("华文细黑");
dataFont.setFontHeightInPoints((short) 10);
dataFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
HSSFCellStyle dataStyle = wb.createCellStyle();
dataStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
dataStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
dataStyle.setFont(dataFont);
dataCell.setCellStyle(dataStyle);
dataCell.setCellValue(parameter[j][i]);
}
}

借你耳朵说爱你 | 园豆:199 (初学一级) | 2019-09-24 11:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册