0

I am reading data from a simple spreadsheet but getCell() returns all the data from a row and not just the indicated cell.

For example, I have a spreadsheet with random text in the first few cells.

   __A__ __B__ __C__ __D__ __E__
1 | aa  | bb  | cc  | dd  | ee  |
2 |_____|_____|_____|_____|_____|

I fire up PHPExcel and run this code:

$objReader = PHPExcel_IOFactory::createReaderForFile($file);
$objPHPExcel = $objReader->load($file);

$foo = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('A', 1)->getValue();
$bar = $objPHPExcel->getActiveSheet()->getCell('A1')->getValue();

The result for both $foo and $bar is one string of all the values:

aa   bb   cc   dd   ee

Why is this happening? Thanks.

PHP v5.3.13

PHPExcel v1.7.9

pnuts
  • 58,317
  • 11
  • 87
  • 139
user1449855
  • 1,195
  • 2
  • 10
  • 14
  • I had a similar question that I created a solution to cherry pick a single cell value you can view the answer [here](http://stackoverflow.com/a/22566639/1815624) – CrandellWS Mar 21 '14 at 18:32

3 Answers3

7

Check the file in a text editor. You normally only get this if the file is a csv file that doesnt use the default separator (,)

But the first argument to getCellByColumnAndRow() should be a numeric value for the column

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
1

Instead of passing 'A', 1 as arguments to getCellByColumnAndRow, try passing 0, 1 instead. That should correctly target the data you are looking for.

Zhube
  • 504
  • 2
  • 6
  • Unfortunately getCellByColumnAndRow(0,1)->getValue() returns the same result as getCellByColumnAndRow('A',1)->getValue() – user1449855 Oct 24 '13 at 22:04
  • What happens if you use PHPExcel_IOFactory::createReader( $inputFileType ) instead of PHPExcel_IOFactory::createReaderForFile( $file )? There's a list of supported types here: https://github.com/PHPOffice/PHPExcel/blob/develop/Documentation/Examples/Reader/exampleReader06.php – Zhube Oct 24 '13 at 23:34
0

I got a response from PHPExel's support team. The XLS document in question is from a third-party. When I ran PHPExcel_IOFactory::identify($file) the result was 'CSV'. Obviously the document has formatting issues. That does explain the problem, though, since the cells could not be properly interpreted.

The response: https://phpexcel.codeplex.com/discussions/463319#post1111959

user1449855
  • 1,195
  • 2
  • 10
  • 14