1

I've been debugging for hours, and cannot seem to figure out the problem.

    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    $objPHPExcelReader = $objReader->load($inputFileName);

    $objPHPExcelReader->setActiveSheetIndex(1);

    $sheetName = $objPHPExcelReader->getActiveSheet()->getTitle();

    echo "<strong>UPLOAD SUCCESSFUL!</strong><br /><br />";
    echo "Excel Path: $target_path<br /><br />";
    echo "$sheetName <br /><br />";

    $ytd_actual = $objPHPExcelReader->getSheet(1)->getCell('Z11')->getValue();
    $ytd_budget = $objPHPExcelReader->getActiveSheet()->getCell('AX11')->getValue();

Both values come back empty, notice I tried both methods

getSheet(1) -> to set a specific sheet

getActiveSheet() -> to use the active sheet (which I set in the beginning)

The sheetname outputs correctly, so I know the right sheet is selected.

Here is the funny part! If I use just the activesheet, without specifying setActiveSheet it works no problem to pull the data from the 1st sheet. Moment I set it to the 2nd sheet, it gives me issues.

If I even try and change

 $ytd_actual = $objPHPExcelReader->getSheet(1)->getCell('Z11')->getValue();

to...

 $ytd_actual = $objPHPExcelReader->getSheet(0)->getCell('Z11')->getValue();

It'll give me the value from the 1st sheet without issue. 2nd sheet, nothing...

What am I doing wrong? (rest assured the cell mapping is correct, there is values)

pnuts
  • 58,317
  • 11
  • 87
  • 139
JCastell
  • 1,135
  • 1
  • 10
  • 11
  • Starting to question if data corruption/formatting could be the cause? – JCastell Mar 10 '14 at 21:50
  • Do you have any "hidden" sheets? What does a call to `$objPHPExcelReader->getSheetNames()` return? This should give a list of sheet names indexed by their numeric index – Mark Baker Mar 10 '14 at 22:08
  • No hidden sheets. Array ( [0] => Sheet1 [1] => Sheet2 ) – JCastell Mar 11 '14 at 13:53
  • In that case, PHPExcel is broken and I'd better fix it PDQ.... I assume you're working with the latest 1.8.0 version – Mark Baker Mar 11 '14 at 14:01
  • I thought I was using the latest version 1.7.9, I started my project last week of Feb. Did not notice a new version released on March 2nd. I downloaded the latest version, it seems to behaving much better. In addition several CSV bugs have been fixed. Thanks for the great update, I'll let you know if I continue to have problems. – JCastell Mar 11 '14 at 17:23
  • Thanks for the update: version 1.8.0 is very new, less than 2 weeks since it was released, but should certainly fix a number of bugs that were present in the previous version – Mark Baker Mar 11 '14 at 17:27
  • Well my original issue still remains, but least it can pull more information than it did before. I would share the sheet, but it's full of clients financials. Side note, I already started working on a work-around that is almost working. What I am doing is taking the XLS, converting the sheets into a CSV (1 file each), then reading the CSV files. This seems to work fine so far... – JCastell Mar 11 '14 at 17:41
  • `$objPHPExcelReader->getSheet(1)->getCell('Z11')->getValue();` should still work, I'm trying to identify a reason why it won't (other than the hidden sheets that I mentioned as a possibility, but which the `$objPHPExcelReader->getSheetNames()` result eliminates). – Mark Baker Mar 11 '14 at 17:49
  • Could it be character encoding, or merged cells? It also has a frozen pane. It has over 50 columns, and 100 rows of financial data. Some columns hidden, some rows hidden. – JCastell Mar 12 '14 at 13:24
  • None of those should affect retrieving cell data from the worksheet itself... getCell() should still return hidden cells.... the only additional I can think of that could affect would be if Z11 was part of a merged cell range – Mark Baker Mar 12 '14 at 13:33
  • Nope all the values I attempt to retrieve are not merged (single cells). Tell you what, give me a few hours and I'll white label the excel document for you to download and try for yourself if you like. – JCastell Mar 12 '14 at 18:16

0 Answers0