I\'m working on a project where I need to import Excel data to my Symfony database. But the problem is that I don\'t know how to do that. I tried with ExcelBundle. The proje
If you can get your excel spreadsheet into CSV format, there is a really good package that can deal with it!
Have a look at this: http://csv.thephpleague.com/9.0/
Here's their example showing how easy it is to get your table into the DB
prepare(
"INSERT INTO users (firstname, lastname, email) VALUES (:firstname, :lastname, :email)"
);
$csv = Reader::createFromPath('/path/to/your/csv/file.csv')
->setHeaderOffset(0)
;
//by setting the header offset we index all records
//with the header record and remove it from the iteration
foreach ($csv as $record) {
//Do not forget to validate your data before inserting it in your database
$sth->bindValue(':firstname', $record['First Name'], PDO::PARAM_STR);
$sth->bindValue(':lastname', $record['Last Name'], PDO::PARAM_STR);
$sth->bindValue(':email', $record['E-mail'], PDO::PARAM_STR);
$sth->execute();
}
Give it a try!