我想在完整的data.put上創建循環。我怎樣才能做到這一點?for循環到excel
如何創建循環?
data.put("01",new Object[] { a[0],a[1],a[2],a[3],a[4], ... a[240],a[241],a[242],a[243] });
data.put("02",new Object[] { a[244],a[245],a[246],a[247],a[248], ... a[484],a[485],a[486],a[487] });
data.put("03",new Object[] { a[488],a[489],a[490],a[491],a[492], ... a[728],a[729],a[730],a[731] });
行= 244 柱= 3
public void ExcelSave() throws IOException {
workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Employee Data");
Map<String, Object[]> data = new TreeMap<String, Object[]>();
String[] a = DataFrom.split("-");
data.put("01",new Object[] { a[0],a[1],a[2],a[3],a[4], ... a[240],a[241],a[242],a[243] });
data.put("02",new Object[] { a[244],a[245],a[246],a[247],a[248], ... a[484],a[485],a[486],a[487] });
data.put("03",new Object[] { a[488],a[489],a[490],a[491],a[492], ... a[728],a[729],a[730],a[731] });
/////////////////////////// ////////////////////////////////////////////////// //////////////////////////////
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 {
FileOutputStream out = new FileOutputStream(new File("ExcelSaves.xlsx"));
workbook.write(out);
out.close();
System.out.println("--> Excel Save...");
} catch (Exception e) {
e.printStackTrace();
}
}
你的意思_如何創建loops_?你可以參加[遊覽]並首先查看[問] – Prisoner