There are several libraries out there for reading and writing MS Excel files. Here I note down my experiences with some of them.

Here is a list of libraries for working with Excel:




Reading a worksheets first column:

Be sure to configure the Package to import the headings as numeric:

'heading' => 'numeric',

Here is my sample code:

Excel::selectSheetsByIndex(1)->load($filename, function($sheet){

  $sheet->each(function($row) {





Reading a worksheets first column:

// open file
$data = new PHPExcelReader\SpreadsheetReader("excel.xls", false , 'UTF-8');
$rows = $data->rowcount();

// loop through all rows
for ($i=1; $i <= $rows; $i++) {
  // output first column
  echo $data->val($i, 1);


Export as HTML to Excel

Last but not least there is the HTML output. Here I found a nice article about:

PHP Header

header("Content-type: application/vnd-ms-excel; charset=utf-8;");
header("Content-Disposition: attachment; filename=export_".time().".xls");
header('Pragma: no-cache');

Example HTML Table

<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
td, th {
vertical-align: top;
text-align: left;

    <?php foreach ($header as $head) : ?>
    <th><?php echo $head; ?></th>
    <?php endforeach; ?>
    <?php foreach ($export_table as $item) : ?>
      <?php foreach ($keys as $key) : ?>
      <td><?php echo $item->$key; ?></td>
      <?php endforeach; ?>
    <?php endforeach; ?>



Categories: PHP

1 Comment

sarawoot · 16/11/2015 at 05:22

Thank youuuu ^^

Comments are closed.