vr-shopxo-source/extend/phpexcel/PHPExcel.php

1154 lines
31 KiB
PHP
Raw Normal View History

2018-12-28 10:58:37 +00:00
<?php
/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
}
/**
* PHPExcel
*
* 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
* @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
{
/**
* Unique ID
*
* @var string
*/
private $uniqueID;
/**
* Document properties
*
* @var PHPExcel_DocumentProperties
*/
private $properties;
/**
* Document security
*
* @var PHPExcel_DocumentSecurity
*/
private $security;
/**
* Collection of Worksheet objects
*
* @var PHPExcel_Worksheet[]
*/
private $workSheetCollection = array();
/**
* Calculation Engine
*
* @var PHPExcel_Calculation
*/
private $calculationEngine;
/**
* Active sheet index
*
* @var integer
*/
private $activeSheetIndex = 0;
/**
* Named ranges
*
* @var PHPExcel_NamedRange[]
*/
private $namedRanges = array();
/**
* CellXf supervisor
*
* @var PHPExcel_Style
*/
private $cellXfSupervisor;
/**
* CellXf collection
*
* @var PHPExcel_Style[]
*/
private $cellXfCollection = array();
/**
* CellStyleXf collection
*
* @var PHPExcel_Style[]
*/
private $cellStyleXfCollection = array();
/**
* hasMacros : this workbook have macros ?
*
* @var bool
*/
private $hasMacros = false;
/**
* macrosCode : all macros code (the vbaProject.bin file, this include form, code, etc.), null if no macro
*
* @var binary
*/
private $macrosCode;
/**
* macrosCertificate : if macros are signed, contains vbaProjectSignature.bin file, null if not signed
*
* @var binary
*/
private $macrosCertificate;
/**
* ribbonXMLData : null if workbook is'nt Excel 2007 or not contain a customized UI
*
* @var null|string
*/
private $ribbonXMLData;
/**
* ribbonBinObjects : null if workbook is'nt Excel 2007 or not contain embedded objects (picture(s)) for Ribbon Elements
* ignored if $ribbonXMLData is null
*
* @var null|array
*/
private $ribbonBinObjects;
/**
* The workbook has macros ?
*
* @return boolean true if workbook has macros, false if not
*/
public function hasMacros()
{
return $this->hasMacros;
}
/**
* Define if a workbook has macros
*
* @param boolean $hasMacros true|false
*/
public function setHasMacros($hasMacros = false)
{
$this->hasMacros = (bool) $hasMacros;
}
/**
* Set the macros code
*
* @param string $MacrosCode string|null
*/
public function setMacrosCode($MacrosCode = null)
{
$this->macrosCode=$MacrosCode;
$this->setHasMacros(!is_null($MacrosCode));
}
/**
* Return the macros code
*
* @return string|null
*/
public function getMacrosCode()
{
return $this->macrosCode;
}
/**
* Set the macros certificate
*
* @param string|null $Certificate
*/
public function setMacrosCertificate($Certificate = null)
{
$this->macrosCertificate=$Certificate;
}
/**
* Is the project signed ?
*
* @return boolean true|false
*/
public function hasMacrosCertificate()
{
return !is_null($this->macrosCertificate);
}
/**
* Return the macros certificate
*
* @return string|null
*/
public function getMacrosCertificate()
{
return $this->macrosCertificate;
}
/**
* Remove all macros, certificate from spreadsheet
*
*/
public function discardMacros()
{
$this->hasMacros=false;
$this->macrosCode=null;
$this->macrosCertificate=null;
}
/**
* set ribbon XML data
*
*/
public function setRibbonXMLData($Target = null, $XMLData = null)
{
if (!is_null($Target) && !is_null($XMLData)) {
$this->ribbonXMLData = array('target' => $Target, 'data' => $XMLData);
} else {
$this->ribbonXMLData = null;
}
}
/**
* retrieve ribbon XML Data
*
* return string|null|array
*/
public function getRibbonXMLData($What = 'all') //we need some constants here...
{
$ReturnData = null;
$What = strtolower($What);
switch ($What){
case 'all':
$ReturnData = $this->ribbonXMLData;
break;
case 'target':
case 'data':
if (is_array($this->ribbonXMLData) && array_key_exists($What, $this->ribbonXMLData)) {
$ReturnData = $this->ribbonXMLData[$What];
}
break;
}
return $ReturnData;
}
/**
* store binaries ribbon objects (pictures)
*
*/
public function setRibbonBinObjects($BinObjectsNames = null, $BinObjectsData = null)
{
if (!is_null($BinObjectsNames) && !is_null($BinObjectsData)) {
$this->ribbonBinObjects = array('names' => $BinObjectsNames, 'data' => $BinObjectsData);
} else {
$this->ribbonBinObjects = null;
}
}
/**
* return the extension of a filename. Internal use for a array_map callback (php<5.3 don't like lambda function)
*
*/
private function getExtensionOnly($ThePath)
{
return pathinfo($ThePath, PATHINFO_EXTENSION);
}
/**
* retrieve Binaries Ribbon Objects
*
*/
public function getRibbonBinObjects($What = 'all')
{
$ReturnData = null;
$What = strtolower($What);
switch($What) {
case 'all':
return $this->ribbonBinObjects;
break;
case 'names':
case 'data':
if (is_array($this->ribbonBinObjects) && array_key_exists($What, $this->ribbonBinObjects)) {
$ReturnData=$this->ribbonBinObjects[$What];
}
break;
case 'types':
if (is_array($this->ribbonBinObjects) &&
array_key_exists('data', $this->ribbonBinObjects) && is_array($this->ribbonBinObjects['data'])) {
$tmpTypes=array_keys($this->ribbonBinObjects['data']);
$ReturnData = array_unique(array_map(array($this, 'getExtensionOnly'), $tmpTypes));
} else {
$ReturnData=array(); // the caller want an array... not null if empty
}
break;
}
return $ReturnData;
}
/**
* This workbook have a custom UI ?
*
* @return boolean true|false
*/
public function hasRibbon()
{
return !is_null($this->ribbonXMLData);
}
/**
* This workbook have additionnal object for the ribbon ?
*
* @return boolean true|false
*/
public function hasRibbonBinObjects()
{
return !is_null($this->ribbonBinObjects);
}
/**
* Check if a sheet with a specified code name already exists
*
* @param string $pSheetCodeName Name of the worksheet to check
* @return boolean
*/
public function sheetCodeNameExists($pSheetCodeName)
{
return ($this->getSheetByCodeName($pSheetCodeName) !== null);
}
/**
* Get sheet by code name. Warning : sheet don't have always a code name !
*
* @param string $pName Sheet name
* @return PHPExcel_Worksheet
*/
public function getSheetByCodeName($pName = '')
{
$worksheetCount = count($this->workSheetCollection);
for ($i = 0; $i < $worksheetCount; ++$i) {
if ($this->workSheetCollection[$i]->getCodeName() == $pName) {
return $this->workSheetCollection[$i];
}
}
return null;
}
/**
* Create a new PHPExcel with one Worksheet
*/
public function __construct()
{
$this->uniqueID = uniqid();
$this->calculationEngine = new PHPExcel_Calculation($this);
// Initialise worksheet collection and add one worksheet
$this->workSheetCollection = array();
$this->workSheetCollection[] = new PHPExcel_Worksheet($this);
$this->activeSheetIndex = 0;
// Create document properties
$this->properties = new PHPExcel_DocumentProperties();
// Create document security
$this->security = new PHPExcel_DocumentSecurity();
// Set named ranges
$this->namedRanges = array();
// Create the cellXf supervisor
$this->cellXfSupervisor = new PHPExcel_Style(true);
$this->cellXfSupervisor->bindParent($this);
// Create the default style
$this->addCellXf(new PHPExcel_Style);
$this->addCellStyleXf(new PHPExcel_Style);
}
/**
* Code to execute when this worksheet is unset()
*
*/
public function __destruct()
{
$this->calculationEngine = null;
$this->disconnectWorksheets();
}
/**
* Disconnect all worksheets from this PHPExcel workbook object,
* typically so that the PHPExcel object can be unset
*
*/
public function disconnectWorksheets()
{
$worksheet = null;
foreach ($this->workSheetCollection as $k => &$worksheet) {
$worksheet->disconnectCells();
$this->workSheetCollection[$k] = null;
}
unset($worksheet);
$this->workSheetCollection = array();
}
/**
* Return the calculation engine for this worksheet
*
* @return PHPExcel_Calculation
*/
public function getCalculationEngine()
{
return $this->calculationEngine;
} // function getCellCacheController()
/**
* Get properties
*
* @return PHPExcel_DocumentProperties
*/
public function getProperties()
{
return $this->properties;
}
/**
* Set properties
*
* @param PHPExcel_DocumentProperties $pValue
*/
public function setProperties(PHPExcel_DocumentProperties $pValue)
{
$this->properties = $pValue;
}
/**
* Get security
*
* @return PHPExcel_DocumentSecurity
*/
public function getSecurity()
{
return $this->security;
}
/**
* Set security
*
* @param PHPExcel_DocumentSecurity $pValue
*/
public function setSecurity(PHPExcel_DocumentSecurity $pValue)
{
$this->security = $pValue;
}
/**
* Get active sheet
*
* @return PHPExcel_Worksheet
*
* @throws PHPExcel_Exception
*/
public function getActiveSheet()
{
return $this->getSheet($this->activeSheetIndex);
}
/**
* Create sheet and add it to this workbook
*