List<String> list = new ArrayList<String>();
list.add("test1~test2");
try {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
for (int index = 0; index < list.size(); index++) {
HSSFRow row = sheet.createRow((short) index);
String[] temp = ((String) list.get(index)).split("~");
HSSFRichTextString rtString = null;
HSSFCell cell = null;
if (temp.length > 0) {
cell = row.createCell((short) 0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
rtString = new HSSFRichTextString(temp[0]);
cell.setCellValue(rtString);
}
if (temp.length > 1) {
cell = row.createCell((short) 1);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
rtString = new HSSFRichTextString(temp[1]);
cell.setCellValue(rtString);
}
}
OutputStream os = response.getOutputStream();
response.setBufferSize(1000000);
workbook.write(os);
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("Export", "UTF-8") + ".xls");
return null;
}
list.add("test1~test2");
try {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
for (int index = 0; index < list.size(); index++) {
HSSFRow row = sheet.createRow((short) index);
String[] temp = ((String) list.get(index)).split("~");
HSSFRichTextString rtString = null;
HSSFCell cell = null;
if (temp.length > 0) {
cell = row.createCell((short) 0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
rtString = new HSSFRichTextString(temp[0]);
cell.setCellValue(rtString);
}
if (temp.length > 1) {
cell = row.createCell((short) 1);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
rtString = new HSSFRichTextString(temp[1]);
cell.setCellValue(rtString);
}
}
OutputStream os = response.getOutputStream();
response.setBufferSize(1000000);
workbook.write(os);
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("Export", "UTF-8") + ".xls");
return null;
}