How to convert php xls to csv

藏色散人
Release: 2023-03-06 18:14:01
Original
2298 people have browsed it

php xls to csv method: first create a PHP sample file; then import "PHPExcel.php"; then list all xls files, check and submit to "$_POST"; finally use the getCsv method Just convert xls to csv.

How to convert php xls to csv

Recommended: "PHP Video Tutorial"

PHPExcle converts xls files to csv files

When importing excel into the database, the data may appear as "= a certain cell" (=A3), so first convert the .xls file to a .csv file, and then import the csv file into the database.

read()) !== false){ if(substr(strrchr($file, '.'), 1) == 'xls'){ $arr[] = $file; } } //把所有xls文件列出列表,勾选提交到这边$_POST foreach($_POST as $k => $item){ foreach($item as $v){ //只获取文件名 $file = str_replace('.xls','',$arr[$v]); getCsv($file); } } function getCsv($file){ $filename = "xls/".$file.".xls"; $objReader = new PHPExcel_Reader_Excel5(); //$objReader = PHPExcel_IOFactory::createReader('Excel5'); $objPHPExcel = $objReader->load($filename); //$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV'); $objWriter = new PHPExcel_Writer_CSV($objPHPExcel); $objWriter->save(str_replace('.xls', '.csv',$filename)); $root = "xls/".$file.".csv"; $newRoot='csv/'.$file.'.csv'; //新目录 copy($root,$newRoot); //拷贝到新目录 unlink($root); //删除旧目录下的文件 } ?>
Copy after login

The above is the detailed content of How to convert php xls to csv. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!