欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-03-30 20:19:53
复制代码 代码如下:

					
复制代码 代码如下:

<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>