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

源码截图

源码目录树

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

/**
 * PHPExcel_Writer_HTML
 *
 * 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_HTML
 * @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##
 */
class PHPExcel_Writer_HTML extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter
{
    /**
     * PHPExcel object
     *
     * @var PHPExcel
     */
    protected $phpExcel;

    /**
     * Sheet index to write
     *
     * @var int
     */
    private $sheetIndex = 0;

    /**
     * Images root
     *
     * @var string
     */
    private $imagesRoot = '.';

    /**
     * embed images, or link to images
     *
     * @var boolean
     */
    private $embedImages = false;

    /**
     * Use inline CSS?
     *
     * @var boolean
     */
    private $useInlineCss = false;

    /**
     * Array of CSS styles
     *
     * @var array
     */
    private $cssStyles;

    /**
     * Array of column widths in points
     *
     * @var array
     */
    private $columnWidths;

    /**
     * Default font
     *
     * @var PHPExcel_Style_Font
     */
    private $defaultFont;

    /**
     * Flag whether spans have been calculated
     *
     * @var boolean
     */
    private $spansAreCalculated = false;

    /**
     * Excel cells that should not be written as HTML cells
     *
     * @var array
     */
    private $isSpannedCell = array();

    /**
     * Excel cells that are upper-left corner in a cell merge
     *
     * @var array
     */
    private $isBaseCell = array();

    /**
     * Excel rows that should not be written as HTML rows
     *
     * @var array
     */
    private $isSpannedRow = array();

    /**
     * Is the current writer creating PDF?
     *
     * @var boolean
     */
    protected $isPdf = false;

    /**
     * Generate the Navigation block
     *
     * @var boolean
     */
    private $generateSheetNavigationBlock = true;

    /**
     * Create a new PHPExcel_Writer_HTML
     *
     * @param    PHPExcel    $phpExcel    PHPExcel object
     */
    public function __construct(PHPExcel $phpExcel)
    {
        $this->phpExcel = $phpExcel;
        $this->defaultFont = $this->phpExcel->getDefaultStyle()->getFont();
    }

    /**
     * Save PHPExcel to file
     *
     * @param    string        $pFilename
     * @throws    PHPExcel_Writer_Exception
     */
    public function save($pFilename = null)
    {
        // garbage collect
        $this->phpExcel->garbageCollect();

        $saveDebugLog = PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->getWriteDebugLog();
        PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog(false);
        $saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType();
        PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE);

        // Build CSS
        $this->buildCSS(!$this->useInlineCss);

        // Open file
        $fileHandle = fopen($pFilename, 'wb+');
        if ($fileHandle === false) {
            throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing.");
        }

        // Write headers
        fwrite($fileHandle, $this->generateHTMLHeader(!$this->useInlineCss));

        // Write navigation (tabs)
        if ((!$this->isPdf) && ($this->generateSheetNavigationBlock)) {
            fwrite($fileHandle, $this->generateNavigation());
        }

        // Write data
        fwrite($fileHandle, $this->generateSheetData());

        // Write footer
        fwrite($fileHandle, $this->generateHTMLFooter());

        // Close file
        fclose($fileHandle);

        PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType);
        PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog);
    }

    /**
     * Map VAlign
     *
     * @param    string        $vAlign        Vertical alignment
     * @return string
     */
    private function mapVAlign($vAlign)
    {
        switch ($vAlign) {
            case PHPExcel_Style_Alignment::VERTICAL_BOTTOM:
                return 'bottom';
            case PHPExcel_Style_Alignment::VERTICAL_TOP:
                return 'top';
            case PHPExcel_Style_Alignment::VERTICAL_CENTER:
            case PHPExcel_Style_Alignment::VERTICAL_JUSTIFY:
                return 'middle';
            default:
                return 'baseline';
        }
    }

    /**
     * Map HAlign
     *
     * @param    string        $hAlign        Horizontal alignment
     * @return string|false
     */
    private function mapHAlign($hAlign)
    {
        switch ($hAlign) {
            case PHPExcel_Style_Alignment::HORIZONTAL_GENERAL:
                return false;
            case PHPExcel_Style_Alignment::HORIZONTAL_LEFT:
                return 'left';
            case PHPExcel_Style_Alignment::HORIZONTAL_RIGHT:
                return 'right';
            case PHPExcel_Style_Alignment::HORIZONTAL_CENTER:
            case PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS:
                return 'center';
            case PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY:
                return 'justify';
            default:
                return false;
        }
    }

    /**
     * Map border style
     *
     * @param    int        $borderStyle        Sheet index
     * @return    string
     */
    private function mapBorderStyle($borderStyle)
    {
        switch ($borderStyle) {
            case PHPExcel_Style_Border::BORDER_NONE:
                return 'none';
            case PHPExcel_Style_Border::BORDER_DASHDOT:
                return '1px dashed';
            case PHPExcel_Style_Border::BORDER_DASHDOTDOT:
                return '1px dotted';
            case PHPExcel_Style_Border::BORDER_DASHED:
                return '1px dashed';
            case PHPExcel_Style_Border::BORDER_DOTTED:
                return '1px dotted';
            case PHPExcel_Style_Border::BORDER_DOUBLE:
                return '3px double';
            case PHPExcel_Style_Border::BORDER_HAIR:
                return '1px solid';
            case PHPExcel_Style_Border::BORDER_MEDIUM:
                return '2px solid';
            case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT:
                return '2px dashed';
            case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT:
                return '2px dotted';
            case PHPExcel_Style_Border::BORDER_MEDIUMDASHED:
                return '2px dashed';
            case PHPExcel_Style_Border::BORDER_SLANTDASHDOT:
                return '2px dashed';
            case PHPExcel_Style_Border::BORDER_THICK:
                return '3px solid';
            case PHPExcel_Style_Border::BORDER_THIN:
                return '1px solid';
            default:
                // map others to thin
                return '1px solid';
        }
    }

    /**
     * Get sheet index
     *
     * @return int
     */
    public function getSheetIndex()
    {
        return $this->sheetIndex;
    }

    /**
     * Set sheet index
     *
     * @param    int        $pValue        Sheet index
     * @return PHPExcel_Writer_HTML
     */
    public function setSheetIndex($pValue = 0)
    {
        $this->sheetIndex = $pValue;
        return $this;
    }

    /**
     * Get sheet index
     *
     * @return boolean
     */
    public function getGenerateSheetNavigationBlock()
    {
        return $this->generateSheetNavigationBlock;
    }

    /**
     * Set sheet index
     *
     * @param    boolean        $pValue        Flag indicating whether the sheet navigation block should be generated or not
     * @return PHPExcel_Writer_HTML
     */
    public function setGenerateSheetNavigationBlock($pValue = true)
    {
        $this->generateSheetNavigationBlock = (bool) $pValue;
        return $this;
    }

    /**
     * Write all sheets (resets sheetIndex to NULL)
     */
    public function writeAllSheets()
    {
        $this->sheetIndex = null;
        return $this;
    }

    /**
     * Generate HTML header
     *
     * @param    boolean        $pIncludeStyles        Include styles?
     * @return    string
     * @throws PHPExcel_Writer_Exception
     */
    public function generateHTMLHeader($pIncludeStyles = false)
    {
        // PHPExcel object known?
        if (is_null($this->phpExcel)) {
            throw new PHPExcel_Writer_Exception('Internal PHPExcel object not set to an instance of an object.');
        }

        // Construct HTML
        $properties = $this->phpExcel->getProperties();
        $html = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' . PHP_EOL;
        $html .= '<!-- Generated by PHPExcel - http://www.phpexcel.net -->' . PHP_EOL;
        $html .= '<html>' . PHP_EOL;
        $html .= '  <head>' . PHP_EOL;
        $html .= '      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">' . PHP_EOL;
        if ($properties->getTitle() > '') {
            $html .= '      <title>' . htmlspecialchars($properties->getTitle()) . '</title>' . PHP_EOL;
        }
        if ($properties->getCreator() > '') {
            $html .= '      <meta name="author" content="' . htmlspecialchars($properties->getCreator()) . '" />' . PHP_EOL;
        }
        if ($properties->getTitle() > '') {
            $html .= '      <meta name="title" content="' . htmlspecialchars($properties->getTitle()) . '" />' . PHP_EOL;
        }
        if ($properties->getDescription() > '') {
            $html .= '      <meta name="description" content="' . htmlspecialchars($properties->getDescription()) . '" />' . PHP_EOL;
        }
        if ($properties->getSubject() > '') {
            $html .= '      <meta name="subject" content="' . htmlspecialchars($properties->getSubject()) . '" />' . PHP_EOL;
        }
        if ($properties->getKeywords() > '') {
            $html .= '      <meta name="keywords" content="' . htmlspecialchars($properties->getKeywords()) . '" />' . PHP_EOL;
        }
        if ($properties->getCategory() > '') {
            $html .= '      <meta name="category" content="' . htmlspecialchars($properties->getCategory()) . '" />' . PHP_EOL;
        }
        if ($properties->getCompany() > '') {
            $html .= '      <meta name="company" content="' . htmlspecialchars($properties->getCompany()) . '" />' . PHP_EOL;
        }
        if ($properties->getManager() > '') {
            $html .= '      <meta name="manager" content="' . htmlspecialchars($properties->getManager()) . '" />' . PHP_EOL;
        }

        if ($pIncludeStyles) {
            $html .= $this->generateStyles(true);
        }

        $html .= '  </head>' . PHP_EOL;
        $html .= '' . PHP_EOL;
        $html .= '  <body>' . PHP_EOL;

        return $html;
    }

    /**
     * Generate sheet data
     *
     * @return    string
     * @throws PHPExcel_Writer_Exception
     */
    public function generateSheetData()
    {
        // PHPExcel object known?
        if (i...
完整源码文件,请先购买后再查看
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号