PHP導出word,CVS,PDF


WORD:

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
//有了這些,可以把帶html標簽的html源碼導入到word里,並且可以保持html的樣式。
/* 
<STYLE>
BR.page { page-break-after: always }
</STYLE>
在<head>部分加這個是為了實現打印的時候分頁
 */
$wordStr = '<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">
<head>
<STYLE>
BR.page { page-break-after: always }
</STYLE>
</head><body>';

    $wordStr = "<b>hello</b><p>this is html code</p>";

    $wordStr .= '</body></html>';
    //防止導出亂碼
    $file = iconv("utf-8", "GBK", $filename);

    header("Content-Type: application/doc");
    header("Content-Disposition: attachment; filename=" . $file . ".doc");
    echo $wordStr;
?>

 

 

CVS:

<?php
header("Content-Disposition: attachment; filename=郵寄地址.csv");
echo "姓名,性別,年齡,電話\n張三,男,23,15010125818";
?>

注:echo中的逗號是每個列的分割標識符,\n則是換行。

 

還有如下可參考:

header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");

PDF:

<?php
header("Content-type:application/pdf");

// 文件將被稱為 downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");

// PDF 源在 original.pdf 中
readfile("original.pdf");
?>

<html>
<body>

...
...

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM