Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ruslan V. Uss  >  Native Excel Reader  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Simple example, reads test.xls file
Class: Native Excel Reader
Parse and access binary Excel files in pure PHP
Author: By
Last change: now throws an error when can't read test.xls
Date: 4 years ago
Size: 917 bytes
 

Contents

Class file image Download
<?php
require_once 'CompoundDocument.inc.php';
require_once 
'BiffWorkbook.inc.php';

$fileName 'test.xls';

if (!
is_readable ($fileName)) die ('Cannot read ' $fileName);

$doc = new CompoundDocument ('utf-8');
$doc->parse (file_get_contents ($fileName));
$wb = new BiffWorkbook ($doc);
$wb->parse ();

foreach (
$wb->sheets as $sheetName => $sheet)
{
    echo 
'<h1>' $sheetName '</h1>';
    echo 
'<table cellspacing = "0">';
    for (
$row 0$row $sheet->rows (); $row ++)
    {
        echo 
'<tr>';
        for (
$col 0$col $sheet->cols (); $col ++)
        {
            if (!isset (
$sheet->cells [$row][$col])) continue;
            
$cell $sheet->cells [$row][$col];
            echo 
'<td style = "' $cell->style->css () . '" rowspan = "' $cell->rowspan '" colspan = "' $cell->colspan '">';
            echo 
is_null ($cell->value) ? '&nbsp;' $cell->value;
            echo 
'</td>';
        }
        echo 
'</tr>';
    }
    echo 
'</table>';
}
?>