Contents

조회 수 8845 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

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

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
우선 excel이나 ms-word로 변환할려면 아래의 헤더부분이 필요합니다. 
<? 
    // 엑셀의 경우
    header( "Content-type: application/vnd.ms-excel" ); 
    header( "Content-Disposition: attachment; filename=파일명.xls" ); 
    header( "Content-Description: PHP4 Generated Data" ); 
    
    // 워드일 경우
    header( "Content-type: application/vnd.ms-word" ); 
    header( "Content-Disposition: attachment; filename=파일명.doc" ); 
    header( "Content-Description: PHP4 Generated Data" ); 
?>

그 다음엔 엑셀에서 자기가 원하는 표를 구성합니다. 
그리고 구성한 엑셀파일을 웹페이지로 저장합니다. (엑셀에서 웹페이지로 저장이 가능합니다.) <- 이 부분이 핵심이라고 할 수 있겠네요. 
그런다음 메모장이나 기타 에디터로 여시고 상단에 위의 헤더를 추가합니다. 
그리고 해당 셀부분에 DB에서 해당하는 필드값을 넣어줍니다. 
워드도 같은 방식으로 구성하면 됩니다. 


엑셀 변환시 샘플코드
<?
    include "./DBConn.php";
    
    header( "Content-type: application/vnd.ms-excel" ); 
    header( "Content-Disposition: attachment; filename=업체관리.xls" ); 
    header( "Content-Description: PHP4 Generated Data" ); 
    
    $table_data = mysql_query("SELECT * FROM company order by BC_REGDATE desc");
?>
<?
    while( $data = mysql_fetch_array( $table_data ) ) :
    
    $bc_no=$data[BC_NO];
    $bc_company=stripslashes($data[BC_COMPANY]);
    $bc_name=stripslashes($data[BC_NAME]);
    $bc_comno=$data[BC_COMNO];
    $bc_address1=stripslashes($data[BC_ADDRESS1]);
    $bc_address2=stripslashes($data[BC_ADDRESS2]);
?>
<html>
<table>
<tr>
<td> <?echo "$bc_company"; ?> </td>
</tr>
<?$i++; endwhile;?>
</table>
</html>


또 다른 샘플.. ㅋㅋ

<html>
...

<table>
<?php
    $table_data = mysql_query("SELECT * FROM company order by BC_REGDATE desc");
    while( $data = mysql_fetch_array( $table_data ) ) :
    {
        echo "<tr>";
        
        foreach($data as $field)
        {
            echo "<td>";
            echo $field;
            echo "</td>";
        }
        echo "</tr>";
    }
?>
</table>

</html>

foreach를 활용해서 필드명을 계속 가져오게 하면 쉽게 처리 됩니다.


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
961 System/OS [linux] 메일서버 세팅정보(sendmail) hooni 2003.04.23 18661
960 System/OS [windows] 도스 사용 팁 hooni 2003.04.23 18633
959 Etc GSM에서 음성이 실리는 과정 요약.. hooni 2013.04.23 18630
958 System/OS [linux] 커널 컴파일, 설정 hooni 2003.04.23 18628
957 System/OS 무선 인증 서버.. 김도.. ㅋㅋ file hooni 2013.04.23 18623
956 Algorithm 암호 알고리즘 및 프로토콜의 이해.. file hooni 2013.04.23 18580
955 System/OS 네트워크별 MTU(최대 전송 단위) hooni 2013.04.23 18500
954 System/OS [windows] 패스워드를 잊어먹었을때.. hooni 2003.04.23 18495
953 Algorithm [security] 블럭 암호에 대해서.. hooni 2013.04.23 18471
952 PPT [php] 프레임워크 발표자료 및 샘플 구현 소스 file hooni 2013.04.23 18432
951 Develop [ios] 자주 쓰는 패턴과 API hooni 2013.04.23 18428
950 System/OS [switch] 시스코 카탈리스트(Cisco Catalyst) 기본 설정 hooni 2013.04.23 18383
Board Pagination Prev 1 ... 14 15 16 17 18 19 20 21 22 23 ... 99 Next
/ 99