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]
댓글목록
등록된 댓글이 없습니다.