我有一张地图,其内容应垂直呈现,而不是水平布局
Multimap<Integer, String> map = getMap();
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet = workbook.createSheet("companyInsurence");
XSSFRow row;
Set < Integer > keyid = map.keySet();
row = spreadsheet.createRow(0);
Cell InitialCell=row.createCell(0);
InitialCell.setCellValue("id");
Cell InitialCell1=row.createCell(1);
InitialCell1.setCellValue("date");
int rowid = 1;
for (Integer key : keyid){
row = spreadsheet.createRow(rowid++);
Cell cell0 = row.createCell(0);
cell0.setCellValue(key);
Collection<String> objectList = map.get(key);
int cellid = 1;
for (Object obj : objectList)
{
Cell cell = row.createCell(cellid++);
if(obj!=null){
cell.setCellValue(obj.toString());
}else{
cell.setCellValue(" ");
}
}
}
amd地图内容是 {12 = [1,2,3,4,5,6,6,6],[13] = [123456,988,65,HGG,91]}
因此excel表将数据显示为
id date
12 1 2 4 ....
13 123456 988 65
所以不是这样,我想要这样的东西
id date
12 1
12 2
12 3
12 4
12 5
12 6
:
:
:
:
13 65
答案 0 :(得分:0)
您需要为每个值创建一行,而不是每个键。
int rowid = 1;
for (Integer key : keyid){
Collection<String> objectList = map.get(key);
for (Object obj : objectList)
{
row = spreadsheet.createRow(rowid++);
Cell cell0 = row.createCell(0);
cell0.setCellValue(key);
Cell cell = row.createCell(1);
if(obj!=null){
cell.setCellValue(obj.toString());
}else{
cell.setCellValue(" ");
}
}
}
注意:我还没有这样做。