2

I want to read an excel file and save the data in database. I tried this in pure PHP by using Spreadsheet_Excel_Reader it is working fine, but when I am using the same code in Zend Framework 2 it is not working. Giving no data...

2 Answers 2

4

You could export the excel file to a csv file (for example data.csv) and then you can do it with an SQL query:

LOAD DATA INFILE 'c:/tmp/data.csv' 
INTO TABLE table_name
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

Check here for more information

Sign up to request clarification or add additional context in comments.

3 Comments

Is this procedure can be done zend doctrine and .xls file can be uploaded or not
@BeDeveloper Zend Framework 2 is a php framework so whatever you can do in php you can also do in ZF2. The question is more how much custom code you would have to write for this. You didn't talk about upload in your question at all, you should add such important information to your question next time (read also here). If those are files uploaded by clients and you will put the data it in your database you should be very careful since it is a perfect way for SQL injections.
Thanks alot i will be careful next time
1

If you are using composer to load zendframework, try to load phpExcel lib too using composer.php.

Run following command from command prompt

php composer.phar selfupdate

php composer.phar require phpoffice/phpexcel

Use in Controller

$excelObj = new \PHPExcel();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.