当前位置:首页 » 编程语言 » 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-12 13:11:42 浏览:811
取随机数php 发布:2025-07-12 12:58:16 浏览:840
如何配置组合音响 发布:2025-07-12 12:53:54 浏览:93
c语言幂计算 发布:2025-07-12 12:52:36 浏览:566
兔费WLAN密码多少 发布:2025-07-12 12:50:59 浏览:861
阿里云分布式存储 发布:2025-07-12 12:45:04 浏览:535
sql日志压缩 发布:2025-07-12 12:39:53 浏览:343
红点角标算法 发布:2025-07-12 12:11:16 浏览:844
开心消消乐服务器繁忙什么情况 发布:2025-07-12 12:11:14 浏览:239
数据库的封锁协议 发布:2025-07-12 12:10:35 浏览:725