<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Object representation of Microsoft Excel Spreadsheets
 *
 * PHP version 5
 *
 * @category   File Formats
 * @package    Spreadsheet_Excel
 * @author     David Sanders <shangxiao@php.net>
 * @copyright  Copyright &copy; 2007, David Sanders
 * @license    LGPL <http://www.gnu.org/licenses/lgpl.html>
 * @version    Release: @release@
 * @link       http://pear.php.net/package/Spreadsheet_Excel
 * @see        Spreadsheet_Excel_Reader
 */

/**
 * Exception for Spreadsheet_Excel
 *
 * PHP version 5
 *
 * @category   File Formats
 * @package    Spreadsheet_Excel
 * @author     David Sanders <shangxiao@php.net>
 * @copyright  Copyright &copy; 2007, David Sanders
 * @license    LGPL <http://www.gnu.org/licenses/lgpl.html>
 */

class Spreadsheet_Excel_Exception extends PEAR_Exception {}


/**
 * Storage for workbook worksheets, settings and formatting 
 *
 * PHP version 5
 *
 * @category   File Formats
 * @package    Spreadsheet_Excel
 * @author     David Sanders <shangxiao@php.net>
 * @copyright  Copyright &copy; 2007, David Sanders
 * @license    LGPL <http://www.gnu.org/licenses/lgpl.html>
 */

class Spreadsheet_Excel_Workbook
{
    const 
BEGIN_USER_DEFINED_FORMATS 164;
    const 
SECONDSINADAY              86400;
    const 
DATEMODE_WIN               0;
    const 
DATEMODE_MAC               1;
    const 
UTCOFFSETDAYS1904          24107;  // 1904-01-01
    
const UTCOFFSETDAYS1900          25569;  // Actually 1899-12-30
    
const ROW_LIMIT                  16384;  // These will change with Excel '07  **ACTUALLY SHOULD DOUBLE-CHECK**
    
const COL_LIMIT                  256;

    
/**
     * List of worksheets that form part of this workbook
     * 
     * @access public
     */
    
public $worksheets = array();

    
/**
     * SST - Shared String Table
     */
    
public $sst = array();

    
/**
     * Datemode - Epoch used to calculate dates
     * 
     * DATEMODE_WIN - Use 30 Dec 1899
     * DATEMODE_MAC - Use  1 Jan 1904
     */
    
public $datemode Spreadsheet_Excel_Workbook::DATEMODE_WIN;

    public 
$font_records = array();

    
/**
     * Holds the format records as defined in Section 6.45
     * 
     * The defaults here are built in and are not written (except for the money ones)
     * 
     * TODO: store default records.
     * 
     */
    
public $format_records = array(
        
0  => '#',
        
1  => '0',
        
2  => '0.00',
        
3  => '#,##0',
        
4  => '#,##0.00',
        
5  => '"$"#,##0_);("$"#,##0)',
        
6  => '"$"#,##0_);[Red]("$"#,##0)',
        
7  => '"$"#,##0.00_);("$"#,##0.00)',
        
8  => '"$"#,##0.00_);[Red]("$"#,##0.00)',
        
9  => '0%',
        
10 => '0.00%',
        
11 => '0.00E+00',
        
12 => '# ?/?',
        
13 => '# ??/??',
        
14 => 'D/M/YY',
        
15 => 'D-MMM-YY',
        
16 => 'D-MMM',
        
17 => 'MMM-YY',
        
18 => 'h:mm AM/PM',
        
19 => 'h:mm:ss AM/PM',
        
20 => 'h:mm',
        
21 => 'h:mm:ss',
        
22 => 'D/M/YY h:mm',
        
37 => '_(#,##0_);(#,##0)',
        
38 => '_(#,##0_);[Red](#,##0)',
        
39 => '_(#,##0.00_);(#,##0.00)',
        
40 => '_(#,##0.00_);[Red](#,##0.00)',
        
41 => '_("$"* #,##0_);_("$"* (#,##0);_("$"* "-"_);_(@_)',
        
42 => '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',
        
43 => '_("$"* #,##0.00_);_("$"* (#,##0.00);_("$"* "-"??_);_(@_)',
        
44 => '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',
        
45 => 'mm:ss',
        
46 => '[h]:mm:ss',
        
47 => 'mm:ss.0',
        
48 => '##0.0E+0',
        
49 => '@',
    );


    public 
$xf_records = array();

    public 
$style_records = array();

    public 
$active_worksheet;
    public 
$user;
    public 
$name;

/*
    public $number_formats = array(
        0  => array('type' => 'General', 'format' => )
    )
*/

    
public function is1904()
    {
        return 
$this->datemode == Spreadsheet_Excel::DATEMODE_MAC;
    }

    public function 
set1904($is_1904)
    {
        
$this->datemode = (int) $is_1904;
    }

    public function 
getWorksheet($worksheet_name null)
    {
        
//TODO if null get the active worksheet?
        
foreach ($this->worksheets as $worksheet) {
            if (
$worksheet->name === $worksheet_name) {
                return 
$worksheet;
            }
        }

        return new 
Spreadsheet_Excel_Workbook_Exception('Unknown worksheet');
    }

    public function 
getActiveWorksheet()
    {
    }

    public function 
toArray()
    {
    }
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * c-hanging-comment-ender-p: nil
 * End:
 */
?>