get workbook line by line

Feb 26, 2010 at 1:21 PM

Hello

I would like to know how to read an excel sheet line by line ?

 

i read the doc but don't find any simple example for my needs:

- read a sheet,

- get the number of line

- for each line get the number of colum

- and then for each colum get the cell value

 

thanks by advance for any response...

 

rccc

Developer
Mar 19, 2010 at 2:09 AM

Here is an example:

<?php
$objPHPExcel = PHPExcel_IOFactory::load('test.xlsx');
$objWorksheet = $objPHPExcel->getActiveSheet();

$highestRow = $objWorksheet->getHighestRow(); // e.g. 10
$highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'

$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5

echo '<table>' . "\n";
for ($row = 1; $row <= $highestRow; ++$row) {
  echo '<tr>' . "\n";

  for ($col = 0; $col <= $highestColumnIndex; ++$col) {
    echo '<td>' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '</td>' . "\n";
  }

  echo '</tr>' . "\n";
}
echo '</table>' . "\n";
?>

Mar 19, 2010 at 8:05 AM
Thanks a lot :)

2010/3/19 koyama <notifications@codeplex.com>

From: koyama

Here is an example:

<?php
$objPHPExcel = PHPExcel_IOFactory::load('test.xlsx');
$objWorksheet = $objPHPExcel->getActiveSheet();

$highestRow = $objWorksheet->getHighestRow(); // e.g. 10
$highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F'

$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5

echo ' . "\n";
for ($row = 1; $row <= $highestRow; ++$row) {
  echo' . "\n";

  for ($col = 0; $col <= $highestColumnIndex; ++$col) {
    echo' . "\n";
  }

  echo' . "\n";
}
echo'
' . $objWorksheet->getCellByColumnAndRow($col, $row)->getValue() . '
'
. "\n"; ?>

Read the full discussion online.

To add a post to this discussion, reply to this email (PHPExcel@discussions.codeplex.com)

To start a new discussion for this project, email PHPExcel@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com