BLOG main image
전체 (276)
[Computer] (42)
[Programming] (62)
[DBMS] (26)
[Operating System] (21)
[Study English] (8)
[For money] (28)
[Interest] (89)
«   2009/11   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
77888 Visitors up to today!
Today 80 hit, Yesterday 46 hit
[폭주기관차, 2008/08/13 15:38, [Programming]/PHP]

웹프로그램인 PHP개발로 접어든지 벌써 6개월정도 되어간다.

일반 응용 프로그램을 만들던 시절에만 해도 아주 어렵게 생각했던 엑셀파일로
저장하는 게 PHP에서는 의외로 간단하게 할 수 있다는 것을 알았다.

간단하게 예를 들어서

a  |  b  |  sum
----------------
1  |  2  |  3
2  |  4  |  6
3  |  5  |  8

이런 테이블이 있다고 하면 이 것을 엑셀로 저장하는 PHP 코드는 아래와 같다.

<?
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename=test.xls" );
header( "Content-Description: PHP4 Generated Data" );

$a   = array("1","2","3");
$b   = array("2","4","5");
$sum = array("3","6","8");

echo "
    <table>
    <tr>
        <td>a</td>
        <td>b</td>
        <td>sum</td>
    </tr>
    "
;

for($i=0; $i<3; $i++) {
        echo "<tr><td>$a[$i]</td><td>$b[$i]</td><td>$sum[$i]</td></tr>";
}

echo "
    </table>
    "
;
?>

위의 코드를 test.php로 저장한 후 한번 실행해보라.
바로 xls파일로 만들준다. 그리고 저장할꺼냐고 물어본다.
열어보면 열린다.

오호 신기하다. 거럼 이제 mySQL같은 DB에 저장되어있는것도
엑셀로 바꿀 수 있겠죠??? ㅋㅋ

참, 참고로 엑셀로 저장될 파일명은 두번째 header지정하는 부분에 filename=요부분에서 설정해주면된다~

출처 : 네이버 지식iN crackerx님의 답변
Trackback Address :: http://kongmks.cafe24.com/trackback/296
Name
Password
Homepage
Secret
*1 ... *2 *3 *4 *5 *6 *7 *8 *9 *10 ... *276