PHP Classes
elePHPant
Icontem

File: examples/03-sheets.php

Recommend this page to a friend!
  Classes of Sergey Shuchkin  >  Simple XLSX  >  examples/03-sheets.php  >  Download  
File: examples/03-sheets.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple XLSX
Parse and retrieve data from Excel XLS files
Author: By
Last change: remove list( $x, $y ) for PHP 5 and 7 capabilities
Merge pull request #36 from tfve/master

use shared string in date cell
Date: 4 months ago
Size: 1,205 bytes
 

 

Contents

Class file image Download
<?php

ini_set
('error_reporting', E_ALL);
ini_set('display_errors', true);

require_once
__DIR__.'/../src/SimpleXLSX.php';

echo
'<h1>Read several sheets</h1>';
if (
$xlsx = SimpleXLSX::parse('countries_and_population.xlsx')) {

    echo
'<pre>'.print_r( $xlsx->sheetNames(), true ).'</pre>';

    echo
'<table cellpadding="10">
    <tr><td valign="top">'
;

   
// output worsheet 1

   
$dim = $xlsx->dimension();
   
$num_cols = $dim[0];
   
$num_rows = $dim[1];

    echo
'<h2>'.$xlsx->sheetName(0).'</h2>';
    echo
'<table border=1>';
    foreach (
$xlsx->rows( 1 ) as $r ) {
        echo
'<tr>';
        for (
$i = 0; $i < $num_cols; $i ++ ) {
            echo
'<td>' . ( ! empty( $r[ $i ] ) ? $r[ $i ] : '&nbsp;' ) . '</td>';
        }
        echo
'</tr>';
    }
    echo
'</table>';

    echo
'</td><td valign="top">';

   
// output worsheet 2

   
$dim = $xlsx->dimension( 2 );
   
$num_cols = $dim[0];
   
$num_rows = $dim[1];

    echo
'<h2>'.$xlsx->sheetName(1).'</h2>';
    echo
'<table border=1>';
    foreach (
$xlsx->rows( 2 ) as $r ) {
        echo
'<tr>';
        for (
$i = 0; $i < $num_cols; $i ++ ) {
            echo
'<td>' . ( ! empty( $r[ $i ] ) ? $r[ $i ] : '&nbsp;' ) . '</td>';
        }
        echo
'</tr>';
    }
    echo
'</table>';

    echo
'</td></tr></table>';
} else {
    echo
SimpleXLSX::parseError();
}