웹마스터 팁

http://www.koreaphp.co.kr/tip_board/board_read.php?page=1&block=1&no=66&cate=43&parent=61웹페이지 상의 문서를 엑셀이나, 파워포인트, 위드 문서로 변환해 줘야 되는 경우 아래와 같은 방법을 쓰면 상당히 쉽게 해결이 되지요.

만약에 엑셀 파일로 변환을 하고 싶으시면
<?
header("Content-Type: application/vnd.ms-excel");
?>
저 부분을 <HTML> 태그 앞에 넣으면 끝나지요.
저 페이지가 호출이 되면 오피스가 깔려있는 사용자들은 저장할것인지 그냥 열것인지를 물어보구여, 안깔려 있는 사용자들은 파일을 다운받을수 있게 되지요.

그럼 워드 파일은
<?
header("Content-Type: application/msword");
?>

파워포인트 역시 같은 방법으로
<?
header("Content-Type: application/vnd.ms-powerpoint");
?>

그럼 마지막으로 ASP에서는
<%
Response.Buffer = TRUE
Response.ContentType = "application/vnd.ms-excel"
%>

나머지는 응용이 가능하시겠지여?
알고보면 상당히 쉬운방법인데 저 방법을 몰라서 고민하시는 분들이 꽤 되시더라구요.

그럼 도움이 되시길. ^^

다음은 header 내용을 변경해서 excel로 바꾸어 주는 구문입니다.

* excel.php

<?php
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=test.xls");
header("Content-Description: PHP4 Generated Data");
?>
<html>
<body>
<table>
<tr>
<td>테스트1</td>
<td>테스트1</td>
<td>테스트1</td>
<td>테스트1</td>
</tr>
<tr>
<td>테스트2</td>
<td>테스트2</td>
<td>테스트2</td>
<td>테스트2</td>
</tr>
</table>
</body>
</html>