메뉴 건너뛰기

프로그램언어

조회 수 29786 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
<?

header( "Content-type: application/vnd.ms-excel" );
header( "Content-type: application/vnd.ms-excel; charset=utf-8");
header( "Content-Disposition: attachment; filename = invoice.xls" );
header( "Content-Description: PHP4 Generated Data" );

$sql = "select * from tblName order by reg_date desc";
$result = mysql_query($sql);

// 테이블 상단 만들기
$EXCEL_STR = "
<table border='1'>
<tr>
   <td>번호</td>
   <td>코드</td>
   <td>내용</td>
</tr>";

while($row = mysql_fetch_array($result)) {
   $EXCEL_STR .= "
   <tr>
       <td>".$row['idx']."</td>
       <td>".$row['code']."</td>
       <td>".$row['contents']."</td>
   </tr>
   ";
}

$EXCEL_STR .= "</table>";

echo "<meta content=\"application/vnd.ms-excel; charset=UTF-8\" name=\"Content-type\"> ";
echo $EXCEL_STR;
?>

 


================================

PHP 엑셀 저장 excel 저장


브라우저화면에 출력되는 내용을 엑셀로 출력해야하는 경우가 많이 있습니다.

DB의 내용을 엑셀파일의 형태로 저장하여 백업을 하거나, 홈페이지 방문자가 화면의 내용을 엑셀형태로 받아가기를 원하는 경우 해당 기능을 구현해야 하는 경우가 있습니다.


엑셀로 저장

엑셀의 형태로 다운받을 수 있는 방법은 상당히 간단합니다.

해당 출력을 담당하는 소스 상단에 아래의 코드를 덧붙여주면 끝입니다.


단, 주의해야할 점이 있다면 header()함수 앞에서는 아무것도 출력을 해서는 안된다는 겁니다.

아래 샘플코드를 프로그램 파일 제일 상단에 두면 큰 문제를 만나시지는 않을 겁니다.


샘플코드


<?

$output_file_name = "다운로드.xls";

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

header( "Content-Disposition: attachment; filename={$output_file_name}.xls" );

header( "Content-Description: PHP4 Generated Data");

?>



  1. 리다이렉션(페이지 이동)의 3가지 방법, location.href

    Date2017.03.07 Views40135
    Read More
  2. [PHP] 게시판 글쓰기와 이미지 파일 DB 저장 및 불러오기 예제

    Date2017.02.19 Views35886
    Read More
  3. $_SERVER 환경변수

    Date2016.09.21 Views33237
    Read More
  4. PHP에서 PDF파일 생성하기

    Date2014.02.27 Views32777
    Read More
  5. PHP에서 자바스크립트 값 가져오기

    Date2014.02.27 Views31635
    Read More
  6. Class를 이용한 DB Connection 소스 (Oracle, MyS

    Date2014.02.27 Views30503
    Read More
  7. htmlentities <-> html_entity_decode (엔티티

    Date2014.04.12 Views30409
    Read More
  8. 무조건 알아야 할 PHP 속도 테스트 14 가지

    Date2014.02.27 Views30280
    Read More
  9. PHP로 Excel 파일 만들기...

    Date2014.02.27 Views30257
    Read More
  10. Text를 GD 이미지로 뿌리기

    Date2014.02.27 Views29813
    Read More
  11. php 엑셀 다운로드 구현

    Date2017.03.07 Views29786
    Read More
  12. 글내용 이미지 리사이징

    Date2014.02.27 Views29446
    Read More
  13. 쿠키변수받기

    Date2014.02.27 Views29211
    Read More
  14. Record Drag/Drop Position

    Date2014.02.27 Views29201
    Read More
  15. 간단한 PHP 파일 업로드, 다운로드 구현

    Date2017.03.06 Views28547
    Read More
  16. DB상의 많은 파일을 한꺼번에 다운받기

    Date2014.02.27 Views28332
    Read More
  17. GD를 이용한 스팸성 게시물 차단을 위한 보안 단어 입력 예제

    Date2014.02.27 Views26945
    Read More
  18. 주간날짜 뽑아오기

    Date2014.02.27 Views26731
    Read More
  19. 전화번호에 하이픈(-) 넣기

    Date2015.04.14 Views26622
    Read More
  20. PHP 변수전달 GET, POST

    Date2015.04.14 Views26566
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved