메뉴 건너뛰기

프로그램언어

조회 수 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. 함수이름을 변수로 사용하기, 매개변수 없는 함수에 매개변수 넣기

    Date2021.03.26 Views746
    Read More
  2. JAVASCRIPT 차트, 그래프 모음 (php chart, graph )

    Date2021.03.26 Views1612
    Read More
  3. 구글 학술 검색

    Date2021.03.26 Views255
    Read More
  4. 복권 번호 뽑기

    Date2021.03.26 Views338
    Read More
  5. 문자열 함수 모음

    Date2021.03.26 Views318
    Read More
  6. 알파벳 순서대로 출력하기 ord(), chr()

    Date2021.03.26 Views580
    Read More
  7. MYSQL DB의 모든 테이블에서 문자열 검색 하기

    Date2021.03.26 Views913
    Read More
  8. while, for, foreach 속도 비교

    Date2021.03.26 Views618
    Read More
  9. 배열 더하기 (+ 를 이용한 배열 합치기 )

    Date2021.03.26 Views451
    Read More
  10. csv파일 다루기. fputcsv(), fgetcsv()

    Date2021.03.26 Views558
    Read More
  11. substr(), mb_substr(), iconv_substr()

    Date2021.03.26 Views564
    Read More
  12. PEAR DB 관련 함수들

    Date2021.03.26 Views690
    Read More
  13. 파일을 변수에 담기(ob_start를 이용한 방법)

    Date2021.03.26 Views674
    Read More
  14. 문자,숫자 랜덤 출력

    Date2021.03.26 Views404
    Read More
  15. PHP Notice: Use of undefined constant ... assumed ... 오류

    Date2021.03.26 Views307
    Read More
  16. HTTP 인증하기, 로그인창 띄우기

    Date2021.03.26 Views214
    Read More
  17. 콜론 연산자

    Date2021.03.26 Views307
    Read More
  18. 상수, 마법상수, 모든 상수 보기

    Date2021.03.26 Views236
    Read More
  19. 조건문의 함수실행 여부 if ( 0 && ... )

    Date2021.03.26 Views227
    Read More
  20. printf() sprintf()

    Date2021.03.26 Views272
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved