単一のキーと複数の値がMap
あります。それらのデータを Excel シートに書き込もうとしています。
Map<String, Object[]> data=new TreeMap<String, Object[]>();
このマップでは、いくつかの値を入れています。
ContentRoleType role=ContentRoleType.toContentRoleType("PRIMARY");
QueryResult contentQuery=ContentHelper.service.getContentsByRole(cadDoc, role);
System.out.println("Content length of "+cadDoc.getName()+" is "+contentQuery.size());
ContentLength=contentQuery.size();
data.put(CadName, new Object[]{Iteration,ContentLength});
次に、このマップを繰り返し処理し、それらの要素をセルに書き込みます。
Set<String> keyset=data.keySet();
int rowNum=0;
for(String key:keyset){
Row row=sheet.createRow(rowNum++);
Object[] objArr=data.get(key);
int cellNum=0;
for(Object obj:objArr){
Cell cell=row.createCell(cellNum++);
if(obj instanceof String)
cell.setCellValue((String)obj);
else if(obj instanceof Integer)
cell.setCellValue((Integer)obj);
}
}
try
{
//Write the workbook in file system
FileOutputStream out = new FileOutputStream(new File("D:\\testExcel.xlsx"));
workbook.write(out);
out.close();
System.out.println("testExcel.xlsx written successfully on disk.");
}
catch (Exception e)
{
e.printStackTrace();
}
ここでの問題は、Excel シートにあり、値である 2 つの列しか表示できません。Excel シート内にキーを印刷できません。キーを最初の列として印刷し、2 つと 3 つが値です。追加方法このループ内のキー?
全てに感謝