안규 공부방

ACTIVE SERVER PAGE > UTF-8 에서 excel 파일로 저장하기

등록일 : 2021-04-29 14:32 조회수 : 67,105

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>
※ 혹시 도움이 되셨다면 댓글에 한마디 남겨주세요!
작성자   비밀번호
자동글 방지     (자동글 방지 기능입니다.)
내용   댓글달기 
이메일 문의 : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.