ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • PHP 데이터 EXCEL로 다운받기
    카테고리 없음 2010. 3. 14. 22:47
    반응형

    잘 알려진 팁이지만 다음과 같은 header를 날린 후 데이터를 table로 만들면 excel로 데이터를 날릴 수 있다.

    header("Content-type: application/vnd.ms-excel; charset=UTF-8");
    header("Content-Disposition: attachment; filename=registry2.xls");
    header("Content-Description: PHP5 Generated Data");
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");

    그런데 문제는 한글이 깨진다는 거... 버그로 추정되지만 header로 날린 charset는 먹지 않는다. 그래서 meta tag를 써서 다시 charset를 넣어 줘야 한다.

    <meta content="application/vnd.ms-excel; charset=UTF-8" name="Content-type">
    <meta content="Excel.Sheet" name="ProgId">
    <meta content="PHP5" name="Generator">

    이런 식으로 쓰면 된다.

Designed by Tistory.