Login   Register  
PHP Classes

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


Class file image Download
require_once 'CompoundDocument.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)
'<h1>' $sheetName '</h1>';
'<table cellspacing = "0">';
    for (
$row 0$row $sheet->rows (); $row ++)
        for (
$col 0$col $sheet->cols (); $col ++)
            if (!isset (
$sheet->cells [$row][$col])) continue;
$cell $sheet->cells [$row][$col];
'<td style = "' $cell->style->css () . '" rowspan = "' $cell->rowspan '" colspan = "' $cell->colspan '">';
is_null ($cell->value) ? '&nbsp;' $cell->value;