PHP将CSV转换为XLS - phpExcel错误 [英] PHP Converting CSV to XLS - phpExcel error

查看:729
本文介绍了PHP将CSV转换为XLS - phpExcel错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个导出脚本,它会将数据从我的数据库导出为CSV或XLS文件。来自数据库的数据需要首先被操作。到目前为止,我有CSV文件工作,现在试图将此CSV字符串转换为XLS。我想使用 phpExcel ,但获得低于误差。

I have written an Export script that will export data from my database as a CSV or XLS file. The data from the database needs to be manipulated first. So far I have the CSV file working and am now trying to convert this CSV string to XLS. I want to use phpExcel but get the below error. Can anyone assist?

Fatal error:  Class 'PHPExcel_Exception' not found in /var/www/leanne/api/library/PHPExcel/Exception.php on line 36

导致错误的代码,所有工作正常,直到我添加XLS内容:

Code which is causing the error, all worked fine until I added the XLS stuff:

if($format == 'csv'){  
                //create and write to file for CSV
                if(file_exists($file_location . $filename)){
                    unlink($file_location . $filename);
                }
                $fh = fopen($file_location . $filename , 'a');
                fwrite($fh, $csv);
                fclose($fh);
            } else if($format == 'xls'){ 
                //wite to file for XLS
                include '../library/PHPExcel/IOFactory.php';

                $objReader = PHPExcel_IOFactory::createReader('CSV');
                $objReader->setDelimiter($separator); 
                $objReader->setEnclosure(" ");
                $objReader->setLineEnding($endrow);

                $objPHPExcel = $objReader->load($csv);
                $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
                $objWriter->save($file_location . $filename);               

            }



NB:csv是一个包含逗号分隔和双引号的字符串字段。行以'\\\
'结尾。

NB: csv is a string containing comma separated and double quoted fields from the database. The lines end with '\n'.

推荐答案

Ive再次下载文件并从头开始工作。一定是我做了一些愚蠢的事,对不起浪费你的时间,感谢你的帮助。

Ive downloaded the files again and started from scratch and its working. Must have been something silly I had done, sorry for wasting your time and thanks for the help.

这篇关于PHP将CSV转换为XLS - phpExcel错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆