<?php
ob_start();
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 10">
<link rel=File-List href="Page.files/filelist.xml">
<style id="Book1_10519_Styles">
<!--table
{mso-displayed-decimal-separator:".";
mso-displayed-thousand-separator:",";}
.font510519
{color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;}
.xl1510519
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-number-format:General;
text-align:general;
vertical-align:middle;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
.xl2210519
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-number-format:General;
text-align:general;
vertical-align:middle;
border:.5pt solid windowtext;
background:silver;
mso-pattern:auto none;
white-space:nowrap;}
.xl2310519
{padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore:padding;
color:windowtext;
font-size:12.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-number-format:General;
text-align:general;
vertical-align:middle;
border:.5pt solid windowtext;
mso-background-source:auto;
mso-pattern:auto;
white-space:nowrap;}
ruby
rt
{color:windowtext;
font-size:9.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:宋体;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-char-type:none;}
-->
</style>
</head>
<body>
<!--[if !excel]> <![endif]-->
<!--下列信息由 Microsoft Excel 的“发布为 Web 页”向导生成。-->
<!--如果同一条目从 Excel 中重新发布,则所有位于 DIV 标记之间的信息均将被替换。-->
<!----------------------------->
<!--“从 EXCEL 发布 Web 页”向导开始-->
<!----------------------------->
<div id="Book1_10519" align=center x:publishsource="Excel">
<?php
if(false==isset($_POST["data"]))
{
echo "没有要显示的数据" ;
exit;
}
?>
<table x:str border=0 cellpadding=0 cellspacing=0 width=519 style='border-collapse:
collapse;table-layout:fixed;width:389pt'>
<col width=72 span=2 style='width:54pt'>
<col width=163 style='mso-width-source:userset;mso-width-alt:5216;width:122pt'>
<col width=87 style='mso-width-source:userset;mso-width-alt:2784;width:65pt'>
<col width=125 style='mso-width-source:userset;mso-width-alt:4000;width:94pt'>
<tr height=19 style='height:14.25pt'>
<td height=19 class=xl1510519 width=72 style='height:14.25pt;width:54pt'></td>
<td class=xl1510519 width=72 style='width:54pt'></td>
<td class=xl1510519 width=163 style='width:122pt'></td>
<td class=xl1510519 width=87 style='width:65pt'></td>
<td class=xl1510519 width=125 style='width:94pt'></td>
</tr>
<tr height=19 style='height:14.25pt'>
<td height=19 class=xl1510519 style='height:14.25pt'></td>
<td class=xl2210519>名称</td>
<td class=xl2210519 style='border-left:none'>地址</td>
<td class=xl2210519 style='border-left:none'>QQ号</td>
<td class=xl2210519 style='border-left:none'>电子邮件</td>
</tr>
<?php
foreach($_POST["data"] as $val)
{
extract($val) ;
?>
<tr height=19 style='height:14.25pt'>
<td height=19 class=xl1510519 style='height:14.25pt'></td>
<td class=xl2310519 style='border-top:none'><?php echo $username ; ?></td>
<td class=xl2310519 style='border-top:none;border-left:none'><?php echo $add ; ?></td>
<td class=xl2310519 style='border-top:none;border-left:none'><?php echo $qq ; ?> </td>
<td class=xl2310519 style='border-top:none;border-left:none'><?php echo $email ; ?></td>
</tr>
<?php
}
?>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=72 style='width:54pt'></td>
<td width=72 style='width:54pt'></td>
<td width=163 style='width:122pt'></td>
<td width=87 style='width:65pt'></td>
<td width=125 style='width:94pt'></td>
</tr>
<![endif]>
</table>
</div>
<!----------------------------->
<!--“从 EXCEL 发布 Web 页”向导结束-->
<!----------------------------->
</body>
</html>
<?php
$outStr=ob_get_contents();
ob_end_clean();
header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".strlen($outStr));
Header("Content-Disposition: attachment; filename=test.Xls");
// 输出文件内容
echo $outStr ;
?>
输入页面的代码:
-------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<form name="form1" method="post" action="showExcel.php">
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>名称</td>
<td>地址</td>
<td>QQ号</td>
<td>电子邮件</td>
</tr>
<tr>
<td><input name="data[0][username]" type="text" id="data[0][username]"></td>
<td><input name="data[0][add]" type="text" id="data[0][add]"></td>
<td><input name="data[0][qq]" type="text" id="data[0][qq]"></td>
<td><input name="data[0][email]" type="text" id="data[0][email]"></td>
</tr>
<tr>
<td><input name="data[1][username]" type="text" id="data[1][username]"></td>
<td><input name="data[1][add]" type="text" id="data[1][add]"></td>
<td><input name="data[1][qq]" type="text" id="data[1][qq]"></td>
<td><input name="data[1][email]" type="text" id="data[1][email]"></td>
</tr>
<tr>
<td><input name="data[2][username]" type="text" id="data[2][username]"></td>
<td><input name="data[2][add]" type="text" id="data[2][add]"></td>
<td><input name="data[2][qq]" type="text" id="data[2][qq]"></td>
<td><input name="data[2][email]" type="text" id="data[2][email]"></td>
</tr>
<tr>
<td><input name="data[3][username]" type="text" id="data[3][username]"></td>
<td><input name="data[3][add]" type="text" id="data[3][add]"></td>
<td><input name="data[3][qq]" type="text" id="data[3][qq]"></td>
<td><input name="data[3][email]" type="text" id="data[3][email]"></td>
</tr>
<tr>
<td><input name="data[4][username]" type="text" id="data[4][username]"></td>
<td><input name="data[4][add]" type="text" id="data[4][add]"></td>
<td><input name="data[4][qq]" type="text" id="data[4][qq]"></td>
<td><input name="data[4][email]" type="text" id="data[4][email]"></td>
</tr>
<tr>
<td><input name="data[5][username]" type="text" id="data[5][username]"></td>
<td><input name="data[5][add]" type="text" id="data[5][add]"></td>
<td><input name="data[5][qq]" type="text" id="data[5][qq]"></td>
<td><input name="data[5][email]" type="text" id="data[5][email]"></td>
</tr>
<tr>
<td><input name="data[6][username]" type="text" id="data[6][username]"></td>
<td><input name="data[6][add]" type="text" id="data[6][add]"></td>
<td><input name="data[6][qq]" type="text" id="data[6][qq]"></td>
<td><input name="data[6][email]" type="text" id="data[6][email]"></td>
</tr>
<tr>
<td><input name="data[7][username]" type="text" id="data[7][username]"></td>
<td><input name="data[7][add]" type="text" id="data[7][add]"></td>
<td><input name="data[7][qq]" type="text" id="data[7][qq]"></td>
<td><input name="data[7][email]" type="text" id="data[7][email]"></td>
</tr>
<tr>
<td><input name="data[8][username]" type="text" id="data[8][username]"></td>
<td><input name="data[8][add]" type="text" id="data[8][add]"></td>
<td><input name="data[8][qq]" type="text" id="data[8][qq]"></td>
<td><input name="data[8][email]" type="text" id="data[8][email]"></td>
</tr>
</table>
<input type="submit" name="Submit" value="Excel查看">
</form>
<a href="show_source.php" target="_blank">查看程序代码</a>
</body>
</html>