메뉴 건너뛰기

프로그램언어

조회 수 29790 추천 수 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. PHPExcel 클래스를 이용해 Excel 2007~2010 의 xlsx 파일 읽기 (100만 행 까지)

    Date2017.03.06 Views21695
    Read More
  2. php/asp에서 가상번호 부여와 가상번호를 거꾸로 적용

    Date2019.01.08 Views1429
    Read More
  3. PHP, $_SERVER 변수

    Date2017.04.13 Views19505
    Read More
  4. PHP 휴대폰번호 짜르기 (preg_replace) "-" 넣기. 형식바꾸기

    Date2018.07.04 Views4057
    Read More
  5. PHP 확장 모듈을 이용한 C 라이브러리 사용

    Date2018.10.27 Views3786
    Read More
  6. PHP 하위 디렉토리 포함 디렉토리 리스트 출력

    Date2023.01.12 Views236
    Read More
  7. PHP 파일크기 단위 붙이기 (용량 변환) file size conversion source code

    Date2018.07.04 Views5804
    Read More
  8. php 파일 확장자

    Date2014.02.27 Views20234
    Read More
  9. PHP 파일 업로드 FORM 처리

    Date2023.01.12 Views229
    Read More
  10. php 파일 다운로드 구현

    Date2014.02.27 Views19794
    Read More
  11. php 파일 다운로드 구현

    Date2014.04.12 Views21700
    Read More
  12. PHP 파일 다루기

    Date2015.04.14 Views22401
    Read More
  13. PHP 특정 디렉토리에 있는 파일 갯수 구하기

    Date2018.07.19 Views5455
    Read More
  14. php 이미지 리사이징 image resizing

    Date2023.01.12 Views259
    Read More
  15. PHP 이미지 리사이즈 함수 imagecopyresized

    Date2023.01.12 Views212
    Read More
  16. PHP 외부 XML 파싱 하기

    Date2019.06.24 Views1946
    Read More
  17. php 엑셀 다운로드 구현

    Date2017.03.07 Views29790
    Read More
  18. PHP 에서의 소켓(Socket) 통신

    Date2014.04.12 Views20395
    Read More
  19. php 암호화 복호화 , 간단한 암호화

    Date2023.01.12 Views366
    Read More
  20. PHP 쉘 스크립트

    Date2021.03.26 Views803
    Read More
Board Pagination Prev 1 ... 6 7 8 9 10 11 12 13 14 15 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved