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

前端之家收集整理的这篇文章主要介绍了PHP处理excel cvs表格的方法实例介绍前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="40255" class="copybut" id="copybut40255" onclick="doCopy('code40255')"> 代码如下:

<div class="codebody" id="code40255">
<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);
?>




 

猜你在找的PHP相关文章