當前位置:首頁 » 編程語言 » php合並文件

php合並文件

發布時間: 2023-11-17 04:03:49

php 導出csv時如何設置屬性,合並單元格之類的。。

CSV文件本身就是不帶格式符號的純文字,無法直接在PHP中控制單元格合並這樣的事情,我覺得你可以用html代碼生成execl能直接讀的文檔比較好

$result=mysql_query("select*fromstudentorderbyidasc");
$str="<tr><td>姓名</td><td>性別</td><td>年齡</td></tr> ";
$str=iconv('utf-8','gb2312',$str);
while($row=mysql_fetch_array($result)){
$name=iconv('utf-8','gb2312',$row['name']);
$sex=iconv('utf-8','gb2312',$row['sex']);
//要控制合並啥的,在下邊修改即可
$str.="<tr><td>".$name."</td><td>".$sex."</td><td>".$row['age']."</td></tr>";
}

$filename=date('Ymd').'.xls';
export_xls($filename,$str);


functionexport_xls($filename,$string){
//可以修改樣式,控制字型大小、字體、表格線、對齊方式、表格寬度、單元格padding等,在下邊的<style></style>
$header="<htmlxmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <metahttp-equiv="Content-type"content="text/html;charset=GBK"/> <style> td{padding:4px;mso-ignore:padding;color:windowtext;font-size:10.0pt;font-weight:400;font-style:normal;text-decoration:none;font-family:Arial;mso-generic-font-family:auto;mso-font-charset:134;mso-number-format:General;text-align:general;vertical-align:middle;border:.5ptsolidwindowtext;mso-background-source:auto;mso-pattern:auto;mso-protection:lockedvisible;white-space:nowrap;mso-rotate:0;} </style> </head><body> <tablex:strborder=0cellpadding=0cellspacing=0width=100%style="border-collapse:collapse">";
$footer="</table> </body></html>";
$exportString=$header.$string.$footer;

header("Cache-Control:public");
header("Pragma:public");
header("Content-type:Content-type:application/vnd.ms-excel");
header("Accept-Ranges:bytes");
header("Content-Disposition:attachment;filename=".$filename);
header("Content-length:".strlen($exportString));
echo$exportString;
exit;
}

⑵ PHP 斷點上傳超大文件,合並文件時內存溢出,怎麼處理

後台腳本佔用的內存是有個上限的,不是你想用多少就有多少的。

你把文件數據用追加的方式寫入文件,而不是把所有數據拼接為字元串再一次性寫入文件,就不會造成內存溢出了:

file_put_contents('文件路徑', '要寫入的數據', FILE_APPEND);

⑶ PHP合並數組

手冊里邊說了,下邊的下標會覆蓋上邊的,所以解決辦法就是將下標改一下再融合。解壓json文件,foreach循環,將下標改掉,或者直接放入一個新數組。將新數組和另外一個數組再array_merge。就可以了。望採納

熱點內容
懶人學編程 發布:2025-07-11 09:44:58 瀏覽:332
android命令行簽名 發布:2025-07-11 09:44:15 瀏覽:881
應用密碼怎麼取消密碼 發布:2025-07-11 09:28:33 瀏覽:797
pythonubuntumysql 發布:2025-07-11 09:23:47 瀏覽:531
硬碟屬於外部存儲器嗎 發布:2025-07-11 09:09:39 瀏覽:936
vs源碼查看 發布:2025-07-11 09:06:43 瀏覽:971
ip當前伺服器不可用是什麼意思 發布:2025-07-11 08:57:55 瀏覽:335
acfun如何緩存 發布:2025-07-11 08:48:12 瀏覽:3
我的世界伺服器tag 發布:2025-07-11 08:48:09 瀏覽:891
c語言設置 發布:2025-07-11 08:48:02 瀏覽:149