●예제
<%@ 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 > Excel 다운관련' 카테고리의 다른 글
jsp poi 폰트, 스타일 적용 (0) | 2015.11.12 |
---|---|
[JSP]엑셀 excel 다운로드 파일 만들기 (한글깨짐, 숫자 포함) (0) | 2015.03.09 |
[JSP] jsp 페이지를 엑셀|워드|한글로 다운로드/실행. (0) | 2015.03.09 |
HTML을 지원하는 Excel과 Word (0) | 2015.03.09 |
Java Servlet & JSP API 개발/코딩 (0) | 2015.03.09 |
JSP 기본(내장) 객체 - response (0) | 2015.03.09 |
Content-disposition 속성 (0) | 2015.03.09 |
html excel 추출 하기.& Jquery excel 추출 하기 (0) | 2015.03.09 |