⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workbook.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 4 页
字号:
<?php/**  Module written/ported by Xavier Noguer <xnoguer@rezebra.com>**  The majority of this is _NOT_ my code.  I simply ported it from the*  PERL Spreadsheet::WriteExcel module.**  The author of the Spreadsheet::WriteExcel module is John McNamara*  <jmcnamara@cpan.org>**  I _DO_ maintain this code, and John McNamara has nothing to do with the*  porting of this code to PHP.  Any questions directly related to this*  class library should be directed to me.**  License Information:**    Spreadsheet_Excel_Writer:  A library for generating Excel Spreadsheets*    Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com**    This library is free software; you can redistribute it and/or*    modify it under the terms of the GNU Lesser General Public*    License as published by the Free Software Foundation; either*    version 2.1 of the License, or (at your option) any later version.**    This library is distributed in the hope that it will be useful,*    but WITHOUT ANY WARRANTY; without even the implied warranty of*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU*    Lesser General Public License for more details.**    You should have received a copy of the GNU Lesser General Public*    License along with this library; if not, write to the Free Software*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Format.php');require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/BIFFwriter.php');require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Worksheet.php');require_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Parser.php');require_once(api_get_path(LIBRARY_PATH).'pear/OLE/PPS/Root.php');require_once(api_get_path(LIBRARY_PATH).'pear/OLE/PPS/File.php');/*** Class for generating Excel Spreadsheets** @author   Xavier Noguer <xnoguer@rezebra.com>* @category FileFormats* @package  Spreadsheet_Excel_Writer*/class Spreadsheet_Excel_Writer_Workbook extends Spreadsheet_Excel_Writer_BIFFwriter{    /**    * Filename for the Workbook    * @var string    */    var $_filename;    /**    * Formula parser    * @var object Parser    */    var $_parser;    /**    * Flag for 1904 date system (0 => base date is 1900, 1 => base date is 1904)    * @var integer    */    var $_1904;    /**    * The active worksheet of the workbook (0 indexed)    * @var integer    */    var $_activesheet;    /**    * 1st displayed worksheet in the workbook (0 indexed)    * @var integer    */    var $_firstsheet;    /**    * Number of workbook tabs selected    * @var integer    */    var $_selected;    /**    * Index for creating adding new formats to the workbook    * @var integer    */    var $_xf_index;    /**    * Flag for preventing close from being called twice.    * @var integer    * @see close()    */    var $_fileclosed;    /**    * The BIFF file size for the workbook.    * @var integer    * @see _calcSheetOffsets()    */    var $_biffsize;    /**    * The default sheetname for all sheets created.    * @var string    */    var $_sheetname;    /**    * The default XF format.    * @var object Format    */    var $_tmp_format;    /**    * Array containing references to all of this workbook's worksheets    * @var array    */    var $_worksheets;    /**    * Array of sheetnames for creating the EXTERNSHEET records    * @var array    */    var $_sheetnames;    /**    * Array containing references to all of this workbook's formats    * @var array    */    var $_formats;    /**    * Array containing the colour palette    * @var array    */    var $_palette;    /**    * The default format for URLs.    * @var object Format    */    var $_url_format;    /**    * The codepage indicates the text encoding used for strings    * @var integer    */    var $_codepage;    /**    * The country code used for localization    * @var integer    */    var $_country_code;    /**    * The temporary dir for storing the OLE file    * @var string    */    var $_tmp_dir;    /**    * number of bytes for sizeinfo of strings    * @var integer    */    var $_string_sizeinfo_size;    /**    * Class constructor    *    * @param string filename for storing the workbook. "-" for writing to stdout.    * @access public    */    function Spreadsheet_Excel_Writer_Workbook($filename)    {        // It needs to call its parent's constructor explicitly        $this->Spreadsheet_Excel_Writer_BIFFwriter();        $this->_filename         = $filename;        $this->_parser           =& new Spreadsheet_Excel_Writer_Parser($this->_byte_order, $this->_BIFF_version);        $this->_1904             = 0;        $this->_activesheet      = 0;        $this->_firstsheet       = 0;        $this->_selected         = 0;        $this->_xf_index         = 16; // 15 style XF's and 1 cell XF.        $this->_fileclosed       = 0;        $this->_biffsize         = 0;        $this->_sheetname        = 'Sheet';        $this->_tmp_format       =& new Spreadsheet_Excel_Writer_Format($this->_BIFF_version);        $this->_worksheets       = array();        $this->_sheetnames       = array();        $this->_formats          = array();        $this->_palette          = array();        $this->_codepage         = 0x04E4; // FIXME: should change for BIFF8        $this->_country_code     = -1;        $this->_string_sizeinfo  = 3;        // Add the default format for hyperlinks        $this->_url_format =& $this->addFormat(array('color' => 'blue', 'underline' => 1));        $this->_str_total       = 0;        $this->_str_unique      = 0;        $this->_str_table       = array();        $this->_setPaletteXl97();        $this->_tmp_dir         = '';    }    /**    * Calls finalization methods.    * This method should always be the last one to be called on every workbook    *    * @access public    * @return mixed true on success. PEAR_Error on failure    */    function close()    {        if ($this->_fileclosed) { // Prevent close() from being called twice.            return true;        }        $res = $this->_storeWorkbook();        if ($this->isError($res)) {            return $this->raiseError($res->getMessage());        }        $this->_fileclosed = 1;        return true;    }    /**    * An accessor for the _worksheets[] array    * Returns an array of the worksheet objects in a workbook    * It actually calls to worksheets()    *    * @access public    * @see worksheets()    * @return array    */    function sheets()    {        return $this->worksheets();    }    /**    * An accessor for the _worksheets[] array.    * Returns an array of the worksheet objects in a workbook    *    * @access public    * @return array    */    function worksheets()    {        return $this->_worksheets;    }    /**    * Sets the BIFF version.    * This method exists just to access experimental functionality    * from BIFF8. It will be deprecated !    * Only possible value is 8 (Excel 97/2000).    * For any other value it fails silently.    *    * @access public    * @param integer $version The BIFF version    */    function setVersion($version)    {        if ($version == 8) { // only accept version 8            $version = 0x0600;            $this->_BIFF_version = $version;            // change BIFFwriter limit for CONTINUE records            $this->_limit = 8228;            $this->_tmp_format->_BIFF_version = $version;            $this->_url_format->_BIFF_version = $version;            $this->_parser->_BIFF_version = $version;            $total_worksheets = count($this->_worksheets);            // change version for all worksheets too            for ($i = 0; $i < $total_worksheets; $i++) {                $this->_worksheets[$i]->_BIFF_version = $version;            }            $total_formats = count($this->_formats);            // change version for all formats too            for ($i = 0; $i < $total_formats; $i++) {                $this->_formats[$i]->_BIFF_version = $version;            }        }    }    /**    * Set the country identifier for the workbook    *    * @access public    * @param integer $code Is the international calling country code for the    *                      chosen country.    */    function setCountry($code)    {        $this->_country_code = $code;    }    /**    * Add a new worksheet to the Excel workbook.    * If no name is given the name of the worksheet will be Sheeti$i, with    * $i in [1..].    *    * @access public    * @param string $name the optional name of the worksheet    * @return mixed reference to a worksheet object on success, PEAR_Error    *               on failure    */    function &addWorksheet($name = '')    {        $index     = count($this->_worksheets);        $sheetname = $this->_sheetname;        if ($name == '') {            $name = $sheetname.($index+1);        }        // Check that sheetname is <= 31 chars (Excel limit before BIFF8).        if ($this->_BIFF_version != 0x0600)        {            if (strlen($name) > 31) {                return $this->raiseError("Sheetname $name must be <= 31 chars");            }        }        // Check that the worksheet name doesn't already exist: a fatal Excel error.        $total_worksheets = count($this->_worksheets);        for ($i = 0; $i < $total_worksheets; $i++) {            if ($this->_worksheets[$i]->getName() == $name) {                return $this->raiseError("Worksheet '$name' already exists");            }        }        $worksheet = new Spreadsheet_Excel_Writer_Worksheet($this->_BIFF_version,                                   $name, $index,                                   $this->_activesheet, $this->_firstsheet,                                   $this->_str_total, $this->_str_unique,                                   $this->_str_table, $this->_url_format,                                   $this->_parser);        $this->_worksheets[$index] = &$worksheet;    // Store ref for iterator        $this->_sheetnames[$index] = $name;          // Store EXTERNSHEET names        $this->_parser->setExtSheet($name, $index);  // Register worksheet name with parser        return $worksheet;    }    /**    * Add a new format to the Excel workbook.    * Also, pass any properties to the Format constructor.    *    * @access public    * @param array $properties array with properties for initializing the format.    * @return &Spreadsheet_Excel_Writer_Format reference to an Excel Format    */    function &addFormat($properties = array())    {        $format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version, $this->_xf_index, $properties);        $this->_xf_index += 1;        $this->_formats[] = &$format;        return $format;    }    /**     * Create new validator.     *     * @access public     * @return &Spreadsheet_Excel_Writer_Validator reference to a Validator     */    function &addValidator()    {        include_once(api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer/Validator.php');        /* FIXME: check for successful inclusion*/        $valid = new Spreadsheet_Excel_Writer_Validator($this->_parser);        return $valid;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -