출처:http://moonstoneit.blogspot.kr/2013/06/html-excle-jsp-html-table-excel-export.html
//Data.html-------------data what you want to make to Excel(엑셀로만들 데이타)
<script type="text/javascript">
function excel(){
document.frm.action = "excel.jsp";
document.frm.excel_data.value = document.getElementById("excel_body").outerHTML;
document.frm.submit();
}
<form name="frm" method="post">
<input type="hidden" name="excel_data" />
</form>
<table id="excel_body">
<caption>list</caption>
<thead>
<tr>
<th>userid</th>
<th>name</th>
<th>mail</th>
</tr>
</thead>
<tbody>
<c:forEach items="${list}" var="data" varStatus="status">
<tr>
<td>
<c:out value='${data.userid}' />
</td>
<td>
<c:out value='${data.username}' />
</td>
<td>
<c:out value='${data.email}' />
</td>
</c:forEach>
</tbody>
</table>
//excel.jsp---------------------use just C&P (그냥복사해서 쓰세요)
<%
request.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment; filename=\"excel.xls\"");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
out.print("<meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel; charset=utf-8\">");
%>
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<style type="text/css">
body {font-family:tahoma;font-size:12px}
table {padding:2px;border-spacing:0px;font-family:tahoma;font-size:12px;border-collapse:collapse}
td {text-align:center}
</style>
</head>
<body>
<% out.print(request.getParameter("excel_data")); %>
</body>
</html>
'JAVASCRIPT 자바스크립트' 카테고리의 다른 글
jquery excel 저장 (0) | 2014.12.24 |
---|---|
jquery 엑셀파일 저장할때 (0) | 2014.12.24 |
jqgride formatter (0) | 2014.12.22 |
jquery table 이나 사이즈 변경시.. (0) | 2014.11.28 |
자바 스프링 3.x (0) | 2014.11.21 |