프로그래밍/기타

PHP, ASP를 엑셀파일로 전환하는 방법

2009. 3. 6. 01:45

웹페이지를 오피스 문서로 변환하는 소스코드는 다음과 같다.

 

 

 

1. PHP에서 사용할 경우

 

(1) 엑셀 파일로 변환할 때

<?  
header("Content-Type: application/vnd.ms-excel");  
?>


(2) 워드 파일로 변환할 때

<?  
header("Content-Type: application/msword");  
?>  

(3) 파워포인트 파일로 변환할 때

<?  
header("Content-Type: application/vnd.ms-powerpoint");  
?>  


 

2. ASP에서 사용할 경우

 

(1) 엑셀 파일로 변환할 때

<%  
Response.Buffer = TRUE  
Response.ContentType = "application/vnd.ms-excel"  
%>

(2) 워드 파일로 변환할 때
<%  
Response.Buffer = TRUE  
Response.ContentType = "application/msword"  
%>

 

(3) 파워포인트 파일로 변환할 때

<%  
Response.Buffer = TRUE  
Response.ContentType = "application/vnd.ms-powerpoint"  
%>

 

* 참고로 ASP에서 밑에 부분을 추가하면 바로 엑셀 프로그램에서 띄울 수 있게 된다

 

Response.AddHeader "Content-Disposition", "attachment;filename=FILENAME.xls"

 

 

 

위와 같은 소스코드를 PHP 또는 ASP 상단에 추가시켜주면 된다.

 

 

참고출처 : http://cafe.naver.com/q69/8386