●예제
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.util.*,
java.io.*,
java.util.List,
java.util.HashMap,
org.apache.poi.xssf.usermodel.XSSFCellStyle,
org.apache.poi.xssf.usermodel.XSSFFont,
org.apache.poi.xssf.usermodel.XSSFCell,
org.apache.poi.xssf.usermodel.XSSFRow,
org.apache.poi.xssf.usermodel.XSSFSheet,
org.apache.poi.xssf.usermodel.XSSFWorkbook,
org.apache.poi.xssf.usermodel.XSSFColor,
org.apache.poi.ss.util.CellRangeAddress,
org.apache.poi.ss.usermodel.Font,
org.apache.poi.ss.usermodel.IndexedColors,
com.kait.mms.common.util.*,
com.kait.ims.inven.inven.vo.InvenVo,
com.kait.ims.srch.vo.SrchVo" %>
<%
String sFileName = "tem.xlsx";
//String sFileName = "ItemList" + "(" + StrUtil.gfGetCurDateTime() + ")" + ".xls";
sFileName = new String ( sFileName.getBytes("KSC5601"), "8859_1");
out.clear();
out = pageContext.pushBody();
response.reset(); // 이 문장이 없으면 excel 등의 파일에서 한글이 깨지는 문제 발생.
String strClient = request.getHeader("User-Agent");
String fileName = sFileName;
if (strClient.indexOf("MSIE 5.5") > -1) {
//response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "filename=" + fileName + ";");
} else {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ";");
}
OutputStream fileOut = null;
//워크북 생성
XSSFWorkbook objWorkBook = new XSSFWorkbook();
//워크시트 생성
XSSFSheet objSheet = objWorkBook.createSheet();
//시트 이름
objWorkBook.setSheetName(0 , "시트명" );
//행생성
XSSFRow objRow = objSheet.createRow((short)0);
//셀 생성
XSSFCell objCell = null;
//------------------------
objRow = objSheet.createRow((short)0);
objCell = objRow.createCell((short)0);
objCell.setCellValue("aa");
objCell = objRow.createCell((short)1);
objCell.setCellValue("bb");
objCell = objRow.createCell((short)2);
objCell.setCellValue("cc");
objCell = objRow.createCell((short)3);
objCell.setCellValue("dd");
objCell = objRow.createCell((short)4);
objCell.setCellValue("ee");
objCell = objRow.createCell((short)5);
objCell.setCellValue("ff");
objCell = objRow.createCell((short)6);
objCell.setCellValue("gg");
objCell = objRow.createCell((short)7);
objCell.setCellValue("hh");
//----------------------------------------------------------------------------------------
//길이 설정
objSheet.setColumnWidth((short)0,(short)3000);
objSheet.setColumnWidth((short)1,(short)3000);
objSheet.setColumnWidth((short)2,(short)3000);
objSheet.setColumnWidth((short)3,(short)3000);
objSheet.setColumnWidth((short)4,(short)3000);
objSheet.setColumnWidth((short)5,(short)8000);
objSheet.setColumnWidth((short)6,(short)3000);
objSheet.setColumnWidth((short)7,(short)5000);
//--------------------------------------------------------------------------------------
fileOut = response.getOutputStream();
objWorkBook.write(fileOut);
fileOut.close();
%>
'프로그래밍 > JSP' 카테고리의 다른 글
웹 호스팅 장시간 접속 안할때 mysql 500에러 (0) | 2015.06.17 |
---|---|
poi error java.lang.OutOfMemoryError: GC overhead limit exceeded (0) | 2013.12.04 |
jsp poi 엑셀 다운 예제 (0) | 2013.11.26 |
jsp 개발환경 세팅 이클립스 톰켓 플러그인 (0) | 2013.10.28 |
jsp poi 엑셀 다운받기 (0) | 2013.09.04 |
댓글