Views 7488 Votes 0 Comment 0
?

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

?

  1. [c] UTF-8을 EUC-KR로 변환.. (iconv)

    Date2013.04.23 CategoryDevelop Byhooni Views20127
    Read More
  2. [c] 도메인(호스트)으로 IP정보 알아오기.. (nslookup과 비슷)

    Date2013.04.23 CategoryDevelop Byhooni Views6925
    Read More
  3. [c] 파이프(popen)로 다른 프로세스 실행결과 가져오기

    Date2013.04.23 CategoryDevelop Byhooni Views8392
    Read More
  4. [c++] Win32 API 기본 출력인 MessageBox() 함수 사용 예제..

    Date2013.04.23 CategoryDevelop Byhooni Views12629
    Read More
  5. [c++] mfc에서 윈도우 항상 위 속성 주기..

    Date2013.04.23 CategoryDevelop Byhooni Views11297
    Read More
  6. [c] 쓰레드에 대한 내용 퍼오기..ㅡㅡ;

    Date2013.04.23 CategoryDevelop Byhooni Views8430
    Read More
  7. [c++] 채팅로봇 소스.. ㅋㄷㅋㄷ

    Date2013.04.23 CategoryDevelop Byhooni Views8878
    Read More
  8. [doc] 인공지능 관련 자료(채팅로봇도 포함..)

    Date2013.04.23 CategoryPPT Byhooni Views18001
    Read More
  9. [doc] mfc 매뉴얼 다운 받아서 완성하기.. ㅋㄷ

    Date2013.04.23 CategoryDevelop Byhooni Views7706
    Read More
  10. [c++] String Tokenizer (나중에 c 코드로 변경해서 사용할 것)

    Date2013.04.23 CategoryDevelop Byhooni Views11690
    Read More
  11. [c++] mfc 윈도우에서 ODBC 사용하여 MDB파일 읽기.. ㅋㅋ

    Date2013.04.23 CategoryDevelop Byhooni Views9118
    Read More
  12. [js] 실행되는 디렉토리 확인하는 스크립트..

    Date2013.04.23 CategoryDevelop Byhooni Views6764
    Read More
  13. [c] 파일(File)의 연결과 연결 해제 (link, unlink, chown)

    Date2013.04.23 CategoryDevelop Byhooni Views9543
    Read More
  14. 라이브러리에 대한 설명 (static & dynamic library)

    Date2013.04.23 CategoryDevelop Byhooni Views6944
    Read More
  15. [java] RGB코드를 HEX코드로 변환하는 코드 ㅎㅎ

    Date2013.04.23 CategoryDevelop Byhooni Views8013
    Read More
  16. php.ini 설정 안됐을때.. ㅋㅋ

    Date2013.04.23 CategorySystem/OS Byhooni Views11639
    Read More
Board Pagination Prev 1 ... 33 34 35 36 37 ... 74 Next
/ 74