本節內容:
一個php匯出文檔的類
例子:
複製代碼 代碼如下:
/**
* 產生word文檔的類
*
*/
class word
{
function start()
{
ob_start();
echo ' xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">';
}
function save($path)
{
echo "";
$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 .='
iGo運 單號 |
'.$val['box_code'].' |
日期 |
'.date('Y-m-d',$val[create_date]).' |
標示 姓名 |
'.$val[code].'/'.$val['orderid'].' '.$val['orderinfo']['user_name'].' |
| 件數 |
3 |
重量 |
56.5 |
品名 |
咬咬了,吸盤碗,學飲杯,魚乾油 |
服務 類別 |
庫房服務 |
服務 要求 |
合小箱 |
客戶 備忘
|
'.$val['orderinfo']['beizhu'].' |
到貨 情況
|
什麼問題?果點不到 什麼問題?果點不到 什麼問題?果點不到
|
';
}
$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();
//匯出word --end--
http://www.bkjia.com/PHPjc/825204.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825204.htmlTechArticle本節內容: 一個php匯出文檔的類 例子: 複製代碼 代碼如下: ?php /** * 產生word文檔的類 * */ class word { function start() { ob_start(); echo 'html xmlns...