반응형
휴대폰열 <td>에 mso-number-format:"\@" 스타일을 넣어주면 0이 붙어서 출력된다.
<?
header("Content-type: application/vnd.ms-excel");
header("Content-type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=filename.xls");
$sql = "select * from table_name order by no desc";
$stmt = mysql_query($sql);
$num = mysql_numrows($stmt);
$str = "<table border='1'>
<tr>
<td>번호</td>
<td>이름</td>
<td>휴대폰</td>
</tr>";
for($i = 0; $i < $num; $i++)
{
$row = mysql_fetch_array($stmt);
str .= "<tr>
<td>" . $row['no'] . "</td>
<td>" . $row['name'] . "</td>
<td style=mso-number-format:\"\@\">" . $row['hp'] . "</td>
</tr>";
}
$str .= "</table>";
echo "<meta content=\"application/vnd.ms-excel; charset=UTF-8\" name=\"Content-type\">";
echo $str;
?>
반응형