DB내용을 엑셀로 다운받기 > php

본문 바로가기
사이트 내 전체검색

php

DB내용을 엑셀로 다운받기

페이지 정보

작성자 서방님 댓글 0건 조회 377회 작성일 11-06-02 13:42

본문

TABLE 형식으로 하는방법도 있지만 느리고 자료가 커질경우 오류발생도 잦은편.

XML 형식이 파싱 속도도 빠르고 더 안정적인방법 입니다.

아래는 XML 형태의 엑셀 기본 형식. 여러개의 시트도 지원하는 장점이 있습니다.

[code]
<?xml version="1.0" encoding="EUC-KR"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40"> 
 <Worksheet ss:Name="aa">
  <Table>
    <Row>
    <Cell><Data ss:Type="String">a11</Data></Cell>
    <Cell><Data ss:Type="String">a12</Data></Cell>
    <Cell><Data ss:Type="String">a13</Data></Cell>
    </Row>
    <Row>
    <Cell><Data ss:Type="String">a21</Data></Cell>
    <Cell><Data ss:Type="String">a22</Data></Cell>
    <Cell><Data ss:Type="String">a23</Data></Cell>
    </Row>
  </Table>
 </Worksheet>
 <Worksheet ss:Name="bb">
  <Table>
    <Row>
    <Cell><Data ss:Type="String">b11</Data></Cell>
    <Cell><Data ss:Type="String">b12</Data></Cell>
    <Cell><Data ss:Type="String">b13</Data></Cell>
    </Row>
    <Row>
    <Cell><Data ss:Type="String">b21</Data></Cell>
    <Cell><Data ss:Type="String">b22</Data></Cell>
    <Cell><Data ss:Type="String">b23</Data></Cell>
    </Row>
  </Table>
 </Worksheet>
</Workbook>
[/code]

응용하여 다운받는 파일을 만들었습니다. 참고용..

[code]
<?php

        header("Content-type: application/vnd.ms-excel");
        header("Content-Disposition: attachment; filename=shop_list_$jb2[time_ymd].xls");
        header("Expires: 0");
        Header("Content-Transfer-Encoding: binary");
        header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
        header("Pragma: public");

echo "<?xml version=\"1.0\" encoding=\"EUC-KR\"?>
<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"
 xmlns:o=\"urn:schemas-microsoft-com:office:office\"
 xmlns:x=\"urn:schemas-microsoft-com:office:excel\"
 xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"
 xmlns:html=\"http://www.w3.org/TR/REC-html40\">
 <Worksheet ss:Name=\"Sheet1\">
  <Table>
    <Row>
    <Cell><Data ss:Type=\"String\">번호</Data></Cell>
    <Cell><Data ss:Type=\"String\">구입처명</Data></Cell>
    <Cell><Data ss:Type=\"String\">지역</Data></Cell>
    <Cell><Data ss:Type=\"String\">지점명</Data></Cell>
    <Cell><Data ss:Type=\"String\">약사명</Data></Cell>
    <Cell><Data ss:Type=\"String\">연락처</Data></Cell>
 <Cell><Data ss:Type=\"String\">홈페이지</Data></Cell>
 <Cell><Data ss:Type=\"String\">콩나물</Data></Cell>
 <Cell><Data ss:Type=\"String\">구분 (5번이 약국)</Data></Cell>
 <Cell><Data ss:Type=\"String\">탭메뉴 클릭시 검색됨</Data></Cell>
    </Row>";

 $sql = "select * from jb2_shop1 order by sh_id asc";
 $result = sql_query($sql);
 while($data = mysql_fetch_array($result)){

echo "
 <Row>
 <Cell><Data ss:Type=\"String\">$data[sh_id]</Data></Cell>
    <Cell><Data ss:Type=\"String\">$data[sh_name]</Data></Cell>
    <Cell><Data ss:Type=\"String\">$data[sh_area]</Data></Cell>
    <Cell><Data ss:Type=\"String\">$data[sh_branch]</Data></Cell>
    <Cell><Data ss:Type=\"String\">$data[sh_pharmacist]</Data></Cell>
    <Cell><Data ss:Type=\"String\">$data[sh_memo]</Data></Cell>
 <Cell><Data ss:Type=\"String\">$data[sh_homepage]</Data></Cell>
 <Cell><Data ss:Type=\"String\">$data[sh_map]</Data></Cell>
 <Cell><Data ss:Type=\"String\">$data[sh_div]</Data></Cell>
 <Cell><Data ss:Type=\"String\">$data[sh_tapchk]</Data></Cell>
 </Row>
 ";
 }
echo "</Table>
 </Worksheet>
</Workbook>";
?>
[/code]

댓글목록

등록된 댓글이 없습니다.

Total 612건 38 페이지
php 목록
번호 제목 글쓴이 조회 날짜
57 서방님 114 07-08
56 서방님 134 07-08
55 서방님 115 07-08
54 서방님 105 07-08
53 서방님 106 07-07
52 서방님 0 07-07
51 서방님 0 07-06
50 서방님 117 07-01
49 서방님 122 07-01
48 서방님 139 07-01
47 서방님 136 06-29
46 서방님 105 06-17
45 서방님 115 06-15
44 서방님 110 06-02
열람중 서방님 378 06-02
게시물 검색

회원로그인

접속자집계

오늘
284
어제
225
최대
1,347
전체
155,043
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.