I am using PHPExcel for the first time. I just wrote a basic code snippet to read one of my Excel files. I want to load the file, iterate through each row and process its contents. However, the function to load the file seems to dump its contents onto the screen.
My code snippet is this:
include 'lib/Classes/PHPExcel/IOFactory.php';
$dest = "uploads/";
$excel = "2012-12-STANDARD.xls";
$objPHPExcel = PHPExcel_IOFactory::load($dest.$excel);
On running this code, the data in the sheet has been echoed twice onto the screen. First, like a regular echo, and the second is a var_dump.
Here is a sample snippet of the screen output:
DOM ELEMENT: HTML DOM ELEMENT: BODY DOM ELEMENT: P START OF
PARAGRAPH: END OF PARAGRAPH: FLUSH CELL: A1 => Type ZipCode City
State County AreaCode CityType CityAliasAbbreviation CityAliasName
Latitude Longitude TimeZone Elevation CountyFIPS DayLightSaving
PreferredLastLineKey ClassificationCode MultiCounty StateFIPS
CityStateKey CityAliasCode PrimaryRecord CityMixedCase
CityAliasMixedCase StateANSI CountyANSI FacilityCode
CityDeliveryIndicator CarrierRouteRateSortation FinanceNumber
UniqueZIPName D 18540 ……array 1 =>
array
‘A’ => string ‘Type ZipCode City State County AreaCode CityType CityAliasAbbreviation CityAliasName Latitude Longitude TimeZone
Elevation CountyFIPS DayLightSaving PreferredLastLineKey
ClassificationCode MultiCounty StateFIPS CityStateKey CityAliasCode ……..’… (length=4573)
Am I doing something wrong here? Why would the load function echo the contents before accessing it?
That code is picking up on the HTML Reader, which still has some of my diagnostics in the code (mea culpa)… if you edit the file Classes/PHPExcel/Reader/HTML.php and comment out every line that contains an echo or a var_dump statement, then it should eliminate the problem.
Coincidence that it’s something I was actually working on last night.
Then you can also ask the person who provided you with the file to give you a proper .xls file in future, rather than one which has an extension of .xls but contains html markup rather than a properly formatted BIFF file.