Contents

?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
우선 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
No. Category Subject Author Date Views
745 Develop [vim] vim 명령으로 &#65279; 문자 제거하기 (remove 65279 bomb) hooni 2021.02.03 1161
744 Develop [js] Click button copy to clipboard hooni 2018.04.05 1171
743 Develop [ios] Facebook Cache 갱신하는 함수 file hooni 2017.02.27 1181
742 Develop [ios] 코코아 프로그래밍의 네이밍 룰(명명 규칙) hooni 2017.05.11 1181
741 Develop [ios] NavigationController 에서 왼쪽(back) 버튼 후킹하기 hooni 2015.10.23 1183
740 Develop 사이버보안실무 발표자료 (2017.06.08) file hooni 2017.06.05 1205
739 Develop [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 hooni 2016.10.03 1208
738 Develop [ios] UIWebView를 이용한 로컬 HTML 파일 표시 file hooni 2015.01.02 1236
737 Develop [ios] APNS, Remote Push 사용자가 수신을 동의했는지 확인하기 hooni 2018.10.19 1252
736 Develop [ios] 동영상 플레이어 샘플 (for PIP Player) file hooni 2017.03.15 1261
735 Develop [android] How can I place app icon on launcher home screen? hooni 2016.11.15 1263
734 Develop [ios] GPS 이용 상태 확인 hooni 2015.04.27 1293
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 71 Next
/ 71