Java/Spring

Excel 다운로드

innocent_k 2015. 5. 18. 16:17

pom.xml 


	org.apache.poi
	poi
	3.12-beta1


	net.sourceforge.jexcelapi
	jxl
	2.6.12


Use

HSSFWorkbook workbook = new HSSFWorkbook();

HSSFSheet sheet = workbook.createSheet("Java Books");
sheet.setDefaultColumnWidth(30);

// create style for header cells
CellStyle style = getHeadStyle(workbook);

HSSFRow header = sheet.createRow(0);

header.createCell(0).setCellValue("Book Title");
header.getCell(0).setCellStyle(style);

header.createCell(1).setCellValue("Author");
header.getCell(1).setCellStyle(style);

header.createCell(2).setCellValue("ISBN");
header.getCell(2).setCellStyle(style);

header.createCell(3).setCellValue("Published Date");
header.getCell(3).setCellStyle(style);

header.createCell(4).setCellValue("Price");
header.getCell(4).setCellStyle(style);
		
/*response.setContentType(getContentType()); // http로 내보낼때 
ServletOutputStream out = response.getOutputStream();*/
File file = new File("d:/excel.xls");		// file로 내보내기 
FileOutputStream out = new FileOutputStream(file);

workbook.write(out);
out.flush();