๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Lect & Tip/PHP & WordPress

- php ์—‘์…€ ๋‹ค์šด๋กœ๋“œ ํ•œ๊ธ€ ๊นจ์ง ๋ฌธ์ œ ํ•ด๊ฒฐ

by ๋‚ฏ์„ ๊ณต๊ฐ„2019 2020. 9. 11.

๋ชฉ์ฐจ

    php๋กœ ์ œ์ž‘๋œ ์›น์‚ฌ์ดํŠธ์—์„œ ์—‘์…€ ๋‹ค์šด๋กœ๋“œ๋ฅผ ๋ฐ›๋Š”๋ฐ ํ•œ๊ธ€๋กœ ๋œ ์—‘์…€ ํŒŒ์ผ๋ช…์ด ๊นจ์ง€๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋‹ค.

    ๋ฌธ์„œ ์ œ๋ชฉ์ด ์—‘์…€ ๋‹ค์šด๋กœ๋“œ์ด๋‹ค๋ณด๋‹ˆ, ms ์—‘์…€ 2010 ๋‹ค์šด ๊ฐ™์€ ๊ฒƒ์„ ๊ธฐ๋Œ€ํ•˜๊ณ  ๋“ค์–ด์˜จ ๋ถ„๋“ค์ด ๋งŽ์€ ๊ฒƒ ๊ฐ™๋‹ค.
    ๊ทธ๋Ÿฐ ๋ถ„๋“ค์€ ์ด ๊ณณ์„ ์ฐธ์กฐ! 
     

    ์—‘์…€ 2010 ๋ฌด๋ฃŒ ๋‹ค์šด

    ์—‘์…€ 2010 ๋ฌด๋ฃŒ ๋‹ค์šด ํŒŒ์›Œํฌ์ธํŠธ 2010 ๋ฌด๋ฃŒ์„ค์น˜ ๋งˆ์ดํฌ๋กœ์†Œํ”„ํŠธ ์—‘์…€ 2010 ๋ฌด๋ฃŒ ๋‹ค์šด ๋กœ๋“œ ์„ค์น˜

    blog1.ezip2020.com

    ์˜ˆ์ „์—๋Š” ์ž˜ ๋˜๋‹ค๊ฐ€ ๊ฐ‘์ž๊ธฐ ์•ˆ๋œ๋‹ค๋Š” ๋ณด๊ณ ๊ฐ€ ์ƒ๊ธฐ๋Š”๋ฐ, ๊ทธ๋Ÿด๋ฆฌ๋Š” ์—†๋‹ค. 

    ์ฒ˜์Œ๋ถ€ํ„ฐ ์•ˆ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

    ํฌ๋กฌ ๋ธŒ๋ผ์šฐ์ €์—์„œ๋Š” ํ•œ๊ธ€ ํŒŒ์ผ๋ช…์œผ๋กœ ์—‘์…€ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ๊ฐ€ ๊ฐ€๋Šฅํ•˜์ง€๋งŒ IE์—์„œ๋Š” ํ•œ๊ธ€ ํŒŒ์ผ๋ช…์˜ ํ•œ๊ธ€์ด ๊นจ์ง€๊ณ  ์ด์ƒํ•œ ๋ฌธ์ž๋กœ ๋งŒ๋“ค์–ด์„œ ์—‘์…€ ํŒŒ์ผ๋ช…๊นŒ์ง€ ์ธ์‹์ด ์•ˆ๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๋‹ค.

    ๋ณดํ†ต php ์—‘์…€ ๋‹ค์šด๋กœ๋“œ ์†Œ์Šค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌ์„ฑ๋  ๋•Œ๊ฐ€ ๋งŽ๋‹ค.

    ExcelHeader("ํ•œ๊ธ€๋ช….xls");   
    
    function ExcelHeader($sFileName) {
    header("Content-type: application/vnd.ms-excel");
    header("Content-type: application/vnd.ms-excel; charset=utf-8");
    header("Content-Disposition: attachment;filename=\"" . $sFileName . "\"");
    }


    ๋ˆˆ์น˜ ์ฑ˜๊ฒ ์ง€๋งŒ, ์ธํ„ฐ๋„ท ๋ธŒ๋ผ์šฐ์ €์—์„œ ํ•œ๊ธ€์ด ๊นจ์ง€๋Š” ๋ฌธ์ œ๋Š” ์ธ์ฝ”๋”ฉ ๋ฌธ์ œ ๋•Œ๋ฌธ์ด๋‹ค.

    ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฒ˜๋ฆฌํ•˜๋ฉด ํ•œ๊ธ€ ๊นจ์ง์ด ํ•ด๊ฒฐ๋œ๋‹ค.

    function ExcelHeader($sFileName) {
      $excelnm = iconv('UTF-8','EUC-KR',$sFileName);   -- ์ถ”๊ฐ€ 
      header("Content-type: application/vnd.ms-excel");
      header("Content-type: application/vnd.ms-excel; charset=utf-8");
      header("Content-Disposition: attachment;filename=\"" . $excelnm . "\"");  --๋ณ€์ˆ˜ ๋ณ€๊ฒฝ
    }

    ํฌ๋กฌ์€ ๋‹น์—ฐํžˆ ์ž˜ ๋˜๊ณ , ์ ์–ด๋„ IE11๊ณผ ์—ฃ์ง€์—์„œ๋„ ์•ก์…€ ๋‹ค์šด๋กœ๋“œ์‹œ ํ•œ๊ธ€ ๊นจ์ง์€ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€