Getting XLSX Data cell by cell not all at once.

Topics: Developer Forum, Project Management Forum, User Forum
Mar 28, 2013 at 1:29 AM
This is probably a really stupid question. I have it running and shows the data on the page perfectly. Now, I need to take the data, cell by cell, and go through it to add it to the database. What I normally do for all other files, CSV and XLS is to take all the first names and string them together separated with a |. I then add all the first names to the FirstName field in the database. Then so on and so on with the rest of the user account info. My problem is that I can't seem to get just the first name cell, last name cell, etc. In a nutshell this is it...

$first = '';

start for or while statement to rifle through all the rows here
if($first == '') {
$first .= "". code for first name cell;
} else {
$first .= "|".code for first name cell;
end for or while statement to rifle through all the rows here

Then I add all the pipe delimited firsts to the database here with a simple INSERT query.

I just can't find anything to show me how to use PHPExcel to dynamically get the cell data.

Any help would be appreciated!!
Mar 28, 2013 at 12:45 PM
$objPHPExcel = PHPExcel_IOFactory::load('YourFile.xlsx');
$Col='C'; // column with the wanted data
$Row=2// first line with data
if($first == '') {
$first .= "". $F->getCell($Col.$Row)->getValue();
} else {
$first .= "|".$F->getCell($Col.$Row)->getValue();
There are some precautions to take if the values are not numbers or strings.
Mar 28, 2013 at 2:21 PM
Thanks sooo much!. Couple of tweaks and worked perfect. You're a real life saver!!

Thanks again.