点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 企业应用>> 新翔网络OA系统V1.0>> 源文件浏览
[商业版 200RMB] WebForm,下载次数:1 次 | 关键字: PHP MYSQL OA 办公 网络办公

源码截图

源码目录树

;
当前路径:Classes/PHPExcel/Writer/Excel5/Workbook.php
<?php

/**
 * PHPExcel_Writer_Excel5_Workbook
 *
 * Copyright (c) 2006 - 2015 PHPExcel
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPExcel
 * @package    PHPExcel_Writer_Excel5
 * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 * @version    ##VERSION##, ##DATE##
 */

// Original file header of PEAR::Spreadsheet_Excel_Writer_Workbook (used as the base for this class):
// -----------------------------------------------------------------------------------------
// /*
// *  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
// */
class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
{
    /**
     * Formula parser
     *
     * @var PHPExcel_Writer_Excel5_Parser
     */
    private $parser;

    /**
     * The BIFF file size for the workbook.
     * @var integer
     * @see calcSheetOffsets()
     */
    private $biffSize;

    /**
     * XF Writers
     * @var PHPExcel_Writer_Excel5_Xf[]
     */
    private $xfWriters = array();

    /**
     * Array containing the colour palette
     * @var array
     */
    private $palette;

    /**
     * The codepage indicates the text encoding used for strings
     * @var integer
     */
    private $codepage;

    /**
     * The country code used for localization
     * @var integer
     */
    private $countryCode;

    /**
     * Workbook
     * @var PHPExcel
     */
    private $phpExcel;

    /**
     * Fonts writers
     *
     * @var PHPExcel_Writer_Excel5_Font[]
     */
    private $fontWriters = array();

    /**
     * Added fonts. Maps from font's hash => index in workbook
     *
     * @var array
     */
    private $addedFonts = array();

    /**
     * Shared number formats
     *
     * @var array
     */
    private $numberFormats = array();

    /**
     * Added number formats. Maps from numberFormat's hash => index in workbook
     *
     * @var array
     */
    private $addedNumberFormats = array();

    /**
     * Sizes of the binary worksheet streams
     *
     * @var array
     */
    private $worksheetSizes = array();

    /**
     * Offsets of the binary worksheet streams relative to the start of the global workbook stream
     *
     * @var array
     */
    private $worksheetOffsets = array();

    /**
     * Total number of shared strings in workbook
     *
     * @var int
     */
    private $stringTotal;

    /**
     * Number of unique shared strings in workbook
     *
     * @var int
     */
    private $stringUnique;

    /**
     * Array of unique shared strings in workbook
     *
     * @var array
     */
    private $stringTable;

    /**
     * Color cache
     */
    private $colors;

    /**
     * Escher object corresponding to MSODRAWINGGROUP
     *
     * @var PHPExcel_Shared_Escher
     */
    private $escher;


    /**
     * Class constructor
     *
     * @param PHPExcel    $phpExcel        The Workbook
     * @param int        &$str_total        Total number of strings
     * @param int        &$str_unique    Total number of unique strings
     * @param array        &$str_table        String Table
     * @param array        &$colors        Colour Table
     * @param mixed        $parser            The formula parser created for the Workbook
     */
    public function __construct(PHPExcel $phpExcel = null, &$str_total, &$str_unique, &$str_table, &$colors, $parser)
    {
        // It needs to call its parent's constructor explicitly
        parent::__construct();

        $this->parser        = $parser;
        $this->biffSize     = 0;
        $this->palette      = array();
        $this->countryCode = -1;

        $this->stringTotal      = &$str_total;
        $this->stringUnique     = &$str_unique;
        $this->stringTable      = &$str_table;
        $this->colors        = &$colors;
        $this->setPaletteXl97();

        $this->phpExcel = $phpExcel;

        // set BIFFwriter limit for CONTINUE records
        //        $this->_limit = 8224;
        $this->codepage = 0x04B0;

        // Add empty sheets and Build color cache
        $countSheets = $phpExcel->getSheetCount();
        for ($i = 0; $i < $countSheets; ++$i) {
            $phpSheet = $phpExcel->getSheet($i);

            $this->parser->setExtSheet($phpSheet->getTitle(), $i);  // Register worksheet name with parser

            $supbook_index = 0x00;
            $ref = pack('vvv', $supbook_index, $i, $i);
            $this->parser->references[] = $ref;  // Register reference with parser

            // Sheet tab colors?
            if ($phpSheet->isTabColorSet()) {
                $this->addColor($phpSheet->getTabColor()->getRGB());
            }
        }

    }

    /**
     * Add a new XF writer
     *
     * @param PHPExcel_Style
     * @param boolean Is it a style XF?
     * @return int Index to XF record
     */
    public function addXfWriter($style, $isStyleXf = false)
    {
        $xfWriter = new PHPExcel_Writer_Excel5_Xf($style);
        $xfWriter->setIsStyleXf($isStyleXf);

        // Add the font if not already added
        $fontIndex = $this->addFont($style->getFont());

        // Assign the font index to the xf record
        $xfWriter->setFontIndex($fontIndex);

        // Background colors, best to treat these after the font so black will come after white in custom palette
        $xfWriter->setFgColor($this->addColor($style->getFill()->getStartColor()->getRGB()));
        $xfWriter->setBgColor($this->addColor($style->getFill()->getEndColor()->getRGB()));
        $xfWriter->setBottomColor($this->addColor($style->getBorders()->getBottom()->getColor()->getRGB()));
        $xfWriter->setTopColor($this->addColor($style->getBorders()->getTop()->getColor()->getRGB()));
        $xfWriter->setRightColor($this->addColor($style->getBorders()->getRight()->getColor()->getRGB()));
        $xfWriter->setLeftColor($this->addColor($style->getBorders()->getLeft()->getColor()->getRGB()));
        $xfWriter->setDiagColor($this->addColor($style->getBorders()->getDiagonal()->getColor()->getRGB()));

        // Add the number format if it is not a built-in one and not already added
        if ($style->getNumberFormat()->getBuiltInFormatCode() === false) {
            $numberFormatHashCode = $style->getNumberFormat()->getHashCode();

            if (isset($this->addedNumberFormats[$numberFormatHashCode])) {
                $numberFormatIndex = $this->addedNumberFormats[$numberFormatHashCode];
            } else {
                $numberFormatIndex = 164 + count($this->numberFormats);
                $this->numberFormats[$numberFormatIndex] = $style->getNumberFormat();
                $this->addedNumberFormats[$numberFormatHashCode] = $numberFormatIndex;
            }
        } else {
            $numberFormatIndex = (int) $style->getNumberFormat()->getBuiltInFormatCode();
        }

        // Assign the number format index to xf record
        $xfWriter->setNumberFormatIndex($numberFormatIndex);

        $this->xfWriters[] = $xfWriter;

        $xfIndex = count($this->xfWriters) - 1;
        return $xfIndex;
    }

    /**
     * Add a font to added fonts
     *
     * @param PHPExcel_Style_Font $font
     * @return int Index to FONT record
     */
    public function addFont(PHPExcel_Style_Font $font)
    {
        $fontHashCode = $font->getHashCode();
        if (isset($this->addedFonts[$fontHashCode])) {
            $fontIndex = $this->addedFonts[$fontHashCode];
        } else {
            $countFonts = count($this->fontWriters);
            $fontIndex = ($countFonts < 4) ? $countFonts : $countFonts + 1;

            $fontWriter = new PHPExcel_Writer_Excel5_Font($font);
            $fontWriter->setColorIndex($this->addColor($font->getColor()->getRGB()));
            $this->fontWriters[] = $fontWriter;

            $this->addedFonts[$fontHashCode] = $fontIndex;
        }
        return $fontIndex;
    }

    /**
     * Alter color palette adding a custom color
     *
     * @param string $rgb E.g. 'FF00AA'
     * @return int Color index
     */
    private function addColor($rgb)
    {
        if (!isset($this->colors[$rgb])) {
            if (count($this->colors) < 57) {
                // then we add a custom color altering the palette
                $colorIndex = 8 + count($this->colors);
                $this->palette[$colorIndex] =
                    array(
                        hexdec(substr($rgb, 0, 2)),
                        hexdec(substr($rgb...
完整源码文件,请先购买后再查看
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号