반응형
[ASP] html을 excel 파일로 저장하기
html 화면에 출력되는 테이블을 엑셀파일로 저장하려는 경우에 아래와 같이 사용하시면 됩니다.
저장할 파일 명은 FileName 으로 변수 선언을 하되, 한글 깨짐을 근본적으로 방지하기 위하여
urlEncode 함수로 감싸서 넘겨주시면 됩니다.
<%@Language="VBScript" CODEPAGE="65001" %>
<%
Response.CharSet="utf-8"
Session.codepage="65001"
Response.codepage="65001"
Response.ContentType="text/html;charset=utf-8"
FileName = Server.urlEncode("한글파일깨짐방지")
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.CacheControl = "public"
Response.AddHeader "Content-disposition","attachment;filename=" & FileName & ".xls"
%>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
</head>
<body>
<table width="750" border="0" cellspacing="1" cellpadding="2" valign = "top" align = "center">
<tr>
<td colspan=6>제목</td>
</tr>
<tr height="30" align=center style="font-size:13px;background-color:#D9E5FF;border-top:1px solid #25314B;">
<td width='9%' height='30' align='center' valign='middle' ><b>일자</b></td>
<td width='41%' height='30' align='center' valign='middle' ><b>적요</b></td>
<td width='12%' height='30' align='center' valign='middle' ><b>수량</b></td>
<td width='13%' height='30' align='center' valign='middle' ><b>금액</b></td>
<td width='13%' height='30' align='center' valign='middle' ><b>잔액</b></td>
</tr>
<tr height='30'>
<td width='9%' align='center'>2019-08-28</td>
<td width='41%' align='left'>임시저장 테스트1</td>
<td width='12%' align='right'>3,000</td>
<td width='13%' align='right'>5,000</td>
<td width='13%' align='right'>15,000,000</td>
</tr>
<tr height='30'>
<td width='9%' align='center'>2019-08-28</td>
<td width='41%' align='left'>임시저장 테스트2</td>
<td width='12%' align='right'>500</td>
<td width='13%' align='right'>1,000</td>
<td width='13%' align='right'>500,000</td>
</tr>
<tr height='30'>
<td width='9%' align='center'>2019-08-28</td>
<td width='41%' align='left'>임시저장 테스트3</td>
<td width='12%' align='right'>6,000</td>
<td width='13%' align='right'>300</td>
<td width='13%' align='right'>1,800,000</td>
</tr>
</table>
</body>
</html>
** 최종 엑셀파일 결과 화면 **
반응형
'프로그램ing > ASP' 카테고리의 다른 글
[SiteGalaxyUpload] UTF-8 에서 한글 파일명 저장 (0) | 2019.08.27 |
---|---|
[ASP] Microsoft JET Database Engine 외부 테이블 형식이 잘못되었습니다. (0) | 2019.04.05 |
[ASP] 엑셀 업로드 코드 작성시 TIP! (0) | 2019.04.04 |
[ASP] 천원단위로 콤마(,) 찍기 (0) | 2019.03.29 |
댓글