PHP Classes
elePHPant
Icontem

File: simplexlsx.example2.php

Recommend this page to a friend!
  Classes of Sergey Shuchkin  >  Simple XLSX  >  simplexlsx.example2.php  >  Download  
File: simplexlsx.example2.php
Role: Example script
Content type: text/plain
Description: example: table output, switch worksheets
Class: Simple XLSX
Parse and retrieve data from Excel XLS files
Author: By
Last change: update examples
Date: 27 days ago
Size: 960 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/simplexlsx.class.php';

if (
$xlsx = SimpleXLSX::parse('countries_and_population.xlsx')) {

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

   
// output worsheet 1

   
list( $num_cols, $num_rows ) = $xlsx->dimension();

    echo
'<h1>Sheet 1</h1>';
    echo
'<table>';
    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

   
list( $num_cols, $num_rows ) = $xlsx->dimension( 2 );

    echo
'<h1>Sheet 2</h1>';
    echo
'<table>';
    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::parse_error();
}
?>