|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
把例子全部敲进去试验,完成一遍以后就会有心得了,因为你会发现为啥我的程序和书上的一模一样就是结果不正确。新手学习的时候必须承认,不容易,因为我也是过来人,你会发现原来有那么多常用的语句,函数都要记。excel|生成excel <?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
$sql = "select ";
if ( $HTTP_POST_VARS["C1"] == "ON" ) $sql .= "hdid, ";
if ( $C2 == "ON" ) $sql .= "location, ";
if ( $C3 == "ON" ) $sql .= "getip, ";
if ( $C4 == "ON" ) $sql .= "type, ";
if ( $C5 == "ON" ) $sql .= "pcusername, ";
if ( $C6 == "ON" ) $sql .= "usergroup, ";
if ( $C7 == "ON" ) $sql .= "ram, ";
if ( $C8 == "ON" ) $sql .= "cpu, ";
if ( $C9 == "ON" ) $sql .= "disk, ";
if ( $C10 == "ON" ) $sql .= "lanmac, ";
if ( $C11 == "ON" ) $sql .= "monitor, ";
if ( $C12 == "ON" ) $sql .= "attachhd, ";
if ( $C13 == "ON" ) $sql .= "software, ";
if ( $C14 == "ON" ) $sql .= "weblog, ";
if ( $C15 == "ON" ) $sql .= "other ";
if ( substr($sql, -2) == ", " ) $sql = substr($sql, 0, strlen($str)-2) . " ";
$sql .= "from pcinfo order by hdid asc";
$link = mysql_connect('127.0.0.1','root','0000') or die("o法B!Bj办理者!");
mysql_select_db('hdinfo',$link) or die("o法B到Y料!Bj办理者!");
//echo $sql;
$result = mysql_query("$sql");
$total=mysql_num_rows($result);
//echo $total;
if ( $HTTP_POST_VARS["C1"] == "ON" ) echo "硬件编号\t";
if ( $C2 == "ON" ) echo "所属厂别\t";
if ( $C3 == "ON" ) echo "所分派的IP\t";
if ( $C4 == "ON" ) echo "机械型号\t";
if ( $C5 == "ON" ) echo "利用者称号\t";
if ( $C6 == "ON" ) echo "利用者部分\t";
if ( $C7 == "ON" ) echo "内存设置装备摆设\t";
if ( $C8 == "ON" ) echo "CPU设置装备摆设\t";
if ( $C9 == "ON" ) echo "硬盘设置装备摆设\t";
if ( $C10 == "ON" ) echo "网卡型号及MAC\t";
if ( $C11 == "ON" ) echo "显示器型号\t";
if ( $C12 == "ON" ) echo "其所附的硬件\t";
if ( $C13 == "ON" ) echo "所装置的软件\t";
if ( $C14 == "ON" ) echo "上彀请求记载\t";
if ( $C15 == "ON" ) echo "其他\t";
echo " \t\n";
for ($i=0 ;$i<$total; $i++)
{
$result_row=mysql_fetch_row($result);
while (list($no,$content)=each($result_row))
{
echo "$content\t";
}
echo " \t\n";
}
以上是依据分歧的选项查询分歧的列,然后生成Excel 的文件
我是根据自己的成长历程来写的,如有不对的还请指正。 |
|