php匯出word格式資料的代碼執行個體_PHP教程

來源:互聯網
上載者:User
本節內容:
一個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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.