엑셀로 출력하는 방법

2015-11-02 (월) 18:22:20 4,367
Copy
<?php$sub_menu = "400100";include_once('./_common.php');include (G5_SKIN_PATH.'/multi_category/lib.php'); auth_check($auth[$sub_menu], 'r'); $g5['title'] = '전체 접수내역';include_once('./handling.sub.php'); $colspan = 5; $max = 0;$sum_count = 0;$sql = " select * from {$g5['write_aaaa_table']}            where wr_3 between '{$fr_date}' and '{$to_date}' order by wr_id desc";$result = sql_query($sql); ?> <div class="tbl_head01 tbl_wrap">     <table>    <caption><?php echo $g5['title']; ?> 목록</caption>    <thead>    <tr>        <th scope="col">분류</th>        <th scope="col">제목</th>        <th scope="col">접수경로</th>        <th scope="col">접수일</th>        <th scope="col">접수시간</th>        <th scope="col">접수자</th>        <th scope="col">연락처</th>        <th scope="col">휴대전화</th>        <th scope="col">지역</th>        <th scope="col">상세주소</th>        <th scope="col">내용</th>        <th scope="col">기타사항</th>        <th scope="col">처리상태</th>        <th scope="col">처리완료일</th>        <th scope="col">처리불가 사유</th>     </tr>    </thead>     <tbody>      <?php      $h1 = 0;      $h2 = 0;      $h3 = 0;      $h4 = 0;      $no = 0;       for ($i=0; $row=sql_fetch_array($result); $i++) {          $no = $i+1;          $ca_name = $row['ca_name'];            include('handle_multi.php');          $wr_1 = $row['wr_1'];          $wr_2 = $row['wr_2'];          $wr_3 = $row['wr_3'];          $wr_4 = $row['wr_4'];          $wr_5 = $row['wr_5'];          $wr_6 = $row['wr_6'];          $wr_7 = $row['wr_7'];          $wr_8 = $row['wr_8'];          $wr_9 = $row['wr_9'];          $wr_10 = $row['wr_10'];          $wr_11 = $row['wr_11'];          $wr_12 = $row['wr_12'];          $wr_13 = $row['wr_13'];          $wr_subject = $row['wr_subject'];          $wr_content = $row['wr_content'];          $bg = 'bg'.($i%2);           if($wr_1 == '처리중'){            $h1 = $h1 + 1;          }          else if($wr_1 == '처리완료'){            $h2 = $h2 + 1;          }          else if($wr_1 == '처리불가'){            $h3 = $h3 + 1;          }          else {            $h4 = $h4 + 1;          }    ?>     <tr class="<?php echo $bg; ?>">        <td><?php echo $ca_name ?></td>        <td><?php echo $wr_subject ?></td>        <td><?php echo $wr_2 ?></td>        <td><?php echo $wr_3 ?></td>        <td><?php echo $wr_4 ?></td>        <td><?php echo $wr_5 ?></td>        <td><?php echo $wr_6 ?></td>        <td><?php echo $wr_7 ?></td>        <td><?php echo $wr_8 ?></td>        <td><?php echo $wr_9 ?></td>        <td><?php echo $wr_content ?></td>        <td><?php echo $wr_10 ?></td>        <td><?php echo $wr_1 ?></td>        <td><?php echo $wr_12 ?></td>        <td><?php echo $wr_13 ?></td>    </tr>     <?php    }    $sum_count = $no;    if ($i == 0)        echo '<tr><td colspan="15" class="empty_table">자료가 없습니다.</td></tr>';     ?>    </tbody>    <tfoot>    <tr>        <td>합계</td>        <td><strong><?php echo $sum_count ?></strong></td>        <td colspan="13"> 처리중 : <?php echo $h1 ?> | 처리완료 : <?php echo $h2 ?> | 처리불가 : <?php echo $h3 ?> | 대기 : <?php echo $h4 ?></td>    </tr>    </tfoot>    </table></div> <?phpinclude_once('./admin.tail.php');?>

그누보드 에서 관리자에서 날짜별 조회하여 게시글을 출력하는 페이지를 만들어 보았습니다.
이렇게 출력된 게시글을 엑셀로 출력이라는 버튼을 만들어서 엑셀로 출력하고 싶은데
어떻게 하는지 알고싶습니다.
|

답변 1개 / 댓글 1개

엑셀로 출력시 디자인 요소인 header, footer가 있으면 같이 출력이 되기 때문에 body 부분에는 table만 존재해야 됩니다.

그리고 엑셀로 출력할때는 header에 어플리케이션 타입을 엑셀로 정의하시면 됩니다.

변수를 하나 정의하셔서 엑셀이 아닐경우에만

$sub_menu = "400100";

include_once('./_common.php');

include (G5_SKIN_PATH.'/multi_category/lib.php');

auth_check($auth[$sub_menu], 'r');

$g5['title'] = '전체 접수내역';

include_once('./handling.sub.php');

이부분과

include_once('./admin.tail.php');

이 부분을 노출하시고

엑셀일 경우에는 소스 앞부분에

header("Pragma:");

header("Cache-Control:");

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

header("Content-Disposition: attachment; filename=$file_name); // 저장을 원하는 파일제목

header("Content-Description: PHP5 Generated Data"); // description

를 노출하시면 됩니다.

문서 컨텐트 타입이 엑셀이므로 엑셀 파일로 다운이 됩니다.

 


답변에 대한 댓글 1개

2015-11-03 (화) 09:49:37
말씀하신데로 해 보았는데 500에러가 뜨네요...ㅠ
노출을 하지말라는 소스중에
include_once('./handling.sub.php');
이것은 날짜 선택하는 페이지인데
이것도 노출하면 안되는건가요?
그리고 제가 날짜를 선택해서 조회하면
현재 출력된 내용을 엑셀로 저장하고 싶은데... 엑셀로 저장이라는 버튼을 만들어서
이 방법은 없을까요?

답변을 작성하려면 로그인이 필요합니다.