Posted
Filed under PHP
[원본 주소] - http://cafe.naver.com/suninet.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=548
Excel 다운로드 처리 샘플.

<?
header("Content-Type: application/vnd.ms-excel");
header("Content-Type: application/vnd.ms-excel; charset=euc-kr");
header("Content-Type: application/x-msdownload");
header("Content-Disposition: attachment; filename=$fileName.xls");
header("Content-Description: PHP4 Generated Data");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Type: file/unknown");
?>


<html>
<head><title>엑셀변환</title>
<script language="javascript">
self.close();
</script>
<style type="text/css">
body {  font-family: "굴림"; font-size: 9pt; color: #595959; line-height:130%}
td {  font-family: "굴림"; font-size: 9pt; color: #595959; line-height:130%}

A:visited { color: #595959; text-decoration: none;}

A:hover { color:#595959; text-decoration: none; }

A:active { color: #595959; text-decoration: none; }

A:link { color: #595959; text-decoration: none; }
</style>
</head>
<body>

<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolor="#DEDBDE">
<tr>
<?
for($i=0;$i<count($fieldName);$i++)
{
 echo "<td align='center' bgcolor='#F7F3F7' height='25'><b>".$fieldName[$i]."</b></td>";
}
?>
</tr>

<?
$sql = str_replace("\\", "", "$sql");
$re = $DB->setResult($sql);

$j = 0;

for($i=0;$i<$re[cnt];$i++)
{
 $row = mysql_fetch_array($re[result]);
 if($j == 0) echo "<TR>";
 for($k=0;$k<count($fieldValue);$k++) { echo "<td align='center' bgcolor='#FFFFFF'>&nbsp;".$row[$fieldValue[$k]]."</td>"; }

 if($j == count($fieldName)) { echo "</tr>"; $j = 0; }
}
?>
</tr>

</table>
</body>
</html>

2009/08/06 13:12 2009/08/06 13:12