php 导出word格式的数据
大家也许对php导出excel格式数据的原理很熟悉了吧,但是excel格式的数据的格式很死不灵活的,用户一定要导出word格式的数据 在技术经理的指导下,马马虎虎的写了一个还算凑合的,以下是具体的程序代码:// 这是word 的类(不用改,直接拷贝过去建一个word的类文件放在自己的公共的类文件夹下)
class word
{
function start()
{
ob_start();
echo '<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">';
}
function save($path)
{
echo "</html>";
$data = ob_get_contents();
ob_end_clean();
$this->wirtefile ($path,$data);
}
function wirtefile ($fn,$data)
{
$fp=fopen($fn,"wb");
fwrite($fp,$data);
fclose($fp);
}
}
// 这里是你 导出的程序文件
// 导出 **********start**********
require SITE_ROOT.'include/word.class.php'; // 上面的类文件我是放在 根目录下的include文件夹下
$word = new word();
// 查询数据填入 word 中
$result = $db->query("SELECT * FROM ".DB_PRE."box where status='9' order by boxid DESC");
while($r = $db->fetch_array($result))
{
$r['orderinfo'] = $db->get_one("SELECT * FROM ".DB_PRE."order where orderid='".$r['orderid']."'");
$r['wrapinfo'] = $db->get_one("SELECT * FROM ".DB_PRE."wrap where orderid='".$r['orderid']."'");
$boxlist[] = $r;
}
foreach($boxlist as $key=>$val){
$order->UPCAbarcode($val['box_code']);
$html .='<table width=800 cellpadding="6" align="center" cellspacing="5" bgcolor="#000000">
<tr bgcolor="White" height="50">
<td width=80 style="border:1px solid #c8c8c8;">iGo运<br/>单号</td>
<td width=300 style="border:1px solid #c8c8c8;"><img src='.$val['iGocode_code'].' /><br/> '.$val['box_code'].'</td>
<td width=60 style="border:1px solid #c8c8c8;">日期</td>
<td width=100 style="border:1px solid #c8c8c8;">'.date('Y-m-d',$val).'</td>
<td width=100 style="border:1px solid #c8c8c8;">标示<br/>姓名</td>
<td width=240 style="border:1px solid #c8c8c8;">'.$val.'/'.$val['orderid'].'<br/>'.$val['orderinfo']['user_name'].'</td>
</tr>
<tr bgcolor="White">
<td width=60 style="border:1px solid #c8c8c8;">件数</td>
<td width=40 style="border:1px solid #c8c8c8;">3</td>
<td width=40 style="border:1px solid #c8c8c8;">重量</td>
<td width=150 style="border:1px solid #c8c8c8;">56.5</td>
<td width=40 style="border:1px solid #c8c8c8;">品名</td>
<td width=390 style="border:1px solid #c8c8c8;">咬咬了,吸盘碗,学饮杯,鱼干油</td>
</tr>
<tr bgcolor="White">
<td width=110 style="border:1px solid #c8c8c8;">服务<br/>类别</td>
<td width=200 style="border:1px solid #c8c8c8;">库房服务</td>
<td width=110 style="border:1px solid #c8c8c8;">服务<br/>要求</td>
<td width=280 style="border:1px solid #c8c8c8;">合小箱</td>
</tr>
<tr bgcolor="White">
<td width=120 style="border:1px solid #c8c8c8;"><br/><br/>客户<br/>备注<br/><br/></td>
<td width=580 style="border:1px solid #c8c8c8;">'.$val['orderinfo']['beizhu'].'</td>
</tr>
<tr bgcolor="White">
<td width=120 style="border:1px solid #c8c8c8;"><br/><br/><br/>到货<br/>情况<br/><br/><br/><br/></td>
<td width=580 style="border:1px solid #c8c8c8;">什么问题?果点不到<br/>什么问题?果点不到<br/>什么问题?果点不到<br/><br/><br/><br/><br/><br/><br/><br/></td>
</tr>
</table> <br/><br/><br/><br/>
';
}
$word->start();
$filename = '拣货单导出.doc';
echo $html;
$word->save($filename);
//文件的类型
header('Content-type: application/word');
header('Content-Disposition: attachment; filename="拣货单导出.doc"');
readfile($filename);
ob_flush();
flush();
exit();
// 导出 **********end**********
// 好啦 运行一下 看看效果吧
页:
[1]