if("sheet1".equals(sheetname[i])){
Sheet sheet = workbook.createSheet(sheetname[i]);
sheet.setDefaultColumnWidth(15);
Row header = sheet.createRow(0);
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
Cell cell = header.createCell(0);
cell.setCellStyle(style);
cell.setCellValue("a");
}else if("sheet2".equals(sheetname[i])){
Sheet sheet = workbook.createSheet(sheetname[i]);
sheet.setDefaultColumnWidth(15);
Row header = sheet.createRow(0);
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
Cell cell = header.createCell(0);
cell.setCellStyle(style);
cell.setCellValue("aa");
}
特意给你测试了一下,这样写是没问题的,仅供参考