레이블이 excel인 게시물을 표시합니다. 모든 게시물 표시
레이블이 excel인 게시물을 표시합니다. 모든 게시물 표시

2013년 6월 25일 화요일

html의 데이타를 excle로 저장하기 간단소스 jsp (html table excel export simple jsp source)

//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>