Valid XHTML 1.0 Transitional logo

Description

PHPEditTable is a class which mimics a simple spreadsheet behaviour. It handles cell formatting as well as math expressions based on cells' addresses parsing.

Features

Sample (and commented) code

<?php
    require('../class_EditTable.php');                         // read class file
    $e = new EditTable(13,8);                                  // instantiate class, set 13 columns and 8 rows 

    $e->setRow(0,'macro', 'header',                            // set row 0 properties
                 'background-color', '#dddddd',
                 'value', array('sizes','34','36','38','40','42','44','46','48','50','52','54','sum'));

    $e->setCol(0,'macro', 'header',                            // set column 0 properties
                 'background-color', '#dddddd',
                 'width', '140px',
                 'value', array('sizes','available','team 1','team 2','team 3','team 4','sum', 'difference'));

    $e->setCol(12,'macro', 'header',                           // set column 12 properties 
                  'background-color', '#dddddd');

    $e->setRange(12,1,12,6, 'formula', 'SUM(@B#:L#)');         // set formula for cells from (12,1) to (12,6)
                                                               // i.e. formula for cell (12,4) will be SUM(@B3:L3)
                                                               // addresses: A1 = (0,0), B1 = (1,0), A3 = (0,2)
    
    $e->setRow(array(1,6,7),'macro', 'header');                // set rows 1, 6 and 7 property
    $e->setRange(1,2,11,5, 'background-color', '#eeeeee');     // set range (1,2) to (11,5) background-color
    $e->setRange(0,6,0,7, 'color', 'blue');  
    $e->setRange(1,6,11,6,'formula','SUM(@#3:#6)');
    $e->setRange(1,7,12,7,'formula','@#2-@#7',
                          'onplus_color', 'yellow',            // set condition YELLOW color if value in cell > 0
                          'onminus_color', 'red',              // set condition RED color if value in cell < 0
                          'onzero_color', 'blue');             // set condition BLUE  color if value in cell == 0

    $e->setRow(1,'value', array('available',10,8,8,8,8,4,5,8,10,6,2),    // set contents of a row
                 'color', 'green');                                      // set color of a row
    
    // set validation rule (must validate to != 0 if to be submitted, when result is 0, validation is failed
    //                      and alert is shown)                    
    $e->setValidate('@B8==0&&@C8==0&&@D8==0&&@E8==0&&@F8==0&&@G8==0&&@H8==0&&@I8==0&&@J8==0&&@K8==0&&@L8==0',
                    'All differences shall be zero 0.');
    
    $e->setSheet('type','int');                                // all user input data must have only digits and '-'
    $e->userString = '<input type="hidden" name="sel" value="1">';   // add some user string to form

    $e->DrawSheet();                                                 // draw table
    $e->focus(1,2);                                                  // focus first editable cell
?>

Sample of above code (screenshot)

sample

Download

To download project files go to project page.

Syntax

To look at some syntax description go to syntax.

Contact

To contact with the author use this e-mail: glebows (at) chemeng.p.lodz.pl