PHP处理excel cvs表格的方法实例介绍

编程学习 2021-07-05 09:49www.dzhlxh.cn编程入门
PHP处理excel cvs表格想必有很多朋友对此还是很陌生的吧,狼蚁网站SEO优化以实例为大家介绍下,感兴趣的朋友可以参考下哈,希望对你有所帮助
代码如下:

<PRE class=php name="code"><?php
$data = array();
//convert a cvs file to an array $data
$handle = fopen("data.csv","r");
while ($curline = fgetcsv($handle, 1000, ",")){
$tmp = array();
$num = count($curline);
for($c=0; $c < $num; $c++){
array_push($tmp, $curline[c]);
}
array_push($data, $tmp);
}
print_r($data);
fclose($handle);
//convert array $data back to a cvs file
$handle = fopen("result.csv","w");
foreach($data as $curline){
if(fputcsv($handle, $curline)==false){
die("cannot write CSV line");
}
}
fclose($handle);
?>
</PRE><BR>
<BR>
<PRE></PRE>

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板