<?php

require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/PPS.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/BIFFwriter.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/Format.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/Worksheet.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/OLE.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/File.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/Root.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/Parser.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/Workbook.php';
require_once LIBRARY_PATH . '/Goweb/Excel/Contrib/Writer.php';
/**
 * Goweb Sitemanager 5 Framework
 *
 * @version    5.0.0
 * @category   Goweb
 * @package    Goweb_Excel
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 */

/**
 * Classe de escrita de ficheiros Excel
 *
 * @version    5.0.0
 * @category   Goweb
 * @package    Goweb_Excel
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2009 (c) Goweb (http://www.goweb.pt)
 */

class Goweb_Excel extends Spreadsheet_Excel_Writer{
    public static function getEuro(){
        return chr(128);
    }
    
    /**
     * Convert Excel column number to numeric
     *
     * @param String $col
     * @return int
     */
    public static function getColumnNumber($col){
        $col = str_pad($col,2,'0',STR_PAD_LEFT);
        $i = ($col{0} == '0') ? 0 : (ord($col{0}) - 64) * 26;
        $i += ord($col{1}) - 64;
        return $i;
    }
    
    /**
     * Convert Excel numeric column to number 
     *
     * @param int $col
     * @return String
     */
    public static function getColumnName($col){
        // source: http://www.mrexcel.com/forum/showpost.php?s=e0903b5eaa96d4cb8524a0dffd62124f&p=505824&postcount=5
        $ConvertToLetter = "";
        $iAlpha = floor($col / 27);
        $iRemainder = $col - ($iAlpha * 26);
        If ($iRemainder > 26){
            $iRemainder = $iRemainder - 26;
            $iAlpha = $iAlpha + 1;
        }
        If ($iAlpha > 0){
            $ConvertToLetter = Chr($iAlpha + 64);
        }
        If ($iRemainder > 0){
            $ConvertToLetter = $ConvertToLetter . Chr($iRemainder + 64);
        }
        return $ConvertToLetter;
    }
}
if (!class_exists('PEAR')){
    class PEAR{
        /**
         * Tell whether a value is a PEAR error.
         *
         * @param   mixed $data   the value to test
         * @param   int   $code   if $data is an error object, return true
         *                        only if $code is a string and
         *                        $obj->getMessage() == $code or
         *                        $code is an integer and $obj->getCode() == $code
         * @access  public
         * @return  bool    true if parameter is an error
         */
        static function isError($data, $code = null)
        {
            if ($data instanceof PEAR_Error) {
                if (is_null($code)) {
                    return true;
                } elseif (is_string($code)) {
                    return $data->getMessage() == $code;
                } else {
                    return $data->getCode() == $code;
                }
            }
            return false;
        }


    }
}


/**
 * foram feitas 5 alterações:
 * - OLE.php
 *   - adicionado static às funções Asc2Ucs e LocalDate2OLE
 * - Workbook.php
 *   - função Spreadsheet_Excel_Writer_Workbook:
 *     - retirado o & de $this->_parser  e $this->_tmp_format
 * - em todos os ficheiros, foram comentados os require_once e colocados todos aqui
 * - Retiradas todas as end tags do PHP
 * - aplicado o patch disponivel em http://bugs.pear.php.net/bugs/bug.php?id=8303 e alterada a linha '$this->setColumn($col,$col,$this->col_widths[$col] +
$this->col_auto_width_padding[$col]);' para '$this->setColumn($col,$col,1.1 * ($this->col_widths[$col] +
$this->col_auto_width_padding[$col]));'
 * adicionada seguinte função, no ficheiro library/Goweb/Excel/Contrib/Worksheet.php: 
    function isError($data, $code = null)
    {
        if ($data instanceof PEAR_Error) {
            if (is_null($code)) {
                return true;
            } elseif (is_string($code)) {
                return $data->getMessage() == $code;
            } else {
                return $data->getCode() == $code;
            }
        }
        return false;
    }
 */
