Contents

조회 수 7486 댓글 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를 활용해서 필드명을 계속 가져오게 하면 쉽게 처리 됩니다.


?

  1. [c] 거리와 각도를 입력받아서 좌표로 변환

    Date2013.04.23 CategoryDevelop Byhooni Views10812
    Read More
  2. [c++] 퍼즐 버블버블 간단한 원리(사용공식)

    Date2013.04.23 CategoryDevelop Byhooni Views9953
    Read More
  3. [c] 문자열 자르는 함수(strtok) 예제

    Date2013.04.23 CategoryDevelop Byhooni Views12172
    Read More
  4. [ms-sql] 프로시져 예제..

    Date2013.04.23 CategorySystem/OS Byhooni Views13403
    Read More
  5. 객체지향 프로그래밍에 대한 개념.. (객체)

    Date2013.04.23 CategoryDevelop Byhooni Views7308
    Read More
  6. [jsp] 초간단한 include 구문 예제..

    Date2013.04.23 CategoryDevelop Byhooni Views7225
    Read More
  7. [unix] AIX쉘 초기 파일 (.cshrc)

    Date2013.04.23 CategorySystem/OS Byhooni Views10288
    Read More
  8. [php] 데이터를 엑셀,워드 형태로 변환할 때 헤더(ms-office)

    Date2013.04.23 CategoryDevelop Byhooni Views7486
    Read More
  9. [jsp] 페이지에 한글이 정상적으로 보이지 않을 때..

    Date2013.04.23 CategoryDevelop Byhooni Views8159
    Read More
  10. [asp] 기본 문법과 제어문

    Date2013.04.23 CategoryDevelop Byhooni Views7074
    Read More
  11. [asp] 문자열 관련 함수 요약

    Date2013.04.23 CategoryDevelop Byhooni Views7775
    Read More
  12. [asp] 문자열 넘겨받기 (get,post)

    Date2013.04.23 CategoryDevelop Byhooni Views8677
    Read More
Board Pagination Prev 1 ... 59 60 61 62 63 64 65 66 67 68 ... 98 Next
/ 98