86 changed files with 45057 additions and 0 deletions
File diff suppressed because it is too large
@ -0,0 +1,159 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | YFCMF [ WE CAN DO IT MORE SIMPLE ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: rainfer <81818832@qq.com> |
|||
// +---------------------------------------------------------------------- |
|||
class Alisms |
|||
{ |
|||
private $method = 'GET'; |
|||
private $api = 'https://sms.aliyuncs.com/'; //短信接口 |
|||
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z'; |
|||
private $config = [ |
|||
'Format' => 'json', |
|||
'Version' => '2016-09-27', |
|||
'SignatureMethod' => 'HMAC-SHA1', |
|||
'SignatureVersion' => "1.0", |
|||
'signName' => '', //管理控制台中配置的短信签名(状态必须是验证通过) |
|||
'TemplateCode' => '', |
|||
'AccessKeyId' => '', |
|||
'accessKeySecret' => '', |
|||
]; |
|||
|
|||
public function __construct($config = []) |
|||
{ |
|||
$this->config($config); |
|||
} |
|||
|
|||
/*读取配置*/ |
|||
public function config($config = []) |
|||
{ |
|||
/** |
|||
*发送短信 |
|||
*@AccessKeyId 阿里云申请的 Access Key ID |
|||
*@AccessKeySecret 阿里云申请的 Access Key Secret |
|||
*/ |
|||
if(config('think_sdk_sms.AccessKeyId')) $conf['AccessKeyId']=config('think_sdk_sms.AccessKeyId'); |
|||
if(config('think_sdk_sms.accessKeySecret')) $conf['accessKeySecret']=config('think_sdk_sms.accessKeySecret'); |
|||
if(config('think_sdk_sms.signName')) $conf['signName']=config('think_sdk_sms.signName'); |
|||
if(config('think_sdk_sms.TemplateCode')) $conf['TemplateCode']=config('think_sdk_sms.TemplateCode'); |
|||
$this->config = array_merge($this->config, $conf); |
|||
$this->config = array_merge($this->config, $config); |
|||
if(!config('think_sdk_sms.sms_open')){ |
|||
throw new Exception("短信系统尚未配置和未开启!"); |
|||
}else{ |
|||
return $this; |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
*发送短信 |
|||
*@mobile 目标手机号,多个手机号可以逗号分隔 |
|||
*@code 短信模板的模板CODE |
|||
*@ParamString 短信模板中的变量;,参数格式{“no”:”123456”}, 个人用户每个变量长度必须小于15个字符 |
|||
*/ |
|||
public function smsend($mobile,$ParamString,$code='') |
|||
{ |
|||
date_default_timezone_set("GMT"); |
|||
$dateTimeFormat = 'Y-m-d\TH:i:s\Z'; // ISO8601规范 |
|||
if(!$code){ |
|||
$code = $this->config['TemplateCode']; |
|||
} |
|||
$data = array( |
|||
'SignName' => $this->config['signName'], |
|||
'Format' => $this->config['Format'], |
|||
'Version' => $this->config['Version'], |
|||
'AccessKeyId' => $this->config['AccessKeyId'], |
|||
'SignatureVersion' => $this->config['SignatureVersion'], |
|||
'SignatureMethod' => $this->config['SignatureMethod'], |
|||
'SignatureNonce' => md5('estxiu.com').rand(100000,999999).uniqid(), //唯一随机数 |
|||
'Timestamp' => date($dateTimeFormat), |
|||
// 接口参数 |
|||
'Action' => 'SingleSendSms', |
|||
'TemplateCode' => $code, |
|||
'RecNum' => $mobile, |
|||
'ParamString' => $ParamString, |
|||
); |
|||
$data['Signature'] = $this->computeSignature($data,$this->config['accessKeySecret']); |
|||
//var_dump($data);exit; |
|||
$data = $this->http($this->api, $data, $this->method); |
|||
return $data; |
|||
} |
|||
|
|||
/** |
|||
* 发送HTTP请求方法,目前只支持CURL发送请求 |
|||
* @param string $url 请求URL |
|||
* @param array $params 请求参数 |
|||
* @param string $method 请求方法GET/POST |
|||
* @return array $data 响应数据 |
|||
*/ |
|||
protected function http($url, $params, $method = 'GET', $header = array(), $multi = false) |
|||
{ |
|||
$opts = array( |
|||
CURLOPT_TIMEOUT => 30, |
|||
CURLOPT_RETURNTRANSFER => 1, |
|||
CURLOPT_SSL_VERIFYPEER => false, |
|||
CURLOPT_SSL_VERIFYHOST => false, |
|||
CURLOPT_HTTPHEADER => $header |
|||
); |
|||
|
|||
/* 根据请求类型设置特定参数 */ |
|||
switch (strtoupper($method)) { |
|||
case 'GET': |
|||
$opts[CURLOPT_URL] = $url . '?' . http_build_query($params); |
|||
break; |
|||
case 'POST': |
|||
//判断是否传输文件 |
|||
$params = $multi ? $params : http_build_query($params); |
|||
$opts[CURLOPT_URL] = $url; |
|||
$opts[CURLOPT_POST] = 1; |
|||
$opts[CURLOPT_POSTFIELDS] = $params; |
|||
break; |
|||
default: |
|||
exception('不支持的请求方式!'); |
|||
} |
|||
|
|||
/* 初始化并执行curl请求 */ |
|||
$ch = curl_init(); |
|||
curl_setopt_array($ch, $opts); |
|||
$data = curl_exec($ch); |
|||
$error = curl_error($ch); |
|||
curl_close($ch); |
|||
if ($error) |
|||
exception('请求发生错误:' . $error); |
|||
return $data; |
|||
} |
|||
|
|||
//生成取短信签名 |
|||
private function computeSignature($parameters, $accessKeySecret) |
|||
{ |
|||
ksort($parameters); |
|||
$canonicalizedQueryString = ''; |
|||
foreach($parameters as $key => $value){ |
|||
$canonicalizedQueryString .= '&' . $this->percentEncode($key). '=' . $this->percentEncode($value); |
|||
} |
|||
$stringToSign = $this->method.'&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1)); |
|||
$signature = $this->signString($stringToSign, $accessKeySecret."&"); |
|||
return $signature; |
|||
} |
|||
private function percentEncode($str) |
|||
{ |
|||
$res = urlencode($str); |
|||
$res = preg_replace('/\+/', '%20', $res); |
|||
$res = preg_replace('/\*/', '%2A', $res); |
|||
$res = preg_replace('/%7E/', '~', $res); |
|||
return $res; |
|||
} |
|||
private function signString($source, $accessSecret) |
|||
{ |
|||
return base64_encode(hash_hmac('sha1', $source, $accessSecret, true)); |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
@ -0,0 +1,75 @@ |
|||
<?php |
|||
/* |
|||
* Barcode Encoder tool |
|||
* (C) 2008, Eric Stern |
|||
* http://www.firehed.net, http://www.eric-stern.com |
|||
* |
|||
* This code may be re-used or re-distributed in any application, commercial |
|||
* or non-commercial, free of charge provided that this credit remains intact. |
|||
* |
|||
*/ |
|||
|
|||
class Barcode { |
|||
protected static $code39 = array( |
|||
'0' => 'bwbwwwbbbwbbbwbw','1' => 'bbbwbwwwbwbwbbbw', |
|||
'2' => 'bwbbbwwwbwbwbbbw','3' => 'bbbwbbbwwwbwbwbw', |
|||
'4' => 'bwbwwwbbbwbwbbbw','5' => 'bbbwbwwwbbbwbwbw', |
|||
'6' => 'bwbbbwwwbbbwbwbw','7' => 'bwbwwwbwbbbwbbbw', |
|||
'8' => 'bbbwbwwwbwbbbwbw','9' => 'bwbbbwwwbwbbbwbw', |
|||
'A' => 'bbbwbwbwwwbwbbbw','B' => 'bwbbbwbwwwbwbbbw', |
|||
'C' => 'bbbwbbbwbwwwbwbw','D' => 'bwbwbbbwwwbwbbbw', |
|||
'E' => 'bbbwbwbbbwwwbwbw','F' => 'bwbbbwbbbwwwbwbw', |
|||
'G' => 'bwbwbwwwbbbwbbbw','H' => 'bbbwbwbwwwbbbwbw', |
|||
'I' => 'bwbbbwbwwwbbbwbw','J' => 'bwbwbbbwwwbbbwbw', |
|||
'K' => 'bbbwbwbwbwwwbbbw','L' => 'bwbbbwbwbwwwbbbw', |
|||
'M' => 'bbbwbbbwbwbwwwbw','N' => 'bwbwbbbwbwwwbbbw', |
|||
'O' => 'bbbwbwbbbwbwwwbw','P' => 'bwbbbwbbbwbwwwbw', |
|||
'Q' => 'bwbwbwbbbwwwbbbw','R' => 'bbbwbwbwbbbwwwbw', |
|||
'S' => 'bwbbbwbwbbbwwwbw','T' => 'bwbwbbbwbbbwwwbw', |
|||
'U' => 'bbbwwwbwbwbwbbbw','V' => 'bwwwbbbwbwbwbbbw', |
|||
'W' => 'bbbwwwbbbwbwbwbw','X' => 'bwwwbwbbbwbwbbbw', |
|||
'Y' => 'bbbwwwbwbbbwbwbw','Z' => 'bwwwbbbwbbbwbwbw', |
|||
'-' => 'bwwwbwbwbbbwbbbw','.' => 'bbbwwwbwbwbbbwbw', |
|||
' ' => 'bwwwbbbwbwbbbwbw','*' => 'bwwwbwbbbwbbbwbw', |
|||
'$' => 'bwwwbwwwbwwwbwbw','/' => 'bwwwbwwwbwbwwwbw', |
|||
'+' => 'bwwwbwbwwwbwwwbw','%' => 'bwbwwwbwwwbwwwbw'); |
|||
|
|||
|
|||
public static function code39($text,$filepath='',$height = 50, $widthScale = 1) { |
|||
if (!preg_match('/^[A-Z0-9-. $+\/%]+$/i', $text)) { |
|||
throw new Exception('Invalid text input.'); |
|||
} |
|||
$text = '*' . strtoupper($text) . '*'; // *UPPERCASE TEXT* |
|||
$length = strlen($text); |
|||
$barcode = imageCreate($length * 16 * $widthScale, $height); |
|||
$bg = imagecolorallocate($barcode, 255, 255, 0); //sets background to yellow |
|||
imagecolortransparent($barcode, $bg); //makes that yellow transparent |
|||
$black = imagecolorallocate($barcode, 0, 0, 0); //defines a color for black |
|||
$chars = str_split($text); |
|||
$colors = ''; |
|||
foreach ($chars as $char) { |
|||
$colors .= self::$code39[$char]; |
|||
} |
|||
|
|||
foreach (str_split($colors) as $i => $color) { |
|||
if ($color == 'b') { |
|||
// imageLine($barcode, $i, 0, $i, $height-13, $black); |
|||
imageFilledRectangle($barcode, $widthScale * $i, 0, $widthScale * ($i+1) -1 , $height-13, $black); |
|||
} |
|||
} |
|||
|
|||
//16px per bar-set, halved, minus 6px per char, halved (5*length) |
|||
// $textcenter = $length * 5 * $widthScale; |
|||
$textcenter = ($length * 8 * $widthScale) - ($length * 3); |
|||
|
|||
imageString($barcode, 2, $textcenter, $height-13, $text, $black); |
|||
if(!file_exists($filepath)){ |
|||
@touch($filepath); |
|||
} |
|||
//header('Content-type: image/png'); |
|||
imagePNG($barcode,$filepath); |
|||
//imageDestroy($barcode); |
|||
//exit; |
|||
} // function code39 |
|||
|
|||
} // class barcode |
|||
@ -0,0 +1,210 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn> |
|||
// +---------------------------------------------------------------------- |
|||
use think\Db; |
|||
|
|||
//数据导出模型 |
|||
class Database |
|||
{ |
|||
/** |
|||
* 文件指针 |
|||
* @var resource |
|||
*/ |
|||
private $fp; |
|||
|
|||
/** |
|||
* 备份文件信息 part - 卷号,name - 文件名 |
|||
* @var array |
|||
*/ |
|||
private $file; |
|||
|
|||
/** |
|||
* 当前打开文件大小 |
|||
* @var integer |
|||
*/ |
|||
private $size = 0; |
|||
|
|||
/** |
|||
* 备份配置 |
|||
* @var integer |
|||
*/ |
|||
private $config; |
|||
|
|||
/** |
|||
* 数据库备份构造方法 |
|||
* @param array $file 备份或还原的文件信息 |
|||
* @param array $config 备份配置信息 |
|||
* @param string $type 执行类型,export - 备份数据, import - 还原数据 |
|||
*/ |
|||
public function __construct($file, $config, $type = 'export') |
|||
{ |
|||
$this->file = $file; |
|||
$this->config = $config; |
|||
} |
|||
|
|||
/** |
|||
* 打开一个卷,用于写入数据 |
|||
* @param integer $size 写入数据的大小 |
|||
*/ |
|||
private function open($size = 0) |
|||
{ |
|||
if($this->fp){ |
|||
$this->size += $size; |
|||
if($this->size > $this->config['part']){ |
|||
$this->config['compress'] ? @gzclose($this->fp) : @fclose($this->fp); |
|||
$this->fp = null; |
|||
$this->file['part']++; |
|||
session('backup_file', $this->file); |
|||
$this->create(); |
|||
} |
|||
} else { |
|||
$backuppath = $this->config['path']; |
|||
$filename = "{$backuppath}{$this->file['name']}-{$this->file['part']}.sql"; |
|||
if($this->config['compress']){ |
|||
$filename = "{$filename}.gz"; |
|||
$this->fp = @gzopen($filename, "a{$this->config['level']}"); |
|||
} else { |
|||
$this->fp = @fopen($filename, 'a'); |
|||
} |
|||
$this->size = filesize($filename) + $size; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 写入初始数据 |
|||
* @return boolean true - 写入成功,false - 写入失败 |
|||
*/ |
|||
public function create() |
|||
{ |
|||
$sql = "-- -----------------------------\n"; |
|||
$sql .= "-- MySQL Data Transfer\n"; |
|||
$sql .= "--\n"; |
|||
$sql .= "-- Host : " . config('database.hostname') . "\n"; |
|||
$sql .= "-- Port : " . config('database.hostport') . "\n"; |
|||
$sql .= "-- Database : " . config('database.database') . "\n"; |
|||
$sql .= "--\n"; |
|||
$sql .= "-- Part : #{$this->file['part']}\n"; |
|||
$sql .= "-- Date : " . date("Y-m-d H:i:s") . "\n"; |
|||
$sql .= "-- -----------------------------\n\n"; |
|||
$sql .= "SET FOREIGN_KEY_CHECKS = 0;\n\n"; |
|||
return $this->write($sql); |
|||
} |
|||
|
|||
/** |
|||
* 写入SQL语句 |
|||
* @param string $sql 要写入的SQL语句 |
|||
* @return boolean true - 写入成功,false - 写入失败! |
|||
*/ |
|||
private function write($sql = '') |
|||
{ |
|||
$size = strlen($sql); |
|||
|
|||
//由于压缩原因,无法计算出压缩后的长度,这里假设压缩率为50%, |
|||
//一般情况压缩率都会高于50%; |
|||
$size = $this->config['compress'] ? $size / 2 : $size; |
|||
|
|||
$this->open($size); |
|||
return $this->config['compress'] ? @gzwrite($this->fp, $sql) : @fwrite($this->fp, $sql); |
|||
} |
|||
|
|||
/** |
|||
* 备份表结构 |
|||
* @param string $table 表名 |
|||
* @param integer $start 起始行数 |
|||
* @return boolean false - 备份失败 |
|||
*/ |
|||
public function backup($table = '', $start = 0) |
|||
{ |
|||
// 备份表结构 |
|||
if(0 == $start){ |
|||
$result = Db::query("SHOW CREATE TABLE `{$table}`"); |
|||
|
|||
$sql = "\n"; |
|||
$sql .= "-- -----------------------------\n"; |
|||
$sql .= "-- Table structure for `{$table}`\n"; |
|||
$sql .= "-- -----------------------------\n"; |
|||
$sql .= "DROP TABLE IF EXISTS `{$table}`;\n"; |
|||
$sql .= trim($result[0]['Create Table']) . ";\n\n"; |
|||
if(false === $this->write($sql)){ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
//数据总数 |
|||
$result = Db::query("SELECT COUNT(*) AS count FROM `{$table}`"); |
|||
$count = $result['0']['count']; |
|||
|
|||
//备份表数据 |
|||
if($count){ |
|||
//写入数据注释 |
|||
if(0 == $start){ |
|||
$sql = "-- -----------------------------\n"; |
|||
$sql .= "-- Records of `{$table}`\n"; |
|||
$sql .= "-- -----------------------------\n"; |
|||
$this->write($sql); |
|||
} |
|||
|
|||
//备份数据记录 |
|||
$result = Db::query("SELECT * FROM `{$table}` LIMIT {$start}, 1000"); |
|||
foreach ($result as $row) { |
|||
$row = array_map('addslashes', $row); |
|||
$sql = "INSERT INTO `{$table}` VALUES ('" . str_replace(array("\r","\n"),array('\r','\n'),implode("', '", $row)) . "');\n"; |
|||
if(false === $this->write($sql)){ |
|||
return false; |
|||
} |
|||
} |
|||
//还有更多数据 |
|||
if($count > $start + 1000){ |
|||
return array($start + 1000, $count); |
|||
} |
|||
} |
|||
//备份下一表 |
|||
return 0; |
|||
} |
|||
|
|||
public function import($start = 0) |
|||
{ |
|||
//还原数据 |
|||
if($this->config['compress']){ |
|||
$gz = gzopen($this->file[1], 'r'); |
|||
$size = 0; |
|||
} else { |
|||
$size = filesize($this->file[1]); |
|||
$gz = fopen($this->file[1], 'r'); |
|||
} |
|||
$sql = ''; |
|||
if($start){ |
|||
$this->config['compress'] ? gzseek($gz, $start) : fseek($gz, $start); |
|||
} |
|||
for($i = 0; $i < 1000; $i++){ |
|||
$sql .= $this->config['compress'] ? gzgets($gz) : fgets($gz); |
|||
if(preg_match('/.*;$/', trim($sql))){ |
|||
if(false !== Db::execute($sql)){ |
|||
$start += strlen($sql); |
|||
} else { |
|||
return false; |
|||
} |
|||
$sql = ''; |
|||
} elseif ($this->config['compress'] ? gzeof($gz) : feof($gz)) { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
return array($start, $size); |
|||
} |
|||
|
|||
/** |
|||
* 析构方法,用于关闭文件资源 |
|||
*/ |
|||
public function __destruct() |
|||
{ |
|||
$this->config['compress'] ? @gzclose($this->fp) : @fclose($this->fp); |
|||
} |
|||
} |
|||
@ -0,0 +1,107 @@ |
|||
<?php |
|||
|
|||
/* |
|||
全球 IPv4 地址归属地数据库(17MON.CN 版) |
|||
高春辉(pAUL gAO) <gaochunhui@gmail.com> |
|||
Build 20141009 版权所有 17MON.CN |
|||
(C) 2006 - 2014 保留所有权利 |
|||
请注意及时更新 IP 数据库版本 |
|||
数据问题请加 QQ 群: 346280296 |
|||
Code for PHP 5.3+ only |
|||
*/ |
|||
|
|||
class Ip |
|||
{ |
|||
private static $ip = NULL; |
|||
|
|||
private static $fp = NULL; |
|||
private static $offset = NULL; |
|||
private static $index = NULL; |
|||
|
|||
private static $cached = array(); |
|||
|
|||
public static function find($ip) |
|||
{ |
|||
if (empty($ip) === TRUE) |
|||
{ |
|||
return 'N/A'; |
|||
} |
|||
|
|||
$nip = gethostbyname($ip); |
|||
$ipdot = explode('.', $nip); |
|||
|
|||
if ($ipdot[0] < 0 || $ipdot[0] > 255 || count($ipdot) !== 4) |
|||
{ |
|||
return 'N/A'; |
|||
} |
|||
|
|||
if (isset(self::$cached[$nip]) === TRUE) |
|||
{ |
|||
return self::$cached[$nip]; |
|||
} |
|||
|
|||
if (self::$fp === NULL) |
|||
{ |
|||
self::init(); |
|||
} |
|||
|
|||
$nip2 = pack('N', ip2long($nip)); |
|||
|
|||
$tmp_offset = (int)$ipdot[0] * 4; |
|||
$start = unpack('Vlen', self::$index[$tmp_offset] . self::$index[$tmp_offset + 1] . self::$index[$tmp_offset + 2] . self::$index[$tmp_offset + 3]); |
|||
|
|||
$index_offset = $index_length = NULL; |
|||
$max_comp_len = self::$offset['len'] - 1024 - 4; |
|||
for ($start = $start['len'] * 8 + 1024; $start < $max_comp_len; $start += 8) |
|||
{ |
|||
if (self::$index{$start} . self::$index{$start + 1} . self::$index{$start + 2} . self::$index{$start + 3} >= $nip2) |
|||
{ |
|||
$index_offset = unpack('Vlen', self::$index{$start + 4} . self::$index{$start + 5} . self::$index{$start + 6} . "\x0"); |
|||
$index_length = unpack('Clen', self::$index{$start + 7}); |
|||
|
|||
break; |
|||
} |
|||
} |
|||
|
|||
if ($index_offset === NULL) |
|||
{ |
|||
return 'N/A'; |
|||
} |
|||
|
|||
fseek(self::$fp, self::$offset['len'] + $index_offset['len'] - 1024); |
|||
|
|||
self::$cached[$nip] = explode("\t", fread(self::$fp, $index_length['len'])); |
|||
|
|||
return self::$cached[$nip]; |
|||
} |
|||
|
|||
private static function init() |
|||
{ |
|||
if (self::$fp === NULL) |
|||
{ |
|||
self::$ip = new self(); |
|||
|
|||
self::$fp = fopen(__DIR__ . '/ip/17monipdb.dat', 'rb'); |
|||
if (self::$fp === FALSE) |
|||
{ |
|||
throw new Exception('Invalid 17monipdb.dat file!'); |
|||
} |
|||
|
|||
self::$offset = unpack('Nlen', fread(self::$fp, 4)); |
|||
if (self::$offset['len'] < 4) |
|||
{ |
|||
throw new Exception('Invalid 17monipdb.dat file!'); |
|||
} |
|||
|
|||
self::$index = fread(self::$fp, self::$offset['len'] - 4); |
|||
} |
|||
} |
|||
|
|||
public function __destruct() |
|||
{ |
|||
if (self::$fp !== NULL) |
|||
{ |
|||
fclose(self::$fp); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,81 @@ |
|||
<?php |
|||
|
|||
PHPExcel_Autoloader::register(); |
|||
// As we always try to run the autoloader before anything else, we can use it to do a few |
|||
// simple checks and initialisations |
|||
//PHPExcel_Shared_ZipStreamWrapper::register(); |
|||
// check mbstring.func_overload |
|||
if (ini_get('mbstring.func_overload') & 2) { |
|||
throw new PHPExcel_Exception('Multibyte function overloading in PHP must be disabled for string functions (2).'); |
|||
} |
|||
PHPExcel_Shared_String::buildCharacterSets(); |
|||
|
|||
/** |
|||
* 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_Autoloader |
|||
{ |
|||
/** |
|||
* Register the Autoloader with SPL |
|||
* |
|||
*/ |
|||
public static function register() |
|||
{ |
|||
if (function_exists('__autoload')) { |
|||
// Register any existing autoloader function with SPL, so we don't get any clashes |
|||
spl_autoload_register('__autoload'); |
|||
} |
|||
// Register ourselves with SPL |
|||
if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|||
return spl_autoload_register(array('PHPExcel_Autoloader', 'load'), true, true); |
|||
} else { |
|||
return spl_autoload_register(array('PHPExcel_Autoloader', 'load')); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Autoload a class identified by name |
|||
* |
|||
* @param string $pClassName Name of the object to load |
|||
*/ |
|||
public static function load($pClassName) |
|||
{ |
|||
if ((class_exists($pClassName, false)) || (strpos($pClassName, 'PHPExcel') !== 0)) { |
|||
// Either already loaded, or not a PHPExcel class request |
|||
return false; |
|||
} |
|||
|
|||
$pClassFilePath = PHPEXCEL_ROOT . |
|||
str_replace('_', DIRECTORY_SEPARATOR, $pClassName) . |
|||
'.php'; |
|||
|
|||
if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) { |
|||
// Can't load |
|||
return false; |
|||
} |
|||
|
|||
require($pClassFilePath); |
|||
} |
|||
} |
|||
@ -0,0 +1,231 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_CachedObjectStorageFactory |
|||
* |
|||
* 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_CachedObjectStorage |
|||
* @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_CachedObjectStorageFactory |
|||
{ |
|||
const cache_in_memory = 'Memory'; |
|||
const cache_in_memory_gzip = 'MemoryGZip'; |
|||
const cache_in_memory_serialized = 'MemorySerialized'; |
|||
const cache_igbinary = 'Igbinary'; |
|||
const cache_to_discISAM = 'DiscISAM'; |
|||
const cache_to_apc = 'APC'; |
|||
const cache_to_memcache = 'Memcache'; |
|||
const cache_to_phpTemp = 'PHPTemp'; |
|||
const cache_to_wincache = 'Wincache'; |
|||
const cache_to_sqlite = 'SQLite'; |
|||
const cache_to_sqlite3 = 'SQLite3'; |
|||
|
|||
/** |
|||
* Name of the method used for cell cacheing |
|||
* |
|||
* @var string |
|||
*/ |
|||
private static $cacheStorageMethod = null; |
|||
|
|||
/** |
|||
* Name of the class used for cell cacheing |
|||
* |
|||
* @var string |
|||
*/ |
|||
private static $cacheStorageClass = null; |
|||
|
|||
/** |
|||
* List of all possible cache storage methods |
|||
* |
|||
* @var string[] |
|||
*/ |
|||
private static $storageMethods = array( |
|||
self::cache_in_memory, |
|||
self::cache_in_memory_gzip, |
|||
self::cache_in_memory_serialized, |
|||
self::cache_igbinary, |
|||
self::cache_to_phpTemp, |
|||
self::cache_to_discISAM, |
|||
self::cache_to_apc, |
|||
self::cache_to_memcache, |
|||
self::cache_to_wincache, |
|||
self::cache_to_sqlite, |
|||
self::cache_to_sqlite3, |
|||
); |
|||
|
|||
/** |
|||
* Default arguments for each cache storage method |
|||
* |
|||
* @var array of mixed array |
|||
*/ |
|||
private static $storageMethodDefaultParameters = array( |
|||
self::cache_in_memory => array( |
|||
), |
|||
self::cache_in_memory_gzip => array( |
|||
), |
|||
self::cache_in_memory_serialized => array( |
|||
), |
|||
self::cache_igbinary => array( |
|||
), |
|||
self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB' |
|||
), |
|||
self::cache_to_discISAM => array( 'dir' => null |
|||
), |
|||
self::cache_to_apc => array( 'cacheTime' => 600 |
|||
), |
|||
self::cache_to_memcache => array( 'memcacheServer' => 'localhost', |
|||
'memcachePort' => 11211, |
|||
'cacheTime' => 600 |
|||
), |
|||
self::cache_to_wincache => array( 'cacheTime' => 600 |
|||
), |
|||
self::cache_to_sqlite => array( |
|||
), |
|||
self::cache_to_sqlite3 => array( |
|||
), |
|||
); |
|||
|
|||
/** |
|||
* Arguments for the active cache storage method |
|||
* |
|||
* @var array of mixed array |
|||
*/ |
|||
private static $storageMethodParameters = array(); |
|||
|
|||
/** |
|||
* Return the current cache storage method |
|||
* |
|||
* @return string|null |
|||
**/ |
|||
public static function getCacheStorageMethod() |
|||
{ |
|||
return self::$cacheStorageMethod; |
|||
} |
|||
|
|||
/** |
|||
* Return the current cache storage class |
|||
* |
|||
* @return PHPExcel_CachedObjectStorage_ICache|null |
|||
**/ |
|||
public static function getCacheStorageClass() |
|||
{ |
|||
return self::$cacheStorageClass; |
|||
} |
|||
|
|||
/** |
|||
* Return the list of all possible cache storage methods |
|||
* |
|||
* @return string[] |
|||
**/ |
|||
public static function getAllCacheStorageMethods() |
|||
{ |
|||
return self::$storageMethods; |
|||
} |
|||
|
|||
/** |
|||
* Return the list of all available cache storage methods |
|||
* |
|||
* @return string[] |
|||
**/ |
|||
public static function getCacheStorageMethods() |
|||
{ |
|||
$activeMethods = array(); |
|||
foreach (self::$storageMethods as $storageMethod) { |
|||
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod; |
|||
if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) { |
|||
$activeMethods[] = $storageMethod; |
|||
} |
|||
} |
|||
return $activeMethods; |
|||
} |
|||
|
|||
/** |
|||
* Identify the cache storage method to use |
|||
* |
|||
* @param string $method Name of the method to use for cell cacheing |
|||
* @param array of mixed $arguments Additional arguments to pass to the cell caching class |
|||
* when instantiating |
|||
* @return boolean |
|||
**/ |
|||
public static function initialize($method = self::cache_in_memory, $arguments = array()) |
|||
{ |
|||
if (!in_array($method, self::$storageMethods)) { |
|||
return false; |
|||
} |
|||
|
|||
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method; |
|||
if (!call_user_func(array( $cacheStorageClass, |
|||
'cacheMethodIsAvailable'))) { |
|||
return false; |
|||
} |
|||
|
|||
self::$storageMethodParameters[$method] = self::$storageMethodDefaultParameters[$method]; |
|||
foreach ($arguments as $k => $v) { |
|||
if (array_key_exists($k, self::$storageMethodParameters[$method])) { |
|||
self::$storageMethodParameters[$method][$k] = $v; |
|||
} |
|||
} |
|||
|
|||
if (self::$cacheStorageMethod === null) { |
|||
self::$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method; |
|||
self::$cacheStorageMethod = $method; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* Initialise the cache storage |
|||
* |
|||
* @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet |
|||
* @return PHPExcel_CachedObjectStorage_ICache |
|||
**/ |
|||
public static function getInstance(PHPExcel_Worksheet $parent) |
|||
{ |
|||
$cacheMethodIsAvailable = true; |
|||
if (self::$cacheStorageMethod === null) { |
|||
$cacheMethodIsAvailable = self::initialize(); |
|||
} |
|||
|
|||
if ($cacheMethodIsAvailable) { |
|||
$instance = new self::$cacheStorageClass( |
|||
$parent, |
|||
self::$storageMethodParameters[self::$cacheStorageMethod] |
|||
); |
|||
if ($instance !== null) { |
|||
return $instance; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Clear the cache storage |
|||
* |
|||
**/ |
|||
public static function finalize() |
|||
{ |
|||
self::$cacheStorageMethod = null; |
|||
self::$cacheStorageClass = null; |
|||
self::$storageMethodParameters = array(); |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,680 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Chart |
|||
* |
|||
* 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_Chart |
|||
* @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_Chart |
|||
{ |
|||
/** |
|||
* Chart Name |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $name = ''; |
|||
|
|||
/** |
|||
* Worksheet |
|||
* |
|||
* @var PHPExcel_Worksheet |
|||
*/ |
|||
private $worksheet; |
|||
|
|||
/** |
|||
* Chart Title |
|||
* |
|||
* @var PHPExcel_Chart_Title |
|||
*/ |
|||
private $title; |
|||
|
|||
/** |
|||
* Chart Legend |
|||
* |
|||
* @var PHPExcel_Chart_Legend |
|||
*/ |
|||
private $legend; |
|||
|
|||
/** |
|||
* X-Axis Label |
|||
* |
|||
* @var PHPExcel_Chart_Title |
|||
*/ |
|||
private $xAxisLabel; |
|||
|
|||
/** |
|||
* Y-Axis Label |
|||
* |
|||
* @var PHPExcel_Chart_Title |
|||
*/ |
|||
private $yAxisLabel; |
|||
|
|||
/** |
|||
* Chart Plot Area |
|||
* |
|||
* @var PHPExcel_Chart_PlotArea |
|||
*/ |
|||
private $plotArea; |
|||
|
|||
/** |
|||
* Plot Visible Only |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $plotVisibleOnly = true; |
|||
|
|||
/** |
|||
* Display Blanks as |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $displayBlanksAs = '0'; |
|||
|
|||
/** |
|||
* Chart Asix Y as |
|||
* |
|||
* @var PHPExcel_Chart_Axis |
|||
*/ |
|||
private $yAxis; |
|||
|
|||
/** |
|||
* Chart Asix X as |
|||
* |
|||
* @var PHPExcel_Chart_Axis |
|||
*/ |
|||
private $xAxis; |
|||
|
|||
/** |
|||
* Chart Major Gridlines as |
|||
* |
|||
* @var PHPExcel_Chart_GridLines |
|||
*/ |
|||
private $majorGridlines; |
|||
|
|||
/** |
|||
* Chart Minor Gridlines as |
|||
* |
|||
* @var PHPExcel_Chart_GridLines |
|||
*/ |
|||
private $minorGridlines; |
|||
|
|||
/** |
|||
* Top-Left Cell Position |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $topLeftCellRef = 'A1'; |
|||
|
|||
|
|||
/** |
|||
* Top-Left X-Offset |
|||
* |
|||
* @var integer |
|||
*/ |
|||
private $topLeftXOffset = 0; |
|||
|
|||
|
|||
/** |
|||
* Top-Left Y-Offset |
|||
* |
|||
* @var integer |
|||
*/ |
|||
private $topLeftYOffset = 0; |
|||
|
|||
|
|||
/** |
|||
* Bottom-Right Cell Position |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $bottomRightCellRef = 'A1'; |
|||
|
|||
|
|||
/** |
|||
* Bottom-Right X-Offset |
|||
* |
|||
* @var integer |
|||
*/ |
|||
private $bottomRightXOffset = 10; |
|||
|
|||
|
|||
/** |
|||
* Bottom-Right Y-Offset |
|||
* |
|||
* @var integer |
|||
*/ |
|||
private $bottomRightYOffset = 10; |
|||
|
|||
|
|||
/** |
|||
* Create a new PHPExcel_Chart |
|||
*/ |
|||
public function __construct($name, PHPExcel_Chart_Title $title = null, PHPExcel_Chart_Legend $legend = null, PHPExcel_Chart_PlotArea $plotArea = null, $plotVisibleOnly = true, $displayBlanksAs = '0', PHPExcel_Chart_Title $xAxisLabel = null, PHPExcel_Chart_Title $yAxisLabel = null, PHPExcel_Chart_Axis $xAxis = null, PHPExcel_Chart_Axis $yAxis = null, PHPExcel_Chart_GridLines $majorGridlines = null, PHPExcel_Chart_GridLines $minorGridlines = null) |
|||
{ |
|||
$this->name = $name; |
|||
$this->title = $title; |
|||
$this->legend = $legend; |
|||
$this->xAxisLabel = $xAxisLabel; |
|||
$this->yAxisLabel = $yAxisLabel; |
|||
$this->plotArea = $plotArea; |
|||
$this->plotVisibleOnly = $plotVisibleOnly; |
|||
$this->displayBlanksAs = $displayBlanksAs; |
|||
$this->xAxis = $xAxis; |
|||
$this->yAxis = $yAxis; |
|||
$this->majorGridlines = $majorGridlines; |
|||
$this->minorGridlines = $minorGridlines; |
|||
} |
|||
|
|||
/** |
|||
* Get Name |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getName() |
|||
{ |
|||
return $this->name; |
|||
} |
|||
|
|||
/** |
|||
* Get Worksheet |
|||
* |
|||
* @return PHPExcel_Worksheet |
|||
*/ |
|||
public function getWorksheet() |
|||
{ |
|||
return $this->worksheet; |
|||
} |
|||
|
|||
/** |
|||
* Set Worksheet |
|||
* |
|||
* @param PHPExcel_Worksheet $pValue |
|||
* @throws PHPExcel_Chart_Exception |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setWorksheet(PHPExcel_Worksheet $pValue = null) |
|||
{ |
|||
$this->worksheet = $pValue; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Title |
|||
* |
|||
* @return PHPExcel_Chart_Title |
|||
*/ |
|||
public function getTitle() |
|||
{ |
|||
return $this->title; |
|||
} |
|||
|
|||
/** |
|||
* Set Title |
|||
* |
|||
* @param PHPExcel_Chart_Title $title |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setTitle(PHPExcel_Chart_Title $title) |
|||
{ |
|||
$this->title = $title; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Legend |
|||
* |
|||
* @return PHPExcel_Chart_Legend |
|||
*/ |
|||
public function getLegend() |
|||
{ |
|||
return $this->legend; |
|||
} |
|||
|
|||
/** |
|||
* Set Legend |
|||
* |
|||
* @param PHPExcel_Chart_Legend $legend |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setLegend(PHPExcel_Chart_Legend $legend) |
|||
{ |
|||
$this->legend = $legend; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get X-Axis Label |
|||
* |
|||
* @return PHPExcel_Chart_Title |
|||
*/ |
|||
public function getXAxisLabel() |
|||
{ |
|||
return $this->xAxisLabel; |
|||
} |
|||
|
|||
/** |
|||
* Set X-Axis Label |
|||
* |
|||
* @param PHPExcel_Chart_Title $label |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setXAxisLabel(PHPExcel_Chart_Title $label) |
|||
{ |
|||
$this->xAxisLabel = $label; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Y-Axis Label |
|||
* |
|||
* @return PHPExcel_Chart_Title |
|||
*/ |
|||
public function getYAxisLabel() |
|||
{ |
|||
return $this->yAxisLabel; |
|||
} |
|||
|
|||
/** |
|||
* Set Y-Axis Label |
|||
* |
|||
* @param PHPExcel_Chart_Title $label |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setYAxisLabel(PHPExcel_Chart_Title $label) |
|||
{ |
|||
$this->yAxisLabel = $label; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Plot Area |
|||
* |
|||
* @return PHPExcel_Chart_PlotArea |
|||
*/ |
|||
public function getPlotArea() |
|||
{ |
|||
return $this->plotArea; |
|||
} |
|||
|
|||
/** |
|||
* Get Plot Visible Only |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getPlotVisibleOnly() |
|||
{ |
|||
return $this->plotVisibleOnly; |
|||
} |
|||
|
|||
/** |
|||
* Set Plot Visible Only |
|||
* |
|||
* @param boolean $plotVisibleOnly |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setPlotVisibleOnly($plotVisibleOnly = true) |
|||
{ |
|||
$this->plotVisibleOnly = $plotVisibleOnly; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Display Blanks as |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getDisplayBlanksAs() |
|||
{ |
|||
return $this->displayBlanksAs; |
|||
} |
|||
|
|||
/** |
|||
* Set Display Blanks as |
|||
* |
|||
* @param string $displayBlanksAs |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setDisplayBlanksAs($displayBlanksAs = '0') |
|||
{ |
|||
$this->displayBlanksAs = $displayBlanksAs; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Get yAxis |
|||
* |
|||
* @return PHPExcel_Chart_Axis |
|||
*/ |
|||
public function getChartAxisY() |
|||
{ |
|||
if ($this->yAxis !== null) { |
|||
return $this->yAxis; |
|||
} |
|||
|
|||
return new PHPExcel_Chart_Axis(); |
|||
} |
|||
|
|||
/** |
|||
* Get xAxis |
|||
* |
|||
* @return PHPExcel_Chart_Axis |
|||
*/ |
|||
public function getChartAxisX() |
|||
{ |
|||
if ($this->xAxis !== null) { |
|||
return $this->xAxis; |
|||
} |
|||
|
|||
return new PHPExcel_Chart_Axis(); |
|||
} |
|||
|
|||
/** |
|||
* Get Major Gridlines |
|||
* |
|||
* @return PHPExcel_Chart_GridLines |
|||
*/ |
|||
public function getMajorGridlines() |
|||
{ |
|||
if ($this->majorGridlines !== null) { |
|||
return $this->majorGridlines; |
|||
} |
|||
|
|||
return new PHPExcel_Chart_GridLines(); |
|||
} |
|||
|
|||
/** |
|||
* Get Minor Gridlines |
|||
* |
|||
* @return PHPExcel_Chart_GridLines |
|||
*/ |
|||
public function getMinorGridlines() |
|||
{ |
|||
if ($this->minorGridlines !== null) { |
|||
return $this->minorGridlines; |
|||
} |
|||
|
|||
return new PHPExcel_Chart_GridLines(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Set the Top Left position for the chart |
|||
* |
|||
* @param string $cell |
|||
* @param integer $xOffset |
|||
* @param integer $yOffset |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setTopLeftPosition($cell, $xOffset = null, $yOffset = null) |
|||
{ |
|||
$this->topLeftCellRef = $cell; |
|||
if (!is_null($xOffset)) { |
|||
$this->setTopLeftXOffset($xOffset); |
|||
} |
|||
if (!is_null($yOffset)) { |
|||
$this->setTopLeftYOffset($yOffset); |
|||
} |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the top left position of the chart |
|||
* |
|||
* @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell |
|||
*/ |
|||
public function getTopLeftPosition() |
|||
{ |
|||
return array( |
|||
'cell' => $this->topLeftCellRef, |
|||
'xOffset' => $this->topLeftXOffset, |
|||
'yOffset' => $this->topLeftYOffset |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Get the cell address where the top left of the chart is fixed |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getTopLeftCell() |
|||
{ |
|||
return $this->topLeftCellRef; |
|||
} |
|||
|
|||
/** |
|||
* Set the Top Left cell position for the chart |
|||
* |
|||
* @param string $cell |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setTopLeftCell($cell) |
|||
{ |
|||
$this->topLeftCellRef = $cell; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Set the offset position within the Top Left cell for the chart |
|||
* |
|||
* @param integer $xOffset |
|||
* @param integer $yOffset |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setTopLeftOffset($xOffset = null, $yOffset = null) |
|||
{ |
|||
if (!is_null($xOffset)) { |
|||
$this->setTopLeftXOffset($xOffset); |
|||
} |
|||
if (!is_null($yOffset)) { |
|||
$this->setTopLeftYOffset($yOffset); |
|||
} |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the offset position within the Top Left cell for the chart |
|||
* |
|||
* @return integer[] |
|||
*/ |
|||
public function getTopLeftOffset() |
|||
{ |
|||
return array( |
|||
'X' => $this->topLeftXOffset, |
|||
'Y' => $this->topLeftYOffset |
|||
); |
|||
} |
|||
|
|||
public function setTopLeftXOffset($xOffset) |
|||
{ |
|||
$this->topLeftXOffset = $xOffset; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
public function getTopLeftXOffset() |
|||
{ |
|||
return $this->topLeftXOffset; |
|||
} |
|||
|
|||
public function setTopLeftYOffset($yOffset) |
|||
{ |
|||
$this->topLeftYOffset = $yOffset; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
public function getTopLeftYOffset() |
|||
{ |
|||
return $this->topLeftYOffset; |
|||
} |
|||
|
|||
/** |
|||
* Set the Bottom Right position of the chart |
|||
* |
|||
* @param string $cell |
|||
* @param integer $xOffset |
|||
* @param integer $yOffset |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setBottomRightPosition($cell, $xOffset = null, $yOffset = null) |
|||
{ |
|||
$this->bottomRightCellRef = $cell; |
|||
if (!is_null($xOffset)) { |
|||
$this->setBottomRightXOffset($xOffset); |
|||
} |
|||
if (!is_null($yOffset)) { |
|||
$this->setBottomRightYOffset($yOffset); |
|||
} |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the bottom right position of the chart |
|||
* |
|||
* @return array an associative array containing the cell address, X-Offset and Y-Offset from the top left of that cell |
|||
*/ |
|||
public function getBottomRightPosition() |
|||
{ |
|||
return array( |
|||
'cell' => $this->bottomRightCellRef, |
|||
'xOffset' => $this->bottomRightXOffset, |
|||
'yOffset' => $this->bottomRightYOffset |
|||
); |
|||
} |
|||
|
|||
public function setBottomRightCell($cell) |
|||
{ |
|||
$this->bottomRightCellRef = $cell; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the cell address where the bottom right of the chart is fixed |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getBottomRightCell() |
|||
{ |
|||
return $this->bottomRightCellRef; |
|||
} |
|||
|
|||
/** |
|||
* Set the offset position within the Bottom Right cell for the chart |
|||
* |
|||
* @param integer $xOffset |
|||
* @param integer $yOffset |
|||
* @return PHPExcel_Chart |
|||
*/ |
|||
public function setBottomRightOffset($xOffset = null, $yOffset = null) |
|||
{ |
|||
if (!is_null($xOffset)) { |
|||
$this->setBottomRightXOffset($xOffset); |
|||
} |
|||
if (!is_null($yOffset)) { |
|||
$this->setBottomRightYOffset($yOffset); |
|||
} |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get the offset position within the Bottom Right cell for the chart |
|||
* |
|||
* @return integer[] |
|||
*/ |
|||
public function getBottomRightOffset() |
|||
{ |
|||
return array( |
|||
'X' => $this->bottomRightXOffset, |
|||
'Y' => $this->bottomRightYOffset |
|||
); |
|||
} |
|||
|
|||
public function setBottomRightXOffset($xOffset) |
|||
{ |
|||
$this->bottomRightXOffset = $xOffset; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
public function getBottomRightXOffset() |
|||
{ |
|||
return $this->bottomRightXOffset; |
|||
} |
|||
|
|||
public function setBottomRightYOffset($yOffset) |
|||
{ |
|||
$this->bottomRightYOffset = $yOffset; |
|||
|
|||
return $this; |
|||
} |
|||
|
|||
public function getBottomRightYOffset() |
|||
{ |
|||
return $this->bottomRightYOffset; |
|||
} |
|||
|
|||
|
|||
public function refresh() |
|||
{ |
|||
if ($this->worksheet !== null) { |
|||
$this->plotArea->refresh($this->worksheet); |
|||
} |
|||
} |
|||
|
|||
public function render($outputDestination = null) |
|||
{ |
|||
$libraryName = PHPExcel_Settings::getChartRendererName(); |
|||
if (is_null($libraryName)) { |
|||
return false; |
|||
} |
|||
// Ensure that data series values are up-to-date before we render |
|||
$this->refresh(); |
|||
|
|||
$libraryPath = PHPExcel_Settings::getChartRendererPath(); |
|||
$includePath = str_replace('\\', '/', get_include_path()); |
|||
$rendererPath = str_replace('\\', '/', $libraryPath); |
|||
if (strpos($rendererPath, $includePath) === false) { |
|||
set_include_path(get_include_path() . PATH_SEPARATOR . $libraryPath); |
|||
} |
|||
|
|||
$rendererName = 'PHPExcel_Chart_Renderer_'.$libraryName; |
|||
$renderer = new $rendererName($this); |
|||
|
|||
if ($outputDestination == 'php://output') { |
|||
$outputDestination = null; |
|||
} |
|||
return $renderer->render($outputDestination); |
|||
} |
|||
} |
|||
@ -0,0 +1,338 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Comment |
|||
* |
|||
* 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_Comment implements PHPExcel_IComparable |
|||
{ |
|||
/** |
|||
* Author |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $author; |
|||
|
|||
/** |
|||
* Rich text comment |
|||
* |
|||
* @var PHPExcel_RichText |
|||
*/ |
|||
private $text; |
|||
|
|||
/** |
|||
* Comment width (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $width = '96pt'; |
|||
|
|||
/** |
|||
* Left margin (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $marginLeft = '59.25pt'; |
|||
|
|||
/** |
|||
* Top margin (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $marginTop = '1.5pt'; |
|||
|
|||
/** |
|||
* Visible |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $visible = false; |
|||
|
|||
/** |
|||
* Comment height (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $height = '55.5pt'; |
|||
|
|||
/** |
|||
* Comment fill color |
|||
* |
|||
* @var PHPExcel_Style_Color |
|||
*/ |
|||
private $fillColor; |
|||
|
|||
/** |
|||
* Alignment |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $alignment; |
|||
|
|||
/** |
|||
* Create a new PHPExcel_Comment |
|||
* |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
// Initialise variables |
|||
$this->author = 'Author'; |
|||
$this->text = new PHPExcel_RichText(); |
|||
$this->fillColor = new PHPExcel_Style_Color('FFFFFFE1'); |
|||
$this->alignment = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL; |
|||
} |
|||
|
|||
/** |
|||
* Get Author |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getAuthor() |
|||
{ |
|||
return $this->author; |
|||
} |
|||
|
|||
/** |
|||
* Set Author |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_Comment |
|||
*/ |
|||
public function setAuthor($pValue = '') |
|||
{ |
|||
$this->author = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Rich text comment |
|||
* |
|||
* @return PHPExcel_RichText |
|||
*/ |
|||
public function getText() |
|||
{ |
|||
return $this->text; |
|||
} |
|||
|
|||
/** |
|||
* Set Rich text comment |
|||
* |
|||
* @param PHPExcel_RichText $pValue |
|||
* @return PHPExcel_Comment |
|||
*/ |
|||
public function setText(PHPExcel_RichText $pValue) |
|||
{ |
|||
$this->text = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get comment width (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getWidth() |
|||
{ |
|||
return $this->width; |
|||
} |
|||
|
|||
/** |
|||
* Set comment width (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @param string $value |
|||
* @return PHPExcel_Comment |
|||
*/ |
|||
public function setWidth($value = '96pt') |
|||
{ |
|||
$this->width = $value; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get comment height (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getHeight() |
|||
{ |
|||
return $this->height; |
|||
} |
|||
|
|||
/** |
|||
* Set comment height (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @param string $value |
|||
* @return PHPExcel_Comment |
|||
*/ |
|||
public function setHeight($value = '55.5pt') |
|||
{ |
|||
$this->height = $value; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get left margin (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getMarginLeft() |
|||
{ |
|||
return $this->marginLeft; |
|||
} |
|||
|
|||
/** |
|||
* Set left margin (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @param string $value |
|||
* @return PHPExcel_Comment |
|||
*/ |
|||
public function setMarginLeft($value = '59.25pt') |
|||
{ |
|||
$this->marginLeft = $value; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get top margin (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getMarginTop() |
|||
{ |
|||
return $this->marginTop; |
|||
} |
|||
|
|||
/** |
|||
* Set top margin (CSS style, i.e. XXpx or YYpt) |
|||
* |
|||
* @param string $value |
|||
* @return PHPExcel_Comment |
|||
*/ |
|||
public function setMarginTop($value = '1.5pt') |
|||
{ |
|||
$this->marginTop = $value; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Is the comment visible by default? |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getVisible() |
|||
{ |
|||
return $this->visible; |
|||
} |
|||
|
|||
/** |
|||
* Set comment default visibility |
|||
* |
|||
* @param boolean $value |
|||
* @return PHPExcel_Comment |
|||
*/ |
|||
public function setVisible($value = false) |
|||
{ |
|||
$this->visible = $value; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get fill color |
|||
* |
|||
* @return PHPExcel_Style_Color |
|||
*/ |
|||
public function getFillColor() |
|||
{ |
|||
return $this->fillColor; |
|||
} |
|||
|
|||
/** |
|||
* Set Alignment |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_Comment |
|||
*/ |
|||
public function setAlignment($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) |
|||
{ |
|||
$this->alignment = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Alignment |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getAlignment() |
|||
{ |
|||
return $this->alignment; |
|||
} |
|||
|
|||
/** |
|||
* Get hash code |
|||
* |
|||
* @return string Hash code |
|||
*/ |
|||
public function getHashCode() |
|||
{ |
|||
return md5( |
|||
$this->author . |
|||
$this->text->getHashCode() . |
|||
$this->width . |
|||
$this->height . |
|||
$this->marginLeft . |
|||
$this->marginTop . |
|||
($this->visible ? 1 : 0) . |
|||
$this->fillColor->getHashCode() . |
|||
$this->alignment . |
|||
__CLASS__ |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
|||
*/ |
|||
public function __clone() |
|||
{ |
|||
$vars = get_object_vars($this); |
|||
foreach ($vars as $key => $value) { |
|||
if (is_object($value)) { |
|||
$this->$key = clone $value; |
|||
} else { |
|||
$this->$key = $value; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Convert to string |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function __toString() |
|||
{ |
|||
return $this->text->getPlainText(); |
|||
} |
|||
} |
|||
@ -0,0 +1,611 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_DocumentProperties |
|||
* |
|||
* 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_DocumentProperties |
|||
{ |
|||
/** constants */ |
|||
const PROPERTY_TYPE_BOOLEAN = 'b'; |
|||
const PROPERTY_TYPE_INTEGER = 'i'; |
|||
const PROPERTY_TYPE_FLOAT = 'f'; |
|||
const PROPERTY_TYPE_DATE = 'd'; |
|||
const PROPERTY_TYPE_STRING = 's'; |
|||
const PROPERTY_TYPE_UNKNOWN = 'u'; |
|||
|
|||
/** |
|||
* Creator |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $creator = 'Unknown Creator'; |
|||
|
|||
/** |
|||
* LastModifiedBy |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $lastModifiedBy; |
|||
|
|||
/** |
|||
* Created |
|||
* |
|||
* @var datetime |
|||
*/ |
|||
private $created; |
|||
|
|||
/** |
|||
* Modified |
|||
* |
|||
* @var datetime |
|||
*/ |
|||
private $modified; |
|||
|
|||
/** |
|||
* Title |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $title = 'Untitled Spreadsheet'; |
|||
|
|||
/** |
|||
* Description |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $description = ''; |
|||
|
|||
/** |
|||
* Subject |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $subject = ''; |
|||
|
|||
/** |
|||
* Keywords |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $keywords = ''; |
|||
|
|||
/** |
|||
* Category |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $category = ''; |
|||
|
|||
/** |
|||
* Manager |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $manager = ''; |
|||
|
|||
/** |
|||
* Company |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $company = 'Microsoft Corporation'; |
|||
|
|||
/** |
|||
* Custom Properties |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $customProperties = array(); |
|||
|
|||
|
|||
/** |
|||
* Create a new PHPExcel_DocumentProperties |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
// Initialise values |
|||
$this->lastModifiedBy = $this->creator; |
|||
$this->created = time(); |
|||
$this->modified = time(); |
|||
} |
|||
|
|||
/** |
|||
* Get Creator |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getCreator() |
|||
{ |
|||
return $this->creator; |
|||
} |
|||
|
|||
/** |
|||
* Set Creator |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setCreator($pValue = '') |
|||
{ |
|||
$this->creator = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Last Modified By |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getLastModifiedBy() |
|||
{ |
|||
return $this->lastModifiedBy; |
|||
} |
|||
|
|||
/** |
|||
* Set Last Modified By |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setLastModifiedBy($pValue = '') |
|||
{ |
|||
$this->lastModifiedBy = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Created |
|||
* |
|||
* @return datetime |
|||
*/ |
|||
public function getCreated() |
|||
{ |
|||
return $this->created; |
|||
} |
|||
|
|||
/** |
|||
* Set Created |
|||
* |
|||
* @param datetime $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setCreated($pValue = null) |
|||
{ |
|||
if ($pValue === null) { |
|||
$pValue = time(); |
|||
} elseif (is_string($pValue)) { |
|||
if (is_numeric($pValue)) { |
|||
$pValue = intval($pValue); |
|||
} else { |
|||
$pValue = strtotime($pValue); |
|||
} |
|||
} |
|||
|
|||
$this->created = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Modified |
|||
* |
|||
* @return datetime |
|||
*/ |
|||
public function getModified() |
|||
{ |
|||
return $this->modified; |
|||
} |
|||
|
|||
/** |
|||
* Set Modified |
|||
* |
|||
* @param datetime $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setModified($pValue = null) |
|||
{ |
|||
if ($pValue === null) { |
|||
$pValue = time(); |
|||
} elseif (is_string($pValue)) { |
|||
if (is_numeric($pValue)) { |
|||
$pValue = intval($pValue); |
|||
} else { |
|||
$pValue = strtotime($pValue); |
|||
} |
|||
} |
|||
|
|||
$this->modified = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Title |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getTitle() |
|||
{ |
|||
return $this->title; |
|||
} |
|||
|
|||
/** |
|||
* Set Title |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setTitle($pValue = '') |
|||
{ |
|||
$this->title = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Description |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getDescription() |
|||
{ |
|||
return $this->description; |
|||
} |
|||
|
|||
/** |
|||
* Set Description |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setDescription($pValue = '') |
|||
{ |
|||
$this->description = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Subject |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getSubject() |
|||
{ |
|||
return $this->subject; |
|||
} |
|||
|
|||
/** |
|||
* Set Subject |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setSubject($pValue = '') |
|||
{ |
|||
$this->subject = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Keywords |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getKeywords() |
|||
{ |
|||
return $this->keywords; |
|||
} |
|||
|
|||
/** |
|||
* Set Keywords |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setKeywords($pValue = '') |
|||
{ |
|||
$this->keywords = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Category |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getCategory() |
|||
{ |
|||
return $this->category; |
|||
} |
|||
|
|||
/** |
|||
* Set Category |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setCategory($pValue = '') |
|||
{ |
|||
$this->category = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Company |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getCompany() |
|||
{ |
|||
return $this->company; |
|||
} |
|||
|
|||
/** |
|||
* Set Company |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setCompany($pValue = '') |
|||
{ |
|||
$this->company = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Manager |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getManager() |
|||
{ |
|||
return $this->manager; |
|||
} |
|||
|
|||
/** |
|||
* Set Manager |
|||
* |
|||
* @param string $pValue |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setManager($pValue = '') |
|||
{ |
|||
$this->manager = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get a List of Custom Property Names |
|||
* |
|||
* @return array of string |
|||
*/ |
|||
public function getCustomProperties() |
|||
{ |
|||
return array_keys($this->customProperties); |
|||
} |
|||
|
|||
/** |
|||
* Check if a Custom Property is defined |
|||
* |
|||
* @param string $propertyName |
|||
* @return boolean |
|||
*/ |
|||
public function isCustomPropertySet($propertyName) |
|||
{ |
|||
return isset($this->customProperties[$propertyName]); |
|||
} |
|||
|
|||
/** |
|||
* Get a Custom Property Value |
|||
* |
|||
* @param string $propertyName |
|||
* @return string |
|||
*/ |
|||
public function getCustomPropertyValue($propertyName) |
|||
{ |
|||
if (isset($this->customProperties[$propertyName])) { |
|||
return $this->customProperties[$propertyName]['value']; |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* Get a Custom Property Type |
|||
* |
|||
* @param string $propertyName |
|||
* @return string |
|||
*/ |
|||
public function getCustomPropertyType($propertyName) |
|||
{ |
|||
if (isset($this->customProperties[$propertyName])) { |
|||
return $this->customProperties[$propertyName]['type']; |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* Set a Custom Property |
|||
* |
|||
* @param string $propertyName |
|||
* @param mixed $propertyValue |
|||
* @param string $propertyType |
|||
* 'i' : Integer |
|||
* 'f' : Floating Point |
|||
* 's' : String |
|||
* 'd' : Date/Time |
|||
* 'b' : Boolean |
|||
* @return PHPExcel_DocumentProperties |
|||
*/ |
|||
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null) |
|||
{ |
|||
if (($propertyType === null) || (!in_array($propertyType, array(self::PROPERTY_TYPE_INTEGER, |
|||
self::PROPERTY_TYPE_FLOAT, |
|||
self::PROPERTY_TYPE_STRING, |
|||
self::PROPERTY_TYPE_DATE, |
|||
self::PROPERTY_TYPE_BOOLEAN)))) { |
|||
if ($propertyValue === null) { |
|||
$propertyType = self::PROPERTY_TYPE_STRING; |
|||
} elseif (is_float($propertyValue)) { |
|||
$propertyType = self::PROPERTY_TYPE_FLOAT; |
|||
} elseif (is_int($propertyValue)) { |
|||
$propertyType = self::PROPERTY_TYPE_INTEGER; |
|||
} elseif (is_bool($propertyValue)) { |
|||
$propertyType = self::PROPERTY_TYPE_BOOLEAN; |
|||
} else { |
|||
$propertyType = self::PROPERTY_TYPE_STRING; |
|||
} |
|||
} |
|||
|
|||
$this->customProperties[$propertyName] = array( |
|||
'value' => $propertyValue, |
|||
'type' => $propertyType |
|||
); |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
|||
*/ |
|||
public function __clone() |
|||
{ |
|||
$vars = get_object_vars($this); |
|||
foreach ($vars as $key => $value) { |
|||
if (is_object($value)) { |
|||
$this->$key = clone $value; |
|||
} else { |
|||
$this->$key = $value; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static function convertProperty($propertyValue, $propertyType) |
|||
{ |
|||
switch ($propertyType) { |
|||
case 'empty': // Empty |
|||
return ''; |
|||
break; |
|||
case 'null': // Null |
|||
return null; |
|||
break; |
|||
case 'i1': // 1-Byte Signed Integer |
|||
case 'i2': // 2-Byte Signed Integer |
|||
case 'i4': // 4-Byte Signed Integer |
|||
case 'i8': // 8-Byte Signed Integer |
|||
case 'int': // Integer |
|||
return (int) $propertyValue; |
|||
break; |
|||
case 'ui1': // 1-Byte Unsigned Integer |
|||
case 'ui2': // 2-Byte Unsigned Integer |
|||
case 'ui4': // 4-Byte Unsigned Integer |
|||
case 'ui8': // 8-Byte Unsigned Integer |
|||
case 'uint': // Unsigned Integer |
|||
return abs((int) $propertyValue); |
|||
break; |
|||
case 'r4': // 4-Byte Real Number |
|||
case 'r8': // 8-Byte Real Number |
|||
case 'decimal': // Decimal |
|||
return (float) $propertyValue; |
|||
break; |
|||
case 'lpstr': // LPSTR |
|||
case 'lpwstr': // LPWSTR |
|||
case 'bstr': // Basic String |
|||
return $propertyValue; |
|||
break; |
|||
case 'date': // Date and Time |
|||
case 'filetime': // File Time |
|||
return strtotime($propertyValue); |
|||
break; |
|||
case 'bool': // Boolean |
|||
return ($propertyValue == 'true') ? true : false; |
|||
break; |
|||
case 'cy': // Currency |
|||
case 'error': // Error Status Code |
|||
case 'vector': // Vector |
|||
case 'array': // Array |
|||
case 'blob': // Binary Blob |
|||
case 'oblob': // Binary Blob Object |
|||
case 'stream': // Binary Stream |
|||
case 'ostream': // Binary Stream Object |
|||
case 'storage': // Binary Storage |
|||
case 'ostorage': // Binary Storage Object |
|||
case 'vstream': // Binary Versioned Stream |
|||
case 'clsid': // Class ID |
|||
case 'cf': // Clipboard Data |
|||
return $propertyValue; |
|||
break; |
|||
} |
|||
return $propertyValue; |
|||
} |
|||
|
|||
public static function convertPropertyType($propertyType) |
|||
{ |
|||
switch ($propertyType) { |
|||
case 'i1': // 1-Byte Signed Integer |
|||
case 'i2': // 2-Byte Signed Integer |
|||
case 'i4': // 4-Byte Signed Integer |
|||
case 'i8': // 8-Byte Signed Integer |
|||
case 'int': // Integer |
|||
case 'ui1': // 1-Byte Unsigned Integer |
|||
case 'ui2': // 2-Byte Unsigned Integer |
|||
case 'ui4': // 4-Byte Unsigned Integer |
|||
case 'ui8': // 8-Byte Unsigned Integer |
|||
case 'uint': // Unsigned Integer |
|||
return self::PROPERTY_TYPE_INTEGER; |
|||
break; |
|||
case 'r4': // 4-Byte Real Number |
|||
case 'r8': // 8-Byte Real Number |
|||
case 'decimal': // Decimal |
|||
return self::PROPERTY_TYPE_FLOAT; |
|||
break; |
|||
case 'empty': // Empty |
|||
case 'null': // Null |
|||
case 'lpstr': // LPSTR |
|||
case 'lpwstr': // LPWSTR |
|||
case 'bstr': // Basic String |
|||
return self::PROPERTY_TYPE_STRING; |
|||
break; |
|||
case 'date': // Date and Time |
|||
case 'filetime': // File Time |
|||
return self::PROPERTY_TYPE_DATE; |
|||
break; |
|||
case 'bool': // Boolean |
|||
return self::PROPERTY_TYPE_BOOLEAN; |
|||
break; |
|||
case 'cy': // Currency |
|||
case 'error': // Error Status Code |
|||
case 'vector': // Vector |
|||
case 'array': // Array |
|||
case 'blob': // Binary Blob |
|||
case 'oblob': // Binary Blob Object |
|||
case 'stream': // Binary Stream |
|||
case 'ostream': // Binary Stream Object |
|||
case 'storage': // Binary Storage |
|||
case 'ostorage': // Binary Storage Object |
|||
case 'vstream': // Binary Versioned Stream |
|||
case 'clsid': // Class ID |
|||
case 'cf': // Clipboard Data |
|||
return self::PROPERTY_TYPE_UNKNOWN; |
|||
break; |
|||
} |
|||
return self::PROPERTY_TYPE_UNKNOWN; |
|||
} |
|||
} |
|||
@ -0,0 +1,222 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_DocumentSecurity |
|||
* |
|||
* 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_DocumentSecurity |
|||
{ |
|||
/** |
|||
* LockRevision |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $lockRevision; |
|||
|
|||
/** |
|||
* LockStructure |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $lockStructure; |
|||
|
|||
/** |
|||
* LockWindows |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $lockWindows; |
|||
|
|||
/** |
|||
* RevisionsPassword |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $revisionsPassword; |
|||
|
|||
/** |
|||
* WorkbookPassword |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $workbookPassword; |
|||
|
|||
/** |
|||
* Create a new PHPExcel_DocumentSecurity |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
// Initialise values |
|||
$this->lockRevision = false; |
|||
$this->lockStructure = false; |
|||
$this->lockWindows = false; |
|||
$this->revisionsPassword = ''; |
|||
$this->workbookPassword = ''; |
|||
} |
|||
|
|||
/** |
|||
* Is some sort of document security enabled? |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function isSecurityEnabled() |
|||
{ |
|||
return $this->lockRevision || |
|||
$this->lockStructure || |
|||
$this->lockWindows; |
|||
} |
|||
|
|||
/** |
|||
* Get LockRevision |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getLockRevision() |
|||
{ |
|||
return $this->lockRevision; |
|||
} |
|||
|
|||
/** |
|||
* Set LockRevision |
|||
* |
|||
* @param boolean $pValue |
|||
* @return PHPExcel_DocumentSecurity |
|||
*/ |
|||
public function setLockRevision($pValue = false) |
|||
{ |
|||
$this->lockRevision = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get LockStructure |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getLockStructure() |
|||
{ |
|||
return $this->lockStructure; |
|||
} |
|||
|
|||
/** |
|||
* Set LockStructure |
|||
* |
|||
* @param boolean $pValue |
|||
* @return PHPExcel_DocumentSecurity |
|||
*/ |
|||
public function setLockStructure($pValue = false) |
|||
{ |
|||
$this->lockStructure = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get LockWindows |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getLockWindows() |
|||
{ |
|||
return $this->lockWindows; |
|||
} |
|||
|
|||
/** |
|||
* Set LockWindows |
|||
* |
|||
* @param boolean $pValue |
|||
* @return PHPExcel_DocumentSecurity |
|||
*/ |
|||
public function setLockWindows($pValue = false) |
|||
{ |
|||
$this->lockWindows = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get RevisionsPassword (hashed) |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getRevisionsPassword() |
|||
{ |
|||
return $this->revisionsPassword; |
|||
} |
|||
|
|||
/** |
|||
* Set RevisionsPassword |
|||
* |
|||
* @param string $pValue |
|||
* @param boolean $pAlreadyHashed If the password has already been hashed, set this to true |
|||
* @return PHPExcel_DocumentSecurity |
|||
*/ |
|||
public function setRevisionsPassword($pValue = '', $pAlreadyHashed = false) |
|||
{ |
|||
if (!$pAlreadyHashed) { |
|||
$pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue); |
|||
} |
|||
$this->revisionsPassword = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get WorkbookPassword (hashed) |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getWorkbookPassword() |
|||
{ |
|||
return $this->workbookPassword; |
|||
} |
|||
|
|||
/** |
|||
* Set WorkbookPassword |
|||
* |
|||
* @param string $pValue |
|||
* @param boolean $pAlreadyHashed If the password has already been hashed, set this to true |
|||
* @return PHPExcel_DocumentSecurity |
|||
*/ |
|||
public function setWorkbookPassword($pValue = '', $pAlreadyHashed = false) |
|||
{ |
|||
if (!$pAlreadyHashed) { |
|||
$pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue); |
|||
} |
|||
$this->workbookPassword = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
|||
*/ |
|||
public function __clone() |
|||
{ |
|||
$vars = get_object_vars($this); |
|||
foreach ($vars as $key => $value) { |
|||
if (is_object($value)) { |
|||
$this->$key = clone $value; |
|||
} else { |
|||
$this->$key = $value; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
<?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## |
|||
*/ |
|||
|
|||
|
|||
/** |
|||
* PHPExcel_Exception |
|||
* |
|||
* @category PHPExcel |
|||
* @package PHPExcel |
|||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) |
|||
*/ |
|||
class PHPExcel_Exception extends Exception |
|||
{ |
|||
/** |
|||
* Error handler callback |
|||
* |
|||
* @param mixed $code |
|||
* @param mixed $string |
|||
* @param mixed $file |
|||
* @param mixed $line |
|||
* @param mixed $context |
|||
*/ |
|||
public static function errorHandlerCallback($code, $string, $file, $line, $context) |
|||
{ |
|||
$e = new self($string, $code); |
|||
$e->line = $line; |
|||
$e->file = $file; |
|||
throw $e; |
|||
} |
|||
} |
|||
@ -0,0 +1,204 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_HashTable |
|||
* |
|||
* 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_HashTable |
|||
{ |
|||
/** |
|||
* HashTable elements |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $items = array(); |
|||
|
|||
/** |
|||
* HashTable key map |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected $keyMap = array(); |
|||
|
|||
/** |
|||
* Create a new PHPExcel_HashTable |
|||
* |
|||
* @param PHPExcel_IComparable[] $pSource Optional source array to create HashTable from |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function __construct($pSource = null) |
|||
{ |
|||
if ($pSource !== null) { |
|||
// Create HashTable |
|||
$this->addFromSource($pSource); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Add HashTable items from source |
|||
* |
|||
* @param PHPExcel_IComparable[] $pSource Source array to create HashTable from |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function addFromSource($pSource = null) |
|||
{ |
|||
// Check if an array was passed |
|||
if ($pSource == null) { |
|||
return; |
|||
} elseif (!is_array($pSource)) { |
|||
throw new PHPExcel_Exception('Invalid array parameter passed.'); |
|||
} |
|||
|
|||
foreach ($pSource as $item) { |
|||
$this->add($item); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Add HashTable item |
|||
* |
|||
* @param PHPExcel_IComparable $pSource Item to add |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function add(PHPExcel_IComparable $pSource = null) |
|||
{ |
|||
$hash = $pSource->getHashCode(); |
|||
if (!isset($this->items[$hash])) { |
|||
$this->items[$hash] = $pSource; |
|||
$this->keyMap[count($this->items) - 1] = $hash; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Remove HashTable item |
|||
* |
|||
* @param PHPExcel_IComparable $pSource Item to remove |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function remove(PHPExcel_IComparable $pSource = null) |
|||
{ |
|||
$hash = $pSource->getHashCode(); |
|||
if (isset($this->items[$hash])) { |
|||
unset($this->items[$hash]); |
|||
|
|||
$deleteKey = -1; |
|||
foreach ($this->keyMap as $key => $value) { |
|||
if ($deleteKey >= 0) { |
|||
$this->keyMap[$key - 1] = $value; |
|||
} |
|||
|
|||
if ($value == $hash) { |
|||
$deleteKey = $key; |
|||
} |
|||
} |
|||
unset($this->keyMap[count($this->keyMap) - 1]); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Clear HashTable |
|||
* |
|||
*/ |
|||
public function clear() |
|||
{ |
|||
$this->items = array(); |
|||
$this->keyMap = array(); |
|||
} |
|||
|
|||
/** |
|||
* Count |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function count() |
|||
{ |
|||
return count($this->items); |
|||
} |
|||
|
|||
/** |
|||
* Get index for hash code |
|||
* |
|||
* @param string $pHashCode |
|||
* @return int Index |
|||
*/ |
|||
public function getIndexForHashCode($pHashCode = '') |
|||
{ |
|||
return array_search($pHashCode, $this->keyMap); |
|||
} |
|||
|
|||
/** |
|||
* Get by index |
|||
* |
|||
* @param int $pIndex |
|||
* @return PHPExcel_IComparable |
|||
* |
|||
*/ |
|||
public function getByIndex($pIndex = 0) |
|||
{ |
|||
if (isset($this->keyMap[$pIndex])) { |
|||
return $this->getByHashCode($this->keyMap[$pIndex]); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* Get by hashcode |
|||
* |
|||
* @param string $pHashCode |
|||
* @return PHPExcel_IComparable |
|||
* |
|||
*/ |
|||
public function getByHashCode($pHashCode = '') |
|||
{ |
|||
if (isset($this->items[$pHashCode])) { |
|||
return $this->items[$pHashCode]; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
/** |
|||
* HashTable to array |
|||
* |
|||
* @return PHPExcel_IComparable[] |
|||
*/ |
|||
public function toArray() |
|||
{ |
|||
return $this->items; |
|||
} |
|||
|
|||
/** |
|||
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
|||
*/ |
|||
public function __clone() |
|||
{ |
|||
$vars = get_object_vars($this); |
|||
foreach ($vars as $key => $value) { |
|||
if (is_object($value)) { |
|||
$this->$key = clone $value; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_IComparable |
|||
* |
|||
* 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## |
|||
*/ |
|||
interface PHPExcel_IComparable |
|||
{ |
|||
/** |
|||
* Get hash code |
|||
* |
|||
* @return string Hash code |
|||
*/ |
|||
public function getHashCode(); |
|||
} |
|||
@ -0,0 +1,289 @@ |
|||
<?php |
|||
|
|||
/** PHPExcel root directory */ |
|||
if (!defined('PHPEXCEL_ROOT')) { |
|||
/** |
|||
* @ignore |
|||
*/ |
|||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); |
|||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
|||
} |
|||
|
|||
/** |
|||
* PHPExcel_IOFactory |
|||
* |
|||
* 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_IOFactory |
|||
{ |
|||
/** |
|||
* Search locations |
|||
* |
|||
* @var array |
|||
* @access private |
|||
* @static |
|||
*/ |
|||
private static $searchLocations = array( |
|||
array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ), |
|||
array( 'type' => 'IReader', 'path' => 'PHPExcel/Reader/{0}.php', 'class' => 'PHPExcel_Reader_{0}' ) |
|||
); |
|||
|
|||
/** |
|||
* Autoresolve classes |
|||
* |
|||
* @var array |
|||
* @access private |
|||
* @static |
|||
*/ |
|||
private static $autoResolveClasses = array( |
|||
'Excel2007', |
|||
'Excel5', |
|||
'Excel2003XML', |
|||
'OOCalc', |
|||
'SYLK', |
|||
'Gnumeric', |
|||
'HTML', |
|||
'CSV', |
|||
); |
|||
|
|||
/** |
|||
* Private constructor for PHPExcel_IOFactory |
|||
*/ |
|||
private function __construct() |
|||
{ |
|||
} |
|||
|
|||
/** |
|||
* Get search locations |
|||
* |
|||
* @static |
|||
* @access public |
|||
* @return array |
|||
*/ |
|||
public static function getSearchLocations() |
|||
{ |
|||
return self::$searchLocations; |
|||
} |
|||
|
|||
/** |
|||
* Set search locations |
|||
* |
|||
* @static |
|||
* @access public |
|||
* @param array $value |
|||
* @throws PHPExcel_Reader_Exception |
|||
*/ |
|||
public static function setSearchLocations($value) |
|||
{ |
|||
if (is_array($value)) { |
|||
self::$searchLocations = $value; |
|||
} else { |
|||
throw new PHPExcel_Reader_Exception('Invalid parameter passed.'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Add search location |
|||
* |
|||
* @static |
|||
* @access public |
|||
* @param string $type Example: IWriter |
|||
* @param string $location Example: PHPExcel/Writer/{0}.php |
|||
* @param string $classname Example: PHPExcel_Writer_{0} |
|||
*/ |
|||
public static function addSearchLocation($type = '', $location = '', $classname = '') |
|||
{ |
|||
self::$searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname ); |
|||
} |
|||
|
|||
/** |
|||
* Create PHPExcel_Writer_IWriter |
|||
* |
|||
* @static |
|||
* @access public |
|||
* @param PHPExcel $phpExcel |
|||
* @param string $writerType Example: Excel2007 |
|||
* @return PHPExcel_Writer_IWriter |
|||
* @throws PHPExcel_Reader_Exception |
|||
*/ |
|||
public static function createWriter(PHPExcel $phpExcel, $writerType = '') |
|||
{ |
|||
// Search type |
|||
$searchType = 'IWriter'; |
|||
|
|||
// Include class |
|||
foreach (self::$searchLocations as $searchLocation) { |
|||
if ($searchLocation['type'] == $searchType) { |
|||
$className = str_replace('{0}', $writerType, $searchLocation['class']); |
|||
|
|||
$instance = new $className($phpExcel); |
|||
if ($instance !== null) { |
|||
return $instance; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Nothing found... |
|||
throw new PHPExcel_Reader_Exception("No $searchType found for type $writerType"); |
|||
} |
|||
|
|||
/** |
|||
* Create PHPExcel_Reader_IReader |
|||
* |
|||
* @static |
|||
* @access public |
|||
* @param string $readerType Example: Excel2007 |
|||
* @return PHPExcel_Reader_IReader |
|||
* @throws PHPExcel_Reader_Exception |
|||
*/ |
|||
public static function createReader($readerType = '') |
|||
{ |
|||
// Search type |
|||
$searchType = 'IReader'; |
|||
|
|||
// Include class |
|||
foreach (self::$searchLocations as $searchLocation) { |
|||
if ($searchLocation['type'] == $searchType) { |
|||
$className = str_replace('{0}', $readerType, $searchLocation['class']); |
|||
|
|||
$instance = new $className(); |
|||
if ($instance !== null) { |
|||
return $instance; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Nothing found... |
|||
throw new PHPExcel_Reader_Exception("No $searchType found for type $readerType"); |
|||
} |
|||
|
|||
/** |
|||
* Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution |
|||
* |
|||
* @static |
|||
* @access public |
|||
* @param string $pFilename The name of the spreadsheet file |
|||
* @return PHPExcel |
|||
* @throws PHPExcel_Reader_Exception |
|||
*/ |
|||
public static function load($pFilename) |
|||
{ |
|||
$reader = self::createReaderForFile($pFilename); |
|||
return $reader->load($pFilename); |
|||
} |
|||
|
|||
/** |
|||
* Identify file type using automatic PHPExcel_Reader_IReader resolution |
|||
* |
|||
* @static |
|||
* @access public |
|||
* @param string $pFilename The name of the spreadsheet file to identify |
|||
* @return string |
|||
* @throws PHPExcel_Reader_Exception |
|||
*/ |
|||
public static function identify($pFilename) |
|||
{ |
|||
$reader = self::createReaderForFile($pFilename); |
|||
$className = get_class($reader); |
|||
$classType = explode('_', $className); |
|||
unset($reader); |
|||
return array_pop($classType); |
|||
} |
|||
|
|||
/** |
|||
* Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution |
|||
* |
|||
* @static |
|||
* @access public |
|||
* @param string $pFilename The name of the spreadsheet file |
|||
* @return PHPExcel_Reader_IReader |
|||
* @throws PHPExcel_Reader_Exception |
|||
*/ |
|||
public static function createReaderForFile($pFilename) |
|||
{ |
|||
// First, lucky guess by inspecting file extension |
|||
$pathinfo = pathinfo($pFilename); |
|||
|
|||
$extensionType = null; |
|||
if (isset($pathinfo['extension'])) { |
|||
switch (strtolower($pathinfo['extension'])) { |
|||
case 'xlsx': // Excel (OfficeOpenXML) Spreadsheet |
|||
case 'xlsm': // Excel (OfficeOpenXML) Macro Spreadsheet (macros will be discarded) |
|||
case 'xltx': // Excel (OfficeOpenXML) Template |
|||
case 'xltm': // Excel (OfficeOpenXML) Macro Template (macros will be discarded) |
|||
$extensionType = 'Excel2007'; |
|||
break; |
|||
case 'xls': // Excel (BIFF) Spreadsheet |
|||
case 'xlt': // Excel (BIFF) Template |
|||
$extensionType = 'Excel5'; |
|||
break; |
|||
case 'ods': // Open/Libre Offic Calc |
|||
case 'ots': // Open/Libre Offic Calc Template |
|||
$extensionType = 'OOCalc'; |
|||
break; |
|||
case 'slk': |
|||
$extensionType = 'SYLK'; |
|||
break; |
|||
case 'xml': // Excel 2003 SpreadSheetML |
|||
$extensionType = 'Excel2003XML'; |
|||
break; |
|||
case 'gnumeric': |
|||
$extensionType = 'Gnumeric'; |
|||
break; |
|||
case 'htm': |
|||
case 'html': |
|||
$extensionType = 'HTML'; |
|||
break; |
|||
case 'csv': |
|||
// Do nothing |
|||
// We must not try to use CSV reader since it loads |
|||
// all files including Excel files etc. |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
|
|||
if ($extensionType !== null) { |
|||
$reader = self::createReader($extensionType); |
|||
// Let's see if we are lucky |
|||
if (isset($reader) && $reader->canRead($pFilename)) { |
|||
return $reader; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// If we reach here then "lucky guess" didn't give any result |
|||
// Try walking through all the options in self::$autoResolveClasses |
|||
foreach (self::$autoResolveClasses as $autoResolveClass) { |
|||
// Ignore our original guess, we know that won't work |
|||
if ($autoResolveClass !== $extensionType) { |
|||
$reader = self::createReader($autoResolveClass); |
|||
if ($reader->canRead($pFilename)) { |
|||
return $reader; |
|||
} |
|||
} |
|||
} |
|||
|
|||
throw new PHPExcel_Reader_Exception('Unable to identify a reader for this file'); |
|||
} |
|||
} |
|||
@ -0,0 +1,249 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_NamedRange |
|||
* |
|||
* 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_NamedRange |
|||
{ |
|||
/** |
|||
* Range name |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $name; |
|||
|
|||
/** |
|||
* Worksheet on which the named range can be resolved |
|||
* |
|||
* @var PHPExcel_Worksheet |
|||
*/ |
|||
private $worksheet; |
|||
|
|||
/** |
|||
* Range of the referenced cells |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $range; |
|||
|
|||
/** |
|||
* Is the named range local? (i.e. can only be used on $this->worksheet) |
|||
* |
|||
* @var bool |
|||
*/ |
|||
private $localOnly; |
|||
|
|||
/** |
|||
* Scope |
|||
* |
|||
* @var PHPExcel_Worksheet |
|||
*/ |
|||
private $scope; |
|||
|
|||
/** |
|||
* Create a new NamedRange |
|||
* |
|||
* @param string $pName |
|||
* @param PHPExcel_Worksheet $pWorksheet |
|||
* @param string $pRange |
|||
* @param bool $pLocalOnly |
|||
* @param PHPExcel_Worksheet|null $pScope Scope. Only applies when $pLocalOnly = true. Null for global scope. |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function __construct($pName = null, PHPExcel_Worksheet $pWorksheet, $pRange = 'A1', $pLocalOnly = false, $pScope = null) |
|||
{ |
|||
// Validate data |
|||
if (($pName === null) || ($pWorksheet === null) || ($pRange === null)) { |
|||
throw new PHPExcel_Exception('Parameters can not be null.'); |
|||
} |
|||
|
|||
// Set local members |
|||
$this->name = $pName; |
|||
$this->worksheet = $pWorksheet; |
|||
$this->range = $pRange; |
|||
$this->localOnly = $pLocalOnly; |
|||
$this->scope = ($pLocalOnly == true) ? (($pScope == null) ? $pWorksheet : $pScope) : null; |
|||
} |
|||
|
|||
/** |
|||
* Get name |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getName() |
|||
{ |
|||
return $this->name; |
|||
} |
|||
|
|||
/** |
|||
* Set name |
|||
* |
|||
* @param string $value |
|||
* @return PHPExcel_NamedRange |
|||
*/ |
|||
public function setName($value = null) |
|||
{ |
|||
if ($value !== null) { |
|||
// Old title |
|||
$oldTitle = $this->name; |
|||
|
|||
// Re-attach |
|||
if ($this->worksheet !== null) { |
|||
$this->worksheet->getParent()->removeNamedRange($this->name, $this->worksheet); |
|||
} |
|||
$this->name = $value; |
|||
|
|||
if ($this->worksheet !== null) { |
|||
$this->worksheet->getParent()->addNamedRange($this); |
|||
} |
|||
|
|||
// New title |
|||
$newTitle = $this->name; |
|||
PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->worksheet->getParent(), $oldTitle, $newTitle); |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get worksheet |
|||
* |
|||
* @return PHPExcel_Worksheet |
|||
*/ |
|||
public function getWorksheet() |
|||
{ |
|||
return $this->worksheet; |
|||
} |
|||
|
|||
/** |
|||
* Set worksheet |
|||
* |
|||
* @param PHPExcel_Worksheet $value |
|||
* @return PHPExcel_NamedRange |
|||
*/ |
|||
public function setWorksheet(PHPExcel_Worksheet $value = null) |
|||
{ |
|||
if ($value !== null) { |
|||
$this->worksheet = $value; |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get range |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getRange() |
|||
{ |
|||
return $this->range; |
|||
} |
|||
|
|||
/** |
|||
* Set range |
|||
* |
|||
* @param string $value |
|||
* @return PHPExcel_NamedRange |
|||
*/ |
|||
public function setRange($value = null) |
|||
{ |
|||
if ($value !== null) { |
|||
$this->range = $value; |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get localOnly |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function getLocalOnly() |
|||
{ |
|||
return $this->localOnly; |
|||
} |
|||
|
|||
/** |
|||
* Set localOnly |
|||
* |
|||
* @param bool $value |
|||
* @return PHPExcel_NamedRange |
|||
*/ |
|||
public function setLocalOnly($value = false) |
|||
{ |
|||
$this->localOnly = $value; |
|||
$this->scope = $value ? $this->worksheet : null; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get scope |
|||
* |
|||
* @return PHPExcel_Worksheet|null |
|||
*/ |
|||
public function getScope() |
|||
{ |
|||
return $this->scope; |
|||
} |
|||
|
|||
/** |
|||
* Set scope |
|||
* |
|||
* @param PHPExcel_Worksheet|null $value |
|||
* @return PHPExcel_NamedRange |
|||
*/ |
|||
public function setScope(PHPExcel_Worksheet $value = null) |
|||
{ |
|||
$this->scope = $value; |
|||
$this->localOnly = ($value == null) ? false : true; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Resolve a named range to a regular cell range |
|||
* |
|||
* @param string $pNamedRange Named range |
|||
* @param PHPExcel_Worksheet|null $pSheet Scope. Use null for global scope |
|||
* @return PHPExcel_NamedRange |
|||
*/ |
|||
public static function resolveRange($pNamedRange = '', PHPExcel_Worksheet $pSheet) |
|||
{ |
|||
return $pSheet->getParent()->getNamedRange($pNamedRange, $pSheet); |
|||
} |
|||
|
|||
/** |
|||
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
|||
*/ |
|||
public function __clone() |
|||
{ |
|||
$vars = get_object_vars($this); |
|||
foreach ($vars as $key => $value) { |
|||
if (is_object($value)) { |
|||
$this->$key = clone $value; |
|||
} else { |
|||
$this->$key = $value; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,913 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_ReferenceHelper (Singleton) |
|||
* |
|||
* 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_ReferenceHelper |
|||
{ |
|||
/** Constants */ |
|||
/** Regular Expressions */ |
|||
const REFHELPER_REGEXP_CELLREF = '((\w*|\'[^!]*\')!)?(?<![:a-z\$])(\$?[a-z]{1,3}\$?\d+)(?=[^:!\d\'])'; |
|||
const REFHELPER_REGEXP_CELLRANGE = '((\w*|\'[^!]*\')!)?(\$?[a-z]{1,3}\$?\d+):(\$?[a-z]{1,3}\$?\d+)'; |
|||
const REFHELPER_REGEXP_ROWRANGE = '((\w*|\'[^!]*\')!)?(\$?\d+):(\$?\d+)'; |
|||
const REFHELPER_REGEXP_COLRANGE = '((\w*|\'[^!]*\')!)?(\$?[a-z]{1,3}):(\$?[a-z]{1,3})'; |
|||
|
|||
/** |
|||
* Instance of this class |
|||
* |
|||
* @var PHPExcel_ReferenceHelper |
|||
*/ |
|||
private static $instance; |
|||
|
|||
/** |
|||
* Get an instance of this class |
|||
* |
|||
* @return PHPExcel_ReferenceHelper |
|||
*/ |
|||
public static function getInstance() |
|||
{ |
|||
if (!isset(self::$instance) || (self::$instance === null)) { |
|||
self::$instance = new PHPExcel_ReferenceHelper(); |
|||
} |
|||
|
|||
return self::$instance; |
|||
} |
|||
|
|||
/** |
|||
* Create a new PHPExcel_ReferenceHelper |
|||
*/ |
|||
protected function __construct() |
|||
{ |
|||
} |
|||
|
|||
/** |
|||
* Compare two column addresses |
|||
* Intended for use as a Callback function for sorting column addresses by column |
|||
* |
|||
* @param string $a First column to test (e.g. 'AA') |
|||
* @param string $b Second column to test (e.g. 'Z') |
|||
* @return integer |
|||
*/ |
|||
public static function columnSort($a, $b) |
|||
{ |
|||
return strcasecmp(strlen($a) . $a, strlen($b) . $b); |
|||
} |
|||
|
|||
/** |
|||
* Compare two column addresses |
|||
* Intended for use as a Callback function for reverse sorting column addresses by column |
|||
* |
|||
* @param string $a First column to test (e.g. 'AA') |
|||
* @param string $b Second column to test (e.g. 'Z') |
|||
* @return integer |
|||
*/ |
|||
public static function columnReverseSort($a, $b) |
|||
{ |
|||
return 1 - strcasecmp(strlen($a) . $a, strlen($b) . $b); |
|||
} |
|||
|
|||
/** |
|||
* Compare two cell addresses |
|||
* Intended for use as a Callback function for sorting cell addresses by column and row |
|||
* |
|||
* @param string $a First cell to test (e.g. 'AA1') |
|||
* @param string $b Second cell to test (e.g. 'Z1') |
|||
* @return integer |
|||
*/ |
|||
public static function cellSort($a, $b) |
|||
{ |
|||
sscanf($a, '%[A-Z]%d', $ac, $ar); |
|||
sscanf($b, '%[A-Z]%d', $bc, $br); |
|||
|
|||
if ($ar == $br) { |
|||
return strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); |
|||
} |
|||
return ($ar < $br) ? -1 : 1; |
|||
} |
|||
|
|||
/** |
|||
* Compare two cell addresses |
|||
* Intended for use as a Callback function for sorting cell addresses by column and row |
|||
* |
|||
* @param string $a First cell to test (e.g. 'AA1') |
|||
* @param string $b Second cell to test (e.g. 'Z1') |
|||
* @return integer |
|||
*/ |
|||
public static function cellReverseSort($a, $b) |
|||
{ |
|||
sscanf($a, '%[A-Z]%d', $ac, $ar); |
|||
sscanf($b, '%[A-Z]%d', $bc, $br); |
|||
|
|||
if ($ar == $br) { |
|||
return 1 - strcasecmp(strlen($ac) . $ac, strlen($bc) . $bc); |
|||
} |
|||
return ($ar < $br) ? 1 : -1; |
|||
} |
|||
|
|||
/** |
|||
* Test whether a cell address falls within a defined range of cells |
|||
* |
|||
* @param string $cellAddress Address of the cell we're testing |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @return boolean |
|||
*/ |
|||
private static function cellAddressInDeleteRange($cellAddress, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols) |
|||
{ |
|||
list($cellColumn, $cellRow) = PHPExcel_Cell::coordinateFromString($cellAddress); |
|||
$cellColumnIndex = PHPExcel_Cell::columnIndexFromString($cellColumn); |
|||
// Is cell within the range of rows/columns if we're deleting |
|||
if ($pNumRows < 0 && |
|||
($cellRow >= ($beforeRow + $pNumRows)) && |
|||
($cellRow < $beforeRow)) { |
|||
return true; |
|||
} elseif ($pNumCols < 0 && |
|||
($cellColumnIndex >= ($beforeColumnIndex + $pNumCols)) && |
|||
($cellColumnIndex < $beforeColumnIndex)) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Update page breaks when inserting/deleting rows/columns |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
*/ |
|||
protected function adjustPageBreaks(PHPExcel_Worksheet $pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows) |
|||
{ |
|||
$aBreaks = $pSheet->getBreaks(); |
|||
($pNumCols > 0 || $pNumRows > 0) ? |
|||
uksort($aBreaks, array('PHPExcel_ReferenceHelper','cellReverseSort')) : |
|||
uksort($aBreaks, array('PHPExcel_ReferenceHelper','cellSort')); |
|||
|
|||
foreach ($aBreaks as $key => $value) { |
|||
if (self::cellAddressInDeleteRange($key, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)) { |
|||
// If we're deleting, then clear any defined breaks that are within the range |
|||
// of rows/columns that we're deleting |
|||
$pSheet->setBreak($key, PHPExcel_Worksheet::BREAK_NONE); |
|||
} else { |
|||
// Otherwise update any affected breaks by inserting a new break at the appropriate point |
|||
// and removing the old affected break |
|||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); |
|||
if ($key != $newReference) { |
|||
$pSheet->setBreak($newReference, $value) |
|||
->setBreak($key, PHPExcel_Worksheet::BREAK_NONE); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update cell comments when inserting/deleting rows/columns |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
*/ |
|||
protected function adjustComments($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows) |
|||
{ |
|||
$aComments = $pSheet->getComments(); |
|||
$aNewComments = array(); // the new array of all comments |
|||
|
|||
foreach ($aComments as $key => &$value) { |
|||
// Any comments inside a deleted range will be ignored |
|||
if (!self::cellAddressInDeleteRange($key, $beforeRow, $pNumRows, $beforeColumnIndex, $pNumCols)) { |
|||
// Otherwise build a new array of comments indexed by the adjusted cell reference |
|||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); |
|||
$aNewComments[$newReference] = $value; |
|||
} |
|||
} |
|||
// Replace the comments array with the new set of comments |
|||
$pSheet->setComments($aNewComments); |
|||
} |
|||
|
|||
/** |
|||
* Update hyperlinks when inserting/deleting rows/columns |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
*/ |
|||
protected function adjustHyperlinks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows) |
|||
{ |
|||
$aHyperlinkCollection = $pSheet->getHyperlinkCollection(); |
|||
($pNumCols > 0 || $pNumRows > 0) ? uksort($aHyperlinkCollection, array('PHPExcel_ReferenceHelper','cellReverseSort')) : uksort($aHyperlinkCollection, array('PHPExcel_ReferenceHelper','cellSort')); |
|||
|
|||
foreach ($aHyperlinkCollection as $key => $value) { |
|||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); |
|||
if ($key != $newReference) { |
|||
$pSheet->setHyperlink($newReference, $value); |
|||
$pSheet->setHyperlink($key, null); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update data validations when inserting/deleting rows/columns |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
*/ |
|||
protected function adjustDataValidations($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows) |
|||
{ |
|||
$aDataValidationCollection = $pSheet->getDataValidationCollection(); |
|||
($pNumCols > 0 || $pNumRows > 0) ? uksort($aDataValidationCollection, array('PHPExcel_ReferenceHelper','cellReverseSort')) : uksort($aDataValidationCollection, array('PHPExcel_ReferenceHelper','cellSort')); |
|||
|
|||
foreach ($aDataValidationCollection as $key => $value) { |
|||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); |
|||
if ($key != $newReference) { |
|||
$pSheet->setDataValidation($newReference, $value); |
|||
$pSheet->setDataValidation($key, null); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update merged cells when inserting/deleting rows/columns |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
*/ |
|||
protected function adjustMergeCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows) |
|||
{ |
|||
$aMergeCells = $pSheet->getMergeCells(); |
|||
$aNewMergeCells = array(); // the new array of all merge cells |
|||
foreach ($aMergeCells as $key => &$value) { |
|||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); |
|||
$aNewMergeCells[$newReference] = $newReference; |
|||
} |
|||
$pSheet->setMergeCells($aNewMergeCells); // replace the merge cells array |
|||
} |
|||
|
|||
/** |
|||
* Update protected cells when inserting/deleting rows/columns |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
*/ |
|||
protected function adjustProtectedCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows) |
|||
{ |
|||
$aProtectedCells = $pSheet->getProtectedCells(); |
|||
($pNumCols > 0 || $pNumRows > 0) ? |
|||
uksort($aProtectedCells, array('PHPExcel_ReferenceHelper','cellReverseSort')) : |
|||
uksort($aProtectedCells, array('PHPExcel_ReferenceHelper','cellSort')); |
|||
foreach ($aProtectedCells as $key => $value) { |
|||
$newReference = $this->updateCellReference($key, $pBefore, $pNumCols, $pNumRows); |
|||
if ($key != $newReference) { |
|||
$pSheet->protectCells($newReference, $value, true); |
|||
$pSheet->unprotectCells($key); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update column dimensions when inserting/deleting rows/columns |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
*/ |
|||
protected function adjustColumnDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows) |
|||
{ |
|||
$aColumnDimensions = array_reverse($pSheet->getColumnDimensions(), true); |
|||
if (!empty($aColumnDimensions)) { |
|||
foreach ($aColumnDimensions as $objColumnDimension) { |
|||
$newReference = $this->updateCellReference($objColumnDimension->getColumnIndex() . '1', $pBefore, $pNumCols, $pNumRows); |
|||
list($newReference) = PHPExcel_Cell::coordinateFromString($newReference); |
|||
if ($objColumnDimension->getColumnIndex() != $newReference) { |
|||
$objColumnDimension->setColumnIndex($newReference); |
|||
} |
|||
} |
|||
$pSheet->refreshColumnDimensions(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update row dimensions when inserting/deleting rows/columns |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @param string $pBefore Insert/Delete before this cell address (e.g. 'A1') |
|||
* @param integer $beforeColumnIndex Index number of the column we're inserting/deleting before |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $beforeRow Number of the row we're inserting/deleting before |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
*/ |
|||
protected function adjustRowDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows) |
|||
{ |
|||
$aRowDimensions = array_reverse($pSheet->getRowDimensions(), true); |
|||
if (!empty($aRowDimensions)) { |
|||
foreach ($aRowDimensions as $objRowDimension) { |
|||
$newReference = $this->updateCellReference('A' . $objRowDimension->getRowIndex(), $pBefore, $pNumCols, $pNumRows); |
|||
list(, $newReference) = PHPExcel_Cell::coordinateFromString($newReference); |
|||
if ($objRowDimension->getRowIndex() != $newReference) { |
|||
$objRowDimension->setRowIndex($newReference); |
|||
} |
|||
} |
|||
$pSheet->refreshRowDimensions(); |
|||
|
|||
$copyDimension = $pSheet->getRowDimension($beforeRow - 1); |
|||
for ($i = $beforeRow; $i <= $beforeRow - 1 + $pNumRows; ++$i) { |
|||
$newDimension = $pSheet->getRowDimension($i); |
|||
$newDimension->setRowHeight($copyDimension->getRowHeight()); |
|||
$newDimension->setVisible($copyDimension->getVisible()); |
|||
$newDimension->setOutlineLevel($copyDimension->getOutlineLevel()); |
|||
$newDimension->setCollapsed($copyDimension->getCollapsed()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Insert a new column or row, updating all possible related data |
|||
* |
|||
* @param string $pBefore Insert before this cell address (e.g. 'A1') |
|||
* @param integer $pNumCols Number of columns to insert/delete (negative values indicate deletion) |
|||
* @param integer $pNumRows Number of rows to insert/delete (negative values indicate deletion) |
|||
* @param PHPExcel_Worksheet $pSheet The worksheet that we're editing |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function insertNewBefore($pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, PHPExcel_Worksheet $pSheet = null) |
|||
{ |
|||
$remove = ($pNumCols < 0 || $pNumRows < 0); |
|||
$aCellCollection = $pSheet->getCellCollection(); |
|||
|
|||
// Get coordinates of $pBefore |
|||
$beforeColumn = 'A'; |
|||
$beforeRow = 1; |
|||
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString($pBefore); |
|||
$beforeColumnIndex = PHPExcel_Cell::columnIndexFromString($beforeColumn); |
|||
|
|||
// Clear cells if we are removing columns or rows |
|||
$highestColumn = $pSheet->getHighestColumn(); |
|||
$highestRow = $pSheet->getHighestRow(); |
|||
|
|||
// 1. Clear column strips if we are removing columns |
|||
if ($pNumCols < 0 && $beforeColumnIndex - 2 + $pNumCols > 0) { |
|||
for ($i = 1; $i <= $highestRow - 1; ++$i) { |
|||
for ($j = $beforeColumnIndex - 1 + $pNumCols; $j <= $beforeColumnIndex - 2; ++$j) { |
|||
$coordinate = PHPExcel_Cell::stringFromColumnIndex($j) . $i; |
|||
$pSheet->removeConditionalStyles($coordinate); |
|||
if ($pSheet->cellExists($coordinate)) { |
|||
$pSheet->getCell($coordinate)->setValueExplicit('', PHPExcel_Cell_DataType::TYPE_NULL); |
|||
$pSheet->getCell($coordinate)->setXfIndex(0); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
// 2. Clear row strips if we are removing rows |
|||
if ($pNumRows < 0 && $beforeRow - 1 + $pNumRows > 0) { |
|||
for ($i = $beforeColumnIndex - 1; $i <= PHPExcel_Cell::columnIndexFromString($highestColumn) - 1; ++$i) { |
|||
for ($j = $beforeRow + $pNumRows; $j <= $beforeRow - 1; ++$j) { |
|||
$coordinate = PHPExcel_Cell::stringFromColumnIndex($i) . $j; |
|||
$pSheet->removeConditionalStyles($coordinate); |
|||
if ($pSheet->cellExists($coordinate)) { |
|||
$pSheet->getCell($coordinate)->setValueExplicit('', PHPExcel_Cell_DataType::TYPE_NULL); |
|||
$pSheet->getCell($coordinate)->setXfIndex(0); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Loop through cells, bottom-up, and change cell coordinates |
|||
if ($remove) { |
|||
// It's faster to reverse and pop than to use unshift, especially with large cell collections |
|||
$aCellCollection = array_reverse($aCellCollection); |
|||
} |
|||
while ($cellID = array_pop($aCellCollection)) { |
|||
$cell = $pSheet->getCell($cellID); |
|||
$cellIndex = PHPExcel_Cell::columnIndexFromString($cell->getColumn()); |
|||
|
|||
if ($cellIndex-1 + $pNumCols < 0) { |
|||
continue; |
|||
} |
|||
|
|||
// New coordinates |
|||
$newCoordinates = PHPExcel_Cell::stringFromColumnIndex($cellIndex-1 + $pNumCols) . ($cell->getRow() + $pNumRows); |
|||
|
|||
// Should the cell be updated? Move value and cellXf index from one cell to another. |
|||
if (($cellIndex >= $beforeColumnIndex) && ($cell->getRow() >= $beforeRow)) { |
|||
// Update cell styles |
|||
$pSheet->getCell($newCoordinates)->setXfIndex($cell->getXfIndex()); |
|||
|
|||
// Insert this cell at its new location |
|||
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) { |
|||
// Formula should be adjusted |
|||
$pSheet->getCell($newCoordinates) |
|||
->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle())); |
|||
} else { |
|||
// Formula should not be adjusted |
|||
$pSheet->getCell($newCoordinates)->setValue($cell->getValue()); |
|||
} |
|||
|
|||
// Clear the original cell |
|||
$pSheet->getCellCacheController()->deleteCacheData($cellID); |
|||
} else { |
|||
/* We don't need to update styles for rows/columns before our insertion position, |
|||
but we do still need to adjust any formulae in those cells */ |
|||
if ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA) { |
|||
// Formula should be adjusted |
|||
$cell->setValue($this->updateFormulaReferences($cell->getValue(), $pBefore, $pNumCols, $pNumRows, $pSheet->getTitle())); |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
// Duplicate styles for the newly inserted cells |
|||
$highestColumn = $pSheet->getHighestColumn(); |
|||
$highestRow = $pSheet->getHighestRow(); |
|||
|
|||
if ($pNumCols > 0 && $beforeColumnIndex - 2 > 0) { |
|||
for ($i = $beforeRow; $i <= $highestRow - 1; ++$i) { |
|||
// Style |
|||
$coordinate = PHPExcel_Cell::stringFromColumnIndex($beforeColumnIndex - 2) . $i; |
|||
if ($pSheet->cellExists($coordinate)) { |
|||
$xfIndex = $pSheet->getCell($coordinate)->getXfIndex(); |
|||
$conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? |
|||
$pSheet->getConditionalStyles($coordinate) : false; |
|||
for ($j = $beforeColumnIndex - 1; $j <= $beforeColumnIndex - 2 + $pNumCols; ++$j) { |
|||
$pSheet->getCellByColumnAndRow($j, $i)->setXfIndex($xfIndex); |
|||
if ($conditionalStyles) { |
|||
$cloned = array(); |
|||
foreach ($conditionalStyles as $conditionalStyle) { |
|||
$cloned[] = clone $conditionalStyle; |
|||
} |
|||
$pSheet->setConditionalStyles(PHPExcel_Cell::stringFromColumnIndex($j) . $i, $cloned); |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
if ($pNumRows > 0 && $beforeRow - 1 > 0) { |
|||
for ($i = $beforeColumnIndex - 1; $i <= PHPExcel_Cell::columnIndexFromString($highestColumn) - 1; ++$i) { |
|||
// Style |
|||
$coordinate = PHPExcel_Cell::stringFromColumnIndex($i) . ($beforeRow - 1); |
|||
if ($pSheet->cellExists($coordinate)) { |
|||
$xfIndex = $pSheet->getCell($coordinate)->getXfIndex(); |
|||
$conditionalStyles = $pSheet->conditionalStylesExists($coordinate) ? |
|||
$pSheet->getConditionalStyles($coordinate) : false; |
|||
for ($j = $beforeRow; $j <= $beforeRow - 1 + $pNumRows; ++$j) { |
|||
$pSheet->getCell(PHPExcel_Cell::stringFromColumnIndex($i) . $j)->setXfIndex($xfIndex); |
|||
if ($conditionalStyles) { |
|||
$cloned = array(); |
|||
foreach ($conditionalStyles as $conditionalStyle) { |
|||
$cloned[] = clone $conditionalStyle; |
|||
} |
|||
$pSheet->setConditionalStyles(PHPExcel_Cell::stringFromColumnIndex($i) . $j, $cloned); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Update worksheet: column dimensions |
|||
$this->adjustColumnDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); |
|||
|
|||
// Update worksheet: row dimensions |
|||
$this->adjustRowDimensions($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); |
|||
|
|||
// Update worksheet: page breaks |
|||
$this->adjustPageBreaks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); |
|||
|
|||
// Update worksheet: comments |
|||
$this->adjustComments($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); |
|||
|
|||
// Update worksheet: hyperlinks |
|||
$this->adjustHyperlinks($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); |
|||
|
|||
// Update worksheet: data validations |
|||
$this->adjustDataValidations($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); |
|||
|
|||
// Update worksheet: merge cells |
|||
$this->adjustMergeCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); |
|||
|
|||
// Update worksheet: protected cells |
|||
$this->adjustProtectedCells($pSheet, $pBefore, $beforeColumnIndex, $pNumCols, $beforeRow, $pNumRows); |
|||
|
|||
// Update worksheet: autofilter |
|||
$autoFilter = $pSheet->getAutoFilter(); |
|||
$autoFilterRange = $autoFilter->getRange(); |
|||
if (!empty($autoFilterRange)) { |
|||
if ($pNumCols != 0) { |
|||
$autoFilterColumns = array_keys($autoFilter->getColumns()); |
|||
if (count($autoFilterColumns) > 0) { |
|||
sscanf($pBefore, '%[A-Z]%d', $column, $row); |
|||
$columnIndex = PHPExcel_Cell::columnIndexFromString($column); |
|||
list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($autoFilterRange); |
|||
if ($columnIndex <= $rangeEnd[0]) { |
|||
if ($pNumCols < 0) { |
|||
// If we're actually deleting any columns that fall within the autofilter range, |
|||
// then we delete any rules for those columns |
|||
$deleteColumn = $columnIndex + $pNumCols - 1; |
|||
$deleteCount = abs($pNumCols); |
|||
for ($i = 1; $i <= $deleteCount; ++$i) { |
|||
if (in_array(PHPExcel_Cell::stringFromColumnIndex($deleteColumn), $autoFilterColumns)) { |
|||
$autoFilter->clearColumn(PHPExcel_Cell::stringFromColumnIndex($deleteColumn)); |
|||
} |
|||
++$deleteColumn; |
|||
} |
|||
} |
|||
$startCol = ($columnIndex > $rangeStart[0]) ? $columnIndex : $rangeStart[0]; |
|||
|
|||
// Shuffle columns in autofilter range |
|||
if ($pNumCols > 0) { |
|||
// For insert, we shuffle from end to beginning to avoid overwriting |
|||
$startColID = PHPExcel_Cell::stringFromColumnIndex($startCol-1); |
|||
$toColID = PHPExcel_Cell::stringFromColumnIndex($startCol+$pNumCols-1); |
|||
$endColID = PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0]); |
|||
|
|||
$startColRef = $startCol; |
|||
$endColRef = $rangeEnd[0]; |
|||
$toColRef = $rangeEnd[0]+$pNumCols; |
|||
|
|||
do { |
|||
$autoFilter->shiftColumn(PHPExcel_Cell::stringFromColumnIndex($endColRef-1), PHPExcel_Cell::stringFromColumnIndex($toColRef-1)); |
|||
--$endColRef; |
|||
--$toColRef; |
|||
} while ($startColRef <= $endColRef); |
|||
} else { |
|||
// For delete, we shuffle from beginning to end to avoid overwriting |
|||
$startColID = PHPExcel_Cell::stringFromColumnIndex($startCol-1); |
|||
$toColID = PHPExcel_Cell::stringFromColumnIndex($startCol+$pNumCols-1); |
|||
$endColID = PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0]); |
|||
do { |
|||
$autoFilter->shiftColumn($startColID, $toColID); |
|||
++$startColID; |
|||
++$toColID; |
|||
} while ($startColID != $endColID); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
$pSheet->setAutoFilter($this->updateCellReference($autoFilterRange, $pBefore, $pNumCols, $pNumRows)); |
|||
} |
|||
|
|||
// Update worksheet: freeze pane |
|||
if ($pSheet->getFreezePane() != '') { |
|||
$pSheet->freezePane($this->updateCellReference($pSheet->getFreezePane(), $pBefore, $pNumCols, $pNumRows)); |
|||
} |
|||
|
|||
// Page setup |
|||
if ($pSheet->getPageSetup()->isPrintAreaSet()) { |
|||
$pSheet->getPageSetup()->setPrintArea($this->updateCellReference($pSheet->getPageSetup()->getPrintArea(), $pBefore, $pNumCols, $pNumRows)); |
|||
} |
|||
|
|||
// Update worksheet: drawings |
|||
$aDrawings = $pSheet->getDrawingCollection(); |
|||
foreach ($aDrawings as $objDrawing) { |
|||
$newReference = $this->updateCellReference($objDrawing->getCoordinates(), $pBefore, $pNumCols, $pNumRows); |
|||
if ($objDrawing->getCoordinates() != $newReference) { |
|||
$objDrawing->setCoordinates($newReference); |
|||
} |
|||
} |
|||
|
|||
// Update workbook: named ranges |
|||
if (count($pSheet->getParent()->getNamedRanges()) > 0) { |
|||
foreach ($pSheet->getParent()->getNamedRanges() as $namedRange) { |
|||
if ($namedRange->getWorksheet()->getHashCode() == $pSheet->getHashCode()) { |
|||
$namedRange->setRange($this->updateCellReference($namedRange->getRange(), $pBefore, $pNumCols, $pNumRows)); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Garbage collect |
|||
$pSheet->garbageCollect(); |
|||
} |
|||
|
|||
/** |
|||
* Update references within formulas |
|||
* |
|||
* @param string $pFormula Formula to update |
|||
* @param int $pBefore Insert before this one |
|||
* @param int $pNumCols Number of columns to insert |
|||
* @param int $pNumRows Number of rows to insert |
|||
* @param string $sheetName Worksheet name/title |
|||
* @return string Updated formula |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0, $sheetName = '') |
|||
{ |
|||
// Update cell references in the formula |
|||
$formulaBlocks = explode('"', $pFormula); |
|||
$i = false; |
|||
foreach ($formulaBlocks as &$formulaBlock) { |
|||
// Ignore blocks that were enclosed in quotes (alternating entries in the $formulaBlocks array after the explode) |
|||
if ($i = !$i) { |
|||
$adjustCount = 0; |
|||
$newCellTokens = $cellTokens = array(); |
|||
// Search for row ranges (e.g. 'Sheet1'!3:5 or 3:5) with or without $ absolutes (e.g. $3:5) |
|||
$matchCount = preg_match_all('/'.self::REFHELPER_REGEXP_ROWRANGE.'/i', ' '.$formulaBlock.' ', $matches, PREG_SET_ORDER); |
|||
if ($matchCount > 0) { |
|||
foreach ($matches as $match) { |
|||
$fromString = ($match[2] > '') ? $match[2].'!' : ''; |
|||
$fromString .= $match[3].':'.$match[4]; |
|||
$modified3 = substr($this->updateCellReference('$A'.$match[3], $pBefore, $pNumCols, $pNumRows), 2); |
|||
$modified4 = substr($this->updateCellReference('$A'.$match[4], $pBefore, $pNumCols, $pNumRows), 2); |
|||
|
|||
if ($match[3].':'.$match[4] !== $modified3.':'.$modified4) { |
|||
if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { |
|||
$toString = ($match[2] > '') ? $match[2].'!' : ''; |
|||
$toString .= $modified3.':'.$modified4; |
|||
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more |
|||
$column = 100000; |
|||
$row = 10000000 + trim($match[3], '$'); |
|||
$cellIndex = $column.$row; |
|||
|
|||
$newCellTokens[$cellIndex] = preg_quote($toString); |
|||
$cellTokens[$cellIndex] = '/(?<!\d\$\!)'.preg_quote($fromString).'(?!\d)/i'; |
|||
++$adjustCount; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
// Search for column ranges (e.g. 'Sheet1'!C:E or C:E) with or without $ absolutes (e.g. $C:E) |
|||
$matchCount = preg_match_all('/'.self::REFHELPER_REGEXP_COLRANGE.'/i', ' '.$formulaBlock.' ', $matches, PREG_SET_ORDER); |
|||
if ($matchCount > 0) { |
|||
foreach ($matches as $match) { |
|||
$fromString = ($match[2] > '') ? $match[2].'!' : ''; |
|||
$fromString .= $match[3].':'.$match[4]; |
|||
$modified3 = substr($this->updateCellReference($match[3].'$1', $pBefore, $pNumCols, $pNumRows), 0, -2); |
|||
$modified4 = substr($this->updateCellReference($match[4].'$1', $pBefore, $pNumCols, $pNumRows), 0, -2); |
|||
|
|||
if ($match[3].':'.$match[4] !== $modified3.':'.$modified4) { |
|||
if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { |
|||
$toString = ($match[2] > '') ? $match[2].'!' : ''; |
|||
$toString .= $modified3.':'.$modified4; |
|||
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more |
|||
$column = PHPExcel_Cell::columnIndexFromString(trim($match[3], '$')) + 100000; |
|||
$row = 10000000; |
|||
$cellIndex = $column.$row; |
|||
|
|||
$newCellTokens[$cellIndex] = preg_quote($toString); |
|||
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])'.preg_quote($fromString).'(?![A-Z])/i'; |
|||
++$adjustCount; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
// Search for cell ranges (e.g. 'Sheet1'!A3:C5 or A3:C5) with or without $ absolutes (e.g. $A1:C$5) |
|||
$matchCount = preg_match_all('/'.self::REFHELPER_REGEXP_CELLRANGE.'/i', ' '.$formulaBlock.' ', $matches, PREG_SET_ORDER); |
|||
if ($matchCount > 0) { |
|||
foreach ($matches as $match) { |
|||
$fromString = ($match[2] > '') ? $match[2].'!' : ''; |
|||
$fromString .= $match[3].':'.$match[4]; |
|||
$modified3 = $this->updateCellReference($match[3], $pBefore, $pNumCols, $pNumRows); |
|||
$modified4 = $this->updateCellReference($match[4], $pBefore, $pNumCols, $pNumRows); |
|||
|
|||
if ($match[3].$match[4] !== $modified3.$modified4) { |
|||
if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { |
|||
$toString = ($match[2] > '') ? $match[2].'!' : ''; |
|||
$toString .= $modified3.':'.$modified4; |
|||
list($column, $row) = PHPExcel_Cell::coordinateFromString($match[3]); |
|||
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more |
|||
$column = PHPExcel_Cell::columnIndexFromString(trim($column, '$')) + 100000; |
|||
$row = trim($row, '$') + 10000000; |
|||
$cellIndex = $column.$row; |
|||
|
|||
$newCellTokens[$cellIndex] = preg_quote($toString); |
|||
$cellTokens[$cellIndex] = '/(?<![A-Z]\$\!)'.preg_quote($fromString).'(?!\d)/i'; |
|||
++$adjustCount; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
// Search for cell references (e.g. 'Sheet1'!A3 or C5) with or without $ absolutes (e.g. $A1 or C$5) |
|||
$matchCount = preg_match_all('/'.self::REFHELPER_REGEXP_CELLREF.'/i', ' '.$formulaBlock.' ', $matches, PREG_SET_ORDER); |
|||
|
|||
if ($matchCount > 0) { |
|||
foreach ($matches as $match) { |
|||
$fromString = ($match[2] > '') ? $match[2].'!' : ''; |
|||
$fromString .= $match[3]; |
|||
|
|||
$modified3 = $this->updateCellReference($match[3], $pBefore, $pNumCols, $pNumRows); |
|||
if ($match[3] !== $modified3) { |
|||
if (($match[2] == '') || (trim($match[2], "'") == $sheetName)) { |
|||
$toString = ($match[2] > '') ? $match[2].'!' : ''; |
|||
$toString .= $modified3; |
|||
list($column, $row) = PHPExcel_Cell::coordinateFromString($match[3]); |
|||
// Max worksheet size is 1,048,576 rows by 16,384 columns in Excel 2007, so our adjustments need to be at least one digit more |
|||
$column = PHPExcel_Cell::columnIndexFromString(trim($column, '$')) + 100000; |
|||
$row = trim($row, '$') + 10000000; |
|||
$cellIndex = $row . $column; |
|||
|
|||
$newCellTokens[$cellIndex] = preg_quote($toString); |
|||
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])'.preg_quote($fromString).'(?!\d)/i'; |
|||
++$adjustCount; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if ($adjustCount > 0) { |
|||
if ($pNumCols > 0 || $pNumRows > 0) { |
|||
krsort($cellTokens); |
|||
krsort($newCellTokens); |
|||
} else { |
|||
ksort($cellTokens); |
|||
ksort($newCellTokens); |
|||
} // Update cell references in the formula |
|||
$formulaBlock = str_replace('\\', '', preg_replace($cellTokens, $newCellTokens, $formulaBlock)); |
|||
} |
|||
} |
|||
} |
|||
unset($formulaBlock); |
|||
|
|||
// Then rebuild the formula string |
|||
return implode('"', $formulaBlocks); |
|||
} |
|||
|
|||
/** |
|||
* Update cell reference |
|||
* |
|||
* @param string $pCellRange Cell range |
|||
* @param int $pBefore Insert before this one |
|||
* @param int $pNumCols Number of columns to increment |
|||
* @param int $pNumRows Number of rows to increment |
|||
* @return string Updated cell range |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function updateCellReference($pCellRange = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) |
|||
{ |
|||
// Is it in another worksheet? Will not have to update anything. |
|||
if (strpos($pCellRange, "!") !== false) { |
|||
return $pCellRange; |
|||
// Is it a range or a single cell? |
|||
} elseif (strpos($pCellRange, ':') === false && strpos($pCellRange, ',') === false) { |
|||
// Single cell |
|||
return $this->updateSingleCellReference($pCellRange, $pBefore, $pNumCols, $pNumRows); |
|||
} elseif (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) { |
|||
// Range |
|||
return $this->updateCellRange($pCellRange, $pBefore, $pNumCols, $pNumRows); |
|||
} else { |
|||
// Return original |
|||
return $pCellRange; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update named formulas (i.e. containing worksheet references / named ranges) |
|||
* |
|||
* @param PHPExcel $pPhpExcel Object to update |
|||
* @param string $oldName Old name (name to replace) |
|||
* @param string $newName New name |
|||
*/ |
|||
public function updateNamedFormulas(PHPExcel $pPhpExcel, $oldName = '', $newName = '') |
|||
{ |
|||
if ($oldName == '') { |
|||
return; |
|||
} |
|||
|
|||
foreach ($pPhpExcel->getWorksheetIterator() as $sheet) { |
|||
foreach ($sheet->getCellCollection(false) as $cellID) { |
|||
$cell = $sheet->getCell($cellID); |
|||
if (($cell !== null) && ($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_FORMULA)) { |
|||
$formula = $cell->getValue(); |
|||
if (strpos($formula, $oldName) !== false) { |
|||
$formula = str_replace("'" . $oldName . "'!", "'" . $newName . "'!", $formula); |
|||
$formula = str_replace($oldName . "!", $newName . "!", $formula); |
|||
$cell->setValueExplicit($formula, PHPExcel_Cell_DataType::TYPE_FORMULA); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update cell range |
|||
* |
|||
* @param string $pCellRange Cell range (e.g. 'B2:D4', 'B:C' or '2:3') |
|||
* @param int $pBefore Insert before this one |
|||
* @param int $pNumCols Number of columns to increment |
|||
* @param int $pNumRows Number of rows to increment |
|||
* @return string Updated cell range |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
private function updateCellRange($pCellRange = 'A1:A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) |
|||
{ |
|||
if (strpos($pCellRange, ':') !== false || strpos($pCellRange, ',') !== false) { |
|||
// Update range |
|||
$range = PHPExcel_Cell::splitRange($pCellRange); |
|||
$ic = count($range); |
|||
for ($i = 0; $i < $ic; ++$i) { |
|||
$jc = count($range[$i]); |
|||
for ($j = 0; $j < $jc; ++$j) { |
|||
if (ctype_alpha($range[$i][$j])) { |
|||
$r = PHPExcel_Cell::coordinateFromString($this->updateSingleCellReference($range[$i][$j].'1', $pBefore, $pNumCols, $pNumRows)); |
|||
$range[$i][$j] = $r[0]; |
|||
} elseif (ctype_digit($range[$i][$j])) { |
|||
$r = PHPExcel_Cell::coordinateFromString($this->updateSingleCellReference('A'.$range[$i][$j], $pBefore, $pNumCols, $pNumRows)); |
|||
$range[$i][$j] = $r[1]; |
|||
} else { |
|||
$range[$i][$j] = $this->updateSingleCellReference($range[$i][$j], $pBefore, $pNumCols, $pNumRows); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Recreate range string |
|||
return PHPExcel_Cell::buildRange($range); |
|||
} else { |
|||
throw new PHPExcel_Exception("Only cell ranges may be passed to this method."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Update single cell reference |
|||
* |
|||
* @param string $pCellReference Single cell reference |
|||
* @param int $pBefore Insert before this one |
|||
* @param int $pNumCols Number of columns to increment |
|||
* @param int $pNumRows Number of rows to increment |
|||
* @return string Updated cell reference |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
private function updateSingleCellReference($pCellReference = 'A1', $pBefore = 'A1', $pNumCols = 0, $pNumRows = 0) |
|||
{ |
|||
if (strpos($pCellReference, ':') === false && strpos($pCellReference, ',') === false) { |
|||
// Get coordinates of $pBefore |
|||
list($beforeColumn, $beforeRow) = PHPExcel_Cell::coordinateFromString($pBefore); |
|||
|
|||
// Get coordinates of $pCellReference |
|||
list($newColumn, $newRow) = PHPExcel_Cell::coordinateFromString($pCellReference); |
|||
|
|||
// Verify which parts should be updated |
|||
$updateColumn = (($newColumn{0} != '$') && ($beforeColumn{0} != '$') && (PHPExcel_Cell::columnIndexFromString($newColumn) >= PHPExcel_Cell::columnIndexFromString($beforeColumn))); |
|||
$updateRow = (($newRow{0} != '$') && ($beforeRow{0} != '$') && $newRow >= $beforeRow); |
|||
|
|||
// Create new column reference |
|||
if ($updateColumn) { |
|||
$newColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($newColumn) - 1 + $pNumCols); |
|||
} |
|||
|
|||
// Create new row reference |
|||
if ($updateRow) { |
|||
$newRow = $newRow + $pNumRows; |
|||
} |
|||
|
|||
// Return new reference |
|||
return $newColumn . $newRow; |
|||
} else { |
|||
throw new PHPExcel_Exception("Only single cell references may be passed to this method."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* __clone implementation. Cloning should not be allowed in a Singleton! |
|||
* |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
final public function __clone() |
|||
{ |
|||
throw new PHPExcel_Exception("Cloning a Singleton is not allowed!"); |
|||
} |
|||
} |
|||
@ -0,0 +1,191 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_RichText |
|||
* |
|||
* 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_RichText |
|||
* @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_RichText implements PHPExcel_IComparable |
|||
{ |
|||
/** |
|||
* Rich text elements |
|||
* |
|||
* @var PHPExcel_RichText_ITextElement[] |
|||
*/ |
|||
private $richTextElements; |
|||
|
|||
/** |
|||
* Create a new PHPExcel_RichText instance |
|||
* |
|||
* @param PHPExcel_Cell $pCell |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function __construct(PHPExcel_Cell $pCell = null) |
|||
{ |
|||
// Initialise variables |
|||
$this->richTextElements = array(); |
|||
|
|||
// Rich-Text string attached to cell? |
|||
if ($pCell !== null) { |
|||
// Add cell text and style |
|||
if ($pCell->getValue() != "") { |
|||
$objRun = new PHPExcel_RichText_Run($pCell->getValue()); |
|||
$objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont()); |
|||
$this->addText($objRun); |
|||
} |
|||
|
|||
// Set parent value |
|||
$pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Add text |
|||
* |
|||
* @param PHPExcel_RichText_ITextElement $pText Rich text element |
|||
* @throws PHPExcel_Exception |
|||
* @return PHPExcel_RichText |
|||
*/ |
|||
public function addText(PHPExcel_RichText_ITextElement $pText = null) |
|||
{ |
|||
$this->richTextElements[] = $pText; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Create text |
|||
* |
|||
* @param string $pText Text |
|||
* @return PHPExcel_RichText_TextElement |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function createText($pText = '') |
|||
{ |
|||
$objText = new PHPExcel_RichText_TextElement($pText); |
|||
$this->addText($objText); |
|||
return $objText; |
|||
} |
|||
|
|||
/** |
|||
* Create text run |
|||
* |
|||
* @param string $pText Text |
|||
* @return PHPExcel_RichText_Run |
|||
* @throws PHPExcel_Exception |
|||
*/ |
|||
public function createTextRun($pText = '') |
|||
{ |
|||
$objText = new PHPExcel_RichText_Run($pText); |
|||
$this->addText($objText); |
|||
return $objText; |
|||
} |
|||
|
|||
/** |
|||
* Get plain text |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getPlainText() |
|||
{ |
|||
// Return value |
|||
$returnValue = ''; |
|||
|
|||
// Loop through all PHPExcel_RichText_ITextElement |
|||
foreach ($this->richTextElements as $text) { |
|||
$returnValue .= $text->getText(); |
|||
} |
|||
|
|||
// Return |
|||
return $returnValue; |
|||
} |
|||
|
|||
/** |
|||
* Convert to string |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function __toString() |
|||
{ |
|||
return $this->getPlainText(); |
|||
} |
|||
|
|||
/** |
|||
* Get Rich Text elements |
|||
* |
|||
* @return PHPExcel_RichText_ITextElement[] |
|||
*/ |
|||
public function getRichTextElements() |
|||
{ |
|||
return $this->richTextElements; |
|||
} |
|||
|
|||
/** |
|||
* Set Rich Text elements |
|||
* |
|||
* @param PHPExcel_RichText_ITextElement[] $pElements Array of elements |
|||
* @throws PHPExcel_Exception |
|||
* @return PHPExcel_RichText |
|||
*/ |
|||
public function setRichTextElements($pElements = null) |
|||
{ |
|||
if (is_array($pElements)) { |
|||
$this->richTextElements = $pElements; |
|||
} else { |
|||
throw new PHPExcel_Exception("Invalid PHPExcel_RichText_ITextElement[] array passed."); |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get hash code |
|||
* |
|||
* @return string Hash code |
|||
*/ |
|||
public function getHashCode() |
|||
{ |
|||
$hashElements = ''; |
|||
foreach ($this->richTextElements as $element) { |
|||
$hashElements .= $element->getHashCode(); |
|||
} |
|||
|
|||
return md5( |
|||
$hashElements . |
|||
__CLASS__ |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
|||
*/ |
|||
public function __clone() |
|||
{ |
|||
$vars = get_object_vars($this); |
|||
foreach ($vars as $key => $value) { |
|||
if (is_object($value)) { |
|||
$this->$key = clone $value; |
|||
} else { |
|||
$this->$key = $value; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,389 @@ |
|||
<?php |
|||
|
|||
/** PHPExcel root directory */ |
|||
if (!defined('PHPEXCEL_ROOT')) { |
|||
/** |
|||
* @ignore |
|||
*/ |
|||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); |
|||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); |
|||
} |
|||
|
|||
/** |
|||
* PHPExcel_Settings |
|||
* |
|||
* 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_Settings |
|||
* @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_Settings |
|||
{ |
|||
/** constants */ |
|||
/** Available Zip library classes */ |
|||
const PCLZIP = 'PHPExcel_Shared_ZipArchive'; |
|||
const ZIPARCHIVE = 'ZipArchive'; |
|||
|
|||
/** Optional Chart Rendering libraries */ |
|||
const CHART_RENDERER_JPGRAPH = 'jpgraph'; |
|||
|
|||
/** Optional PDF Rendering libraries */ |
|||
const PDF_RENDERER_TCPDF = 'tcPDF'; |
|||
const PDF_RENDERER_DOMPDF = 'DomPDF'; |
|||
const PDF_RENDERER_MPDF = 'mPDF'; |
|||
|
|||
|
|||
private static $chartRenderers = array( |
|||
self::CHART_RENDERER_JPGRAPH, |
|||
); |
|||
|
|||
private static $pdfRenderers = array( |
|||
self::PDF_RENDERER_TCPDF, |
|||
self::PDF_RENDERER_DOMPDF, |
|||
self::PDF_RENDERER_MPDF, |
|||
); |
|||
|
|||
|
|||
/** |
|||
* Name of the class used for Zip file management |
|||
* e.g. |
|||
* ZipArchive |
|||
* |
|||
* @var string |
|||
*/ |
|||
private static $zipClass = self::ZIPARCHIVE; |
|||
|
|||
|
|||
/** |
|||
* Name of the external Library used for rendering charts |
|||
* e.g. |
|||
* jpgraph |
|||
* |
|||
* @var string |
|||
*/ |
|||
private static $chartRendererName; |
|||
|
|||
/** |
|||
* Directory Path to the external Library used for rendering charts |
|||
* |
|||
* @var string |
|||
*/ |
|||
private static $chartRendererPath; |
|||
|
|||
|
|||
/** |
|||
* Name of the external Library used for rendering PDF files |
|||
* e.g. |
|||
* mPDF |
|||
* |
|||
* @var string |
|||
*/ |
|||
private static $pdfRendererName; |
|||
|
|||
/** |
|||
* Directory Path to the external Library used for rendering PDF files |
|||
* |
|||
* @var string |
|||
*/ |
|||
private static $pdfRendererPath; |
|||
|
|||
/** |
|||
* Default options for libxml loader |
|||
* |
|||
* @var int |
|||
*/ |
|||
private static $libXmlLoaderOptions = null; |
|||
|
|||
/** |
|||
* Set the Zip handler Class that PHPExcel should use for Zip file management (PCLZip or ZipArchive) |
|||
* |
|||
* @param string $zipClass The Zip handler class that PHPExcel should use for Zip file management |
|||
* e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setZipClass($zipClass) |
|||
{ |
|||
if (($zipClass === self::PCLZIP) || |
|||
($zipClass === self::ZIPARCHIVE)) { |
|||
self::$zipClass = $zipClass; |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive) |
|||
* or Zip file management |
|||
* |
|||
* @return string Name of the Zip handler Class that PHPExcel is configured to use |
|||
* for Zip file management |
|||
* e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive |
|||
*/ |
|||
public static function getZipClass() |
|||
{ |
|||
return self::$zipClass; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Return the name of the method that is currently configured for cell cacheing |
|||
* |
|||
* @return string Name of the cacheing method |
|||
*/ |
|||
public static function getCacheStorageMethod() |
|||
{ |
|||
return PHPExcel_CachedObjectStorageFactory::getCacheStorageMethod(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Return the name of the class that is currently being used for cell cacheing |
|||
* |
|||
* @return string Name of the class currently being used for cacheing |
|||
*/ |
|||
public static function getCacheStorageClass() |
|||
{ |
|||
return PHPExcel_CachedObjectStorageFactory::getCacheStorageClass(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Set the method that should be used for cell cacheing |
|||
* |
|||
* @param string $method Name of the cacheing method |
|||
* @param array $arguments Optional configuration arguments for the cacheing method |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setCacheStorageMethod($method = PHPExcel_CachedObjectStorageFactory::cache_in_memory, $arguments = array()) |
|||
{ |
|||
return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Set the locale code to use for formula translations and any special formatting |
|||
* |
|||
* @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk") |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setLocale($locale = 'en_us') |
|||
{ |
|||
return PHPExcel_Calculation::getInstance()->setLocale($locale); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Set details of the external library that PHPExcel should use for rendering charts |
|||
* |
|||
* @param string $libraryName Internal reference name of the library |
|||
* e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH |
|||
* @param string $libraryBaseDir Directory path to the library's base folder |
|||
* |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setChartRenderer($libraryName, $libraryBaseDir) |
|||
{ |
|||
if (!self::setChartRendererName($libraryName)) { |
|||
return false; |
|||
} |
|||
return self::setChartRendererPath($libraryBaseDir); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Identify to PHPExcel the external library to use for rendering charts |
|||
* |
|||
* @param string $libraryName Internal reference name of the library |
|||
* e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH |
|||
* |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setChartRendererName($libraryName) |
|||
{ |
|||
if (!in_array($libraryName, self::$chartRenderers)) { |
|||
return false; |
|||
} |
|||
self::$chartRendererName = $libraryName; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Tell PHPExcel where to find the external library to use for rendering charts |
|||
* |
|||
* @param string $libraryBaseDir Directory path to the library's base folder |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setChartRendererPath($libraryBaseDir) |
|||
{ |
|||
if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) { |
|||
return false; |
|||
} |
|||
self::$chartRendererPath = $libraryBaseDir; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph) |
|||
* |
|||
* @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is |
|||
* currently configured to use |
|||
* e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH |
|||
*/ |
|||
public static function getChartRendererName() |
|||
{ |
|||
return self::$chartRendererName; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use |
|||
* |
|||
* @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is |
|||
* currently configured to use |
|||
*/ |
|||
public static function getChartRendererPath() |
|||
{ |
|||
return self::$chartRendererPath; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Set details of the external library that PHPExcel should use for rendering PDF files |
|||
* |
|||
* @param string $libraryName Internal reference name of the library |
|||
* e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, |
|||
* PHPExcel_Settings::PDF_RENDERER_DOMPDF |
|||
* or PHPExcel_Settings::PDF_RENDERER_MPDF |
|||
* @param string $libraryBaseDir Directory path to the library's base folder |
|||
* |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setPdfRenderer($libraryName, $libraryBaseDir) |
|||
{ |
|||
if (!self::setPdfRendererName($libraryName)) { |
|||
return false; |
|||
} |
|||
return self::setPdfRendererPath($libraryBaseDir); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Identify to PHPExcel the external library to use for rendering PDF files |
|||
* |
|||
* @param string $libraryName Internal reference name of the library |
|||
* e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, |
|||
* PHPExcel_Settings::PDF_RENDERER_DOMPDF |
|||
* or PHPExcel_Settings::PDF_RENDERER_MPDF |
|||
* |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setPdfRendererName($libraryName) |
|||
{ |
|||
if (!in_array($libraryName, self::$pdfRenderers)) { |
|||
return false; |
|||
} |
|||
self::$pdfRendererName = $libraryName; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Tell PHPExcel where to find the external library to use for rendering PDF files |
|||
* |
|||
* @param string $libraryBaseDir Directory path to the library's base folder |
|||
* @return boolean Success or failure |
|||
*/ |
|||
public static function setPdfRendererPath($libraryBaseDir) |
|||
{ |
|||
if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) { |
|||
return false; |
|||
} |
|||
self::$pdfRendererPath = $libraryBaseDir; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf) |
|||
* |
|||
* @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is |
|||
* currently configured to use |
|||
* e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, |
|||
* PHPExcel_Settings::PDF_RENDERER_DOMPDF |
|||
* or PHPExcel_Settings::PDF_RENDERER_MPDF |
|||
*/ |
|||
public static function getPdfRendererName() |
|||
{ |
|||
return self::$pdfRendererName; |
|||
} |
|||
|
|||
/** |
|||
* Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use |
|||
* |
|||
* @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is |
|||
* currently configured to use |
|||
*/ |
|||
public static function getPdfRendererPath() |
|||
{ |
|||
return self::$pdfRendererPath; |
|||
} |
|||
|
|||
/** |
|||
* Set options for libxml loader |
|||
* |
|||
* @param int $options Options for libxml loader |
|||
*/ |
|||
public static function setLibXmlLoaderOptions($options = null) |
|||
{ |
|||
if (is_null($options) && defined('LIBXML_DTDLOAD')) { |
|||
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR; |
|||
} |
|||
if (version_compare(PHP_VERSION, '5.2.11') >= 0) { |
|||
@libxml_disable_entity_loader((bool) $options); |
|||
} |
|||
self::$libXmlLoaderOptions = $options; |
|||
} |
|||
|
|||
/** |
|||
* Get defined options for libxml loader. |
|||
* Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly. |
|||
* |
|||
* @return int Default options for libxml loader |
|||
*/ |
|||
public static function getLibXmlLoaderOptions() |
|||
{ |
|||
if (is_null(self::$libXmlLoaderOptions) && defined('LIBXML_DTDLOAD')) { |
|||
self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR); |
|||
} elseif (is_null(self::$libXmlLoaderOptions)) { |
|||
self::$libXmlLoaderOptions = true; |
|||
} |
|||
if (version_compare(PHP_VERSION, '5.2.11') >= 0) { |
|||
@libxml_disable_entity_loader((bool) self::$libXmlLoaderOptions); |
|||
} |
|||
return self::$libXmlLoaderOptions; |
|||
} |
|||
} |
|||
@ -0,0 +1,644 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Style |
|||
* |
|||
* 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_Style |
|||
* @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_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable |
|||
{ |
|||
/** |
|||
* Font |
|||
* |
|||
* @var PHPExcel_Style_Font |
|||
*/ |
|||
protected $font; |
|||
|
|||
/** |
|||
* Fill |
|||
* |
|||
* @var PHPExcel_Style_Fill |
|||
*/ |
|||
protected $fill; |
|||
|
|||
/** |
|||
* Borders |
|||
* |
|||
* @var PHPExcel_Style_Borders |
|||
*/ |
|||
protected $borders; |
|||
|
|||
/** |
|||
* Alignment |
|||
* |
|||
* @var PHPExcel_Style_Alignment |
|||
*/ |
|||
protected $alignment; |
|||
|
|||
/** |
|||
* Number Format |
|||
* |
|||
* @var PHPExcel_Style_NumberFormat |
|||
*/ |
|||
protected $numberFormat; |
|||
|
|||
/** |
|||
* Conditional styles |
|||
* |
|||
* @var PHPExcel_Style_Conditional[] |
|||
*/ |
|||
protected $conditionalStyles; |
|||
|
|||
/** |
|||
* Protection |
|||
* |
|||
* @var PHPExcel_Style_Protection |
|||
*/ |
|||
protected $protection; |
|||
|
|||
/** |
|||
* Index of style in collection. Only used for real style. |
|||
* |
|||
* @var int |
|||
*/ |
|||
protected $index; |
|||
|
|||
/** |
|||
* Use Quote Prefix when displaying in cell editor. Only used for real style. |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
protected $quotePrefix = false; |
|||
|
|||
/** |
|||
* Create a new PHPExcel_Style |
|||
* |
|||
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not |
|||
* Leave this value at default unless you understand exactly what |
|||
* its ramifications are |
|||
* @param boolean $isConditional Flag indicating if this is a conditional style or not |
|||
* Leave this value at default unless you understand exactly what |
|||
* its ramifications are |
|||
*/ |
|||
public function __construct($isSupervisor = false, $isConditional = false) |
|||
{ |
|||
// Supervisor? |
|||
$this->isSupervisor = $isSupervisor; |
|||
|
|||
// Initialise values |
|||
$this->conditionalStyles = array(); |
|||
$this->font = new PHPExcel_Style_Font($isSupervisor, $isConditional); |
|||
$this->fill = new PHPExcel_Style_Fill($isSupervisor, $isConditional); |
|||
$this->borders = new PHPExcel_Style_Borders($isSupervisor, $isConditional); |
|||
$this->alignment = new PHPExcel_Style_Alignment($isSupervisor, $isConditional); |
|||
$this->numberFormat = new PHPExcel_Style_NumberFormat($isSupervisor, $isConditional); |
|||
$this->protection = new PHPExcel_Style_Protection($isSupervisor, $isConditional); |
|||
|
|||
// bind parent if we are a supervisor |
|||
if ($isSupervisor) { |
|||
$this->font->bindParent($this); |
|||
$this->fill->bindParent($this); |
|||
$this->borders->bindParent($this); |
|||
$this->alignment->bindParent($this); |
|||
$this->numberFormat->bindParent($this); |
|||
$this->protection->bindParent($this); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get the shared style component for the currently active cell in currently active sheet. |
|||
* Only used for style supervisor |
|||
* |
|||
* @return PHPExcel_Style |
|||
*/ |
|||
public function getSharedComponent() |
|||
{ |
|||
$activeSheet = $this->getActiveSheet(); |
|||
$selectedCell = $this->getActiveCell(); // e.g. 'A1' |
|||
|
|||
if ($activeSheet->cellExists($selectedCell)) { |
|||
$xfIndex = $activeSheet->getCell($selectedCell)->getXfIndex(); |
|||
} else { |
|||
$xfIndex = 0; |
|||
} |
|||
|
|||
return $this->parent->getCellXfByIndex($xfIndex); |
|||
} |
|||
|
|||
/** |
|||
* Get parent. Only used for style supervisor |
|||
* |
|||
* @return PHPExcel |
|||
*/ |
|||
public function getParent() |
|||
{ |
|||
return $this->parent; |
|||
} |
|||
|
|||
/** |
|||
* Build style array from subcomponents |
|||
* |
|||
* @param array $array |
|||
* @return array |
|||
*/ |
|||
public function getStyleArray($array) |
|||
{ |
|||
return array('quotePrefix' => $array); |
|||
} |
|||
|
|||
/** |
|||
* Apply styles from array |
|||
* |
|||
* <code> |
|||
* $objPHPExcel->getActiveSheet()->getStyle('B2')->applyFromArray( |
|||
* array( |
|||
* 'font' => array( |
|||
* 'name' => 'Arial', |
|||
* 'bold' => true, |
|||
* 'italic' => false, |
|||
* 'underline' => PHPExcel_Style_Font::UNDERLINE_DOUBLE, |
|||
* 'strike' => false, |
|||
* 'color' => array( |
|||
* 'rgb' => '808080' |
|||
* ) |
|||
* ), |
|||
* 'borders' => array( |
|||
* 'bottom' => array( |
|||
* 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, |
|||
* 'color' => array( |
|||
* 'rgb' => '808080' |
|||
* ) |
|||
* ), |
|||
* 'top' => array( |
|||
* 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, |
|||
* 'color' => array( |
|||
* 'rgb' => '808080' |
|||
* ) |
|||
* ) |
|||
* ), |
|||
* 'quotePrefix' => true |
|||
* ) |
|||
* ); |
|||
* </code> |
|||
* |
|||
* @param array $pStyles Array containing style information |
|||
* @param boolean $pAdvanced Advanced mode for setting borders. |
|||
* @throws PHPExcel_Exception |
|||
* @return PHPExcel_Style |
|||
*/ |
|||
public function applyFromArray($pStyles = null, $pAdvanced = true) |
|||
{ |
|||
if (is_array($pStyles)) { |
|||
if ($this->isSupervisor) { |
|||
$pRange = $this->getSelectedCells(); |
|||
|
|||
// Uppercase coordinate |
|||
$pRange = strtoupper($pRange); |
|||
|
|||
// Is it a cell range or a single cell? |
|||
if (strpos($pRange, ':') === false) { |
|||
$rangeA = $pRange; |
|||
$rangeB = $pRange; |
|||
} else { |
|||
list($rangeA, $rangeB) = explode(':', $pRange); |
|||
} |
|||
|
|||
// Calculate range outer borders |
|||
$rangeStart = PHPExcel_Cell::coordinateFromString($rangeA); |
|||
$rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB); |
|||
|
|||
// Translate column into index |
|||
$rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1; |
|||
$rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1; |
|||
|
|||
// Make sure we can loop upwards on rows and columns |
|||
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { |
|||
$tmp = $rangeStart; |
|||
$rangeStart = $rangeEnd; |
|||
$rangeEnd = $tmp; |
|||
} |
|||
|
|||
// ADVANCED MODE: |
|||
if ($pAdvanced && isset($pStyles['borders'])) { |
|||
// 'allborders' is a shorthand property for 'outline' and 'inside' and |
|||
// it applies to components that have not been set explicitly |
|||
if (isset($pStyles['borders']['allborders'])) { |
|||
foreach (array('outline', 'inside') as $component) { |
|||
if (!isset($pStyles['borders'][$component])) { |
|||
$pStyles['borders'][$component] = $pStyles['borders']['allborders']; |
|||
} |
|||
} |
|||
unset($pStyles['borders']['allborders']); // not needed any more |
|||
} |
|||
// 'outline' is a shorthand property for 'top', 'right', 'bottom', 'left' |
|||
// it applies to components that have not been set explicitly |
|||
if (isset($pStyles['borders']['outline'])) { |
|||
foreach (array('top', 'right', 'bottom', 'left') as $component) { |
|||
if (!isset($pStyles['borders'][$component])) { |
|||
$pStyles['borders'][$component] = $pStyles['borders']['outline']; |
|||
} |
|||
} |
|||
unset($pStyles['borders']['outline']); // not needed any more |
|||
} |
|||
// 'inside' is a shorthand property for 'vertical' and 'horizontal' |
|||
// it applies to components that have not been set explicitly |
|||
if (isset($pStyles['borders']['inside'])) { |
|||
foreach (array('vertical', 'horizontal') as $component) { |
|||
if (!isset($pStyles['borders'][$component])) { |
|||
$pStyles['borders'][$component] = $pStyles['borders']['inside']; |
|||
} |
|||
} |
|||
unset($pStyles['borders']['inside']); // not needed any more |
|||
} |
|||
// width and height characteristics of selection, 1, 2, or 3 (for 3 or more) |
|||
$xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3); |
|||
$yMax = min($rangeEnd[1] - $rangeStart[1] + 1, 3); |
|||
|
|||
// loop through up to 3 x 3 = 9 regions |
|||
for ($x = 1; $x <= $xMax; ++$x) { |
|||
// start column index for region |
|||
$colStart = ($x == 3) ? |
|||
PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0]) |
|||
: PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] + $x - 1); |
|||
// end column index for region |
|||
$colEnd = ($x == 1) ? |
|||
PHPExcel_Cell::stringFromColumnIndex($rangeStart[0]) |
|||
: PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] - $xMax + $x); |
|||
|
|||
for ($y = 1; $y <= $yMax; ++$y) { |
|||
// which edges are touching the region |
|||
$edges = array(); |
|||
if ($x == 1) { |
|||
// are we at left edge |
|||
$edges[] = 'left'; |
|||
} |
|||
if ($x == $xMax) { |
|||
// are we at right edge |
|||
$edges[] = 'right'; |
|||
} |
|||
if ($y == 1) { |
|||
// are we at top edge? |
|||
$edges[] = 'top'; |
|||
} |
|||
if ($y == $yMax) { |
|||
// are we at bottom edge? |
|||
$edges[] = 'bottom'; |
|||
} |
|||
|
|||
// start row index for region |
|||
$rowStart = ($y == 3) ? |
|||
$rangeEnd[1] : $rangeStart[1] + $y - 1; |
|||
|
|||
// end row index for region |
|||
$rowEnd = ($y == 1) ? |
|||
$rangeStart[1] : $rangeEnd[1] - $yMax + $y; |
|||
|
|||
// build range for region |
|||
$range = $colStart . $rowStart . ':' . $colEnd . $rowEnd; |
|||
|
|||
// retrieve relevant style array for region |
|||
$regionStyles = $pStyles; |
|||
unset($regionStyles['borders']['inside']); |
|||
|
|||
// what are the inner edges of the region when looking at the selection |
|||
$innerEdges = array_diff(array('top', 'right', 'bottom', 'left'), $edges); |
|||
|
|||
// inner edges that are not touching the region should take the 'inside' border properties if they have been set |
|||
foreach ($innerEdges as $innerEdge) { |
|||
switch ($innerEdge) { |
|||
case 'top': |
|||
case 'bottom': |
|||
// should pick up 'horizontal' border property if set |
|||
if (isset($pStyles['borders']['horizontal'])) { |
|||
$regionStyles['borders'][$innerEdge] = $pStyles['borders']['horizontal']; |
|||
} else { |
|||
unset($regionStyles['borders'][$innerEdge]); |
|||
} |
|||
break; |
|||
case 'left': |
|||
case 'right': |
|||
// should pick up 'vertical' border property if set |
|||
if (isset($pStyles['borders']['vertical'])) { |
|||
$regionStyles['borders'][$innerEdge] = $pStyles['borders']['vertical']; |
|||
} else { |
|||
unset($regionStyles['borders'][$innerEdge]); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// apply region style to region by calling applyFromArray() in simple mode |
|||
$this->getActiveSheet()->getStyle($range)->applyFromArray($regionStyles, false); |
|||
} |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
// SIMPLE MODE: |
|||
// Selection type, inspect |
|||
if (preg_match('/^[A-Z]+1:[A-Z]+1048576$/', $pRange)) { |
|||
$selectionType = 'COLUMN'; |
|||
} elseif (preg_match('/^A[0-9]+:XFD[0-9]+$/', $pRange)) { |
|||
$selectionType = 'ROW'; |
|||
} else { |
|||
$selectionType = 'CELL'; |
|||
} |
|||
|
|||
// First loop through columns, rows, or cells to find out which styles are affected by this operation |
|||
switch ($selectionType) { |
|||
case 'COLUMN': |
|||
$oldXfIndexes = array(); |
|||
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { |
|||
$oldXfIndexes[$this->getActiveSheet()->getColumnDimensionByColumn($col)->getXfIndex()] = true; |
|||
} |
|||
break; |
|||
case 'ROW': |
|||
$oldXfIndexes = array(); |
|||
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { |
|||
if ($this->getActiveSheet()->getRowDimension($row)->getXfIndex() == null) { |
|||
$oldXfIndexes[0] = true; // row without explicit style should be formatted based on default style |
|||
} else { |
|||
$oldXfIndexes[$this->getActiveSheet()->getRowDimension($row)->getXfIndex()] = true; |
|||
} |
|||
} |
|||
break; |
|||
case 'CELL': |
|||
$oldXfIndexes = array(); |
|||
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { |
|||
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { |
|||
$oldXfIndexes[$this->getActiveSheet()->getCellByColumnAndRow($col, $row)->getXfIndex()] = true; |
|||
} |
|||
} |
|||
break; |
|||
} |
|||
|
|||
// clone each of the affected styles, apply the style array, and add the new styles to the workbook |
|||
$workbook = $this->getActiveSheet()->getParent(); |
|||
foreach ($oldXfIndexes as $oldXfIndex => $dummy) { |
|||
$style = $workbook->getCellXfByIndex($oldXfIndex); |
|||
$newStyle = clone $style; |
|||
$newStyle->applyFromArray($pStyles); |
|||
|
|||
if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) { |
|||
// there is already such cell Xf in our collection |
|||
$newXfIndexes[$oldXfIndex] = $existingStyle->getIndex(); |
|||
} else { |
|||
// we don't have such a cell Xf, need to add |
|||
$workbook->addCellXf($newStyle); |
|||
$newXfIndexes[$oldXfIndex] = $newStyle->getIndex(); |
|||
} |
|||
} |
|||
|
|||
// Loop through columns, rows, or cells again and update the XF index |
|||
switch ($selectionType) { |
|||
case 'COLUMN': |
|||
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { |
|||
$columnDimension = $this->getActiveSheet()->getColumnDimensionByColumn($col); |
|||
$oldXfIndex = $columnDimension->getXfIndex(); |
|||
$columnDimension->setXfIndex($newXfIndexes[$oldXfIndex]); |
|||
} |
|||
break; |
|||
|
|||
case 'ROW': |
|||
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { |
|||
$rowDimension = $this->getActiveSheet()->getRowDimension($row); |
|||
$oldXfIndex = $rowDimension->getXfIndex() === null ? |
|||
0 : $rowDimension->getXfIndex(); // row without explicit style should be formatted based on default style |
|||
$rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]); |
|||
} |
|||
break; |
|||
|
|||
case 'CELL': |
|||
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { |
|||
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { |
|||
$cell = $this->getActiveSheet()->getCellByColumnAndRow($col, $row); |
|||
$oldXfIndex = $cell->getXfIndex(); |
|||
$cell->setXfIndex($newXfIndexes[$oldXfIndex]); |
|||
} |
|||
} |
|||
break; |
|||
} |
|||
|
|||
} else { |
|||
// not a supervisor, just apply the style array directly on style object |
|||
if (array_key_exists('fill', $pStyles)) { |
|||
$this->getFill()->applyFromArray($pStyles['fill']); |
|||
} |
|||
if (array_key_exists('font', $pStyles)) { |
|||
$this->getFont()->applyFromArray($pStyles['font']); |
|||
} |
|||
if (array_key_exists('borders', $pStyles)) { |
|||
$this->getBorders()->applyFromArray($pStyles['borders']); |
|||
} |
|||
if (array_key_exists('alignment', $pStyles)) { |
|||
$this->getAlignment()->applyFromArray($pStyles['alignment']); |
|||
} |
|||
if (array_key_exists('numberformat', $pStyles)) { |
|||
$this->getNumberFormat()->applyFromArray($pStyles['numberformat']); |
|||
} |
|||
if (array_key_exists('protection', $pStyles)) { |
|||
$this->getProtection()->applyFromArray($pStyles['protection']); |
|||
} |
|||
if (array_key_exists('quotePrefix', $pStyles)) { |
|||
$this->quotePrefix = $pStyles['quotePrefix']; |
|||
} |
|||
} |
|||
} else { |
|||
throw new PHPExcel_Exception("Invalid style array passed."); |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Fill |
|||
* |
|||
* @return PHPExcel_Style_Fill |
|||
*/ |
|||
public function getFill() |
|||
{ |
|||
return $this->fill; |
|||
} |
|||
|
|||
/** |
|||
* Get Font |
|||
* |
|||
* @return PHPExcel_Style_Font |
|||
*/ |
|||
public function getFont() |
|||
{ |
|||
return $this->font; |
|||
} |
|||
|
|||
/** |
|||
* Set font |
|||
* |
|||
* @param PHPExcel_Style_Font $font |
|||
* @return PHPExcel_Style |
|||
*/ |
|||
public function setFont(PHPExcel_Style_Font $font) |
|||
{ |
|||
$this->font = $font; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Borders |
|||
* |
|||
* @return PHPExcel_Style_Borders |
|||
*/ |
|||
public function getBorders() |
|||
{ |
|||
return $this->borders; |
|||
} |
|||
|
|||
/** |
|||
* Get Alignment |
|||
* |
|||
* @return PHPExcel_Style_Alignment |
|||
*/ |
|||
public function getAlignment() |
|||
{ |
|||
return $this->alignment; |
|||
} |
|||
|
|||
/** |
|||
* Get Number Format |
|||
* |
|||
* @return PHPExcel_Style_NumberFormat |
|||
*/ |
|||
public function getNumberFormat() |
|||
{ |
|||
return $this->numberFormat; |
|||
} |
|||
|
|||
/** |
|||
* Get Conditional Styles. Only used on supervisor. |
|||
* |
|||
* @return PHPExcel_Style_Conditional[] |
|||
*/ |
|||
public function getConditionalStyles() |
|||
{ |
|||
return $this->getActiveSheet()->getConditionalStyles($this->getActiveCell()); |
|||
} |
|||
|
|||
/** |
|||
* Set Conditional Styles. Only used on supervisor. |
|||
* |
|||
* @param PHPExcel_Style_Conditional[] $pValue Array of condtional styles |
|||
* @return PHPExcel_Style |
|||
*/ |
|||
public function setConditionalStyles($pValue = null) |
|||
{ |
|||
if (is_array($pValue)) { |
|||
$this->getActiveSheet()->setConditionalStyles($this->getSelectedCells(), $pValue); |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Protection |
|||
* |
|||
* @return PHPExcel_Style_Protection |
|||
*/ |
|||
public function getProtection() |
|||
{ |
|||
return $this->protection; |
|||
} |
|||
|
|||
/** |
|||
* Get quote prefix |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getQuotePrefix() |
|||
{ |
|||
if ($this->isSupervisor) { |
|||
return $this->getSharedComponent()->getQuotePrefix(); |
|||
} |
|||
return $this->quotePrefix; |
|||
} |
|||
|
|||
/** |
|||
* Set quote prefix |
|||
* |
|||
* @param boolean $pValue |
|||
*/ |
|||
public function setQuotePrefix($pValue) |
|||
{ |
|||
if ($pValue == '') { |
|||
$pValue = false; |
|||
} |
|||
if ($this->isSupervisor) { |
|||
$styleArray = array('quotePrefix' => $pValue); |
|||
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray); |
|||
} else { |
|||
$this->quotePrefix = (boolean) $pValue; |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get hash code |
|||
* |
|||
* @return string Hash code |
|||
*/ |
|||
public function getHashCode() |
|||
{ |
|||
$hashConditionals = ''; |
|||
foreach ($this->conditionalStyles as $conditional) { |
|||
$hashConditionals .= $conditional->getHashCode(); |
|||
} |
|||
|
|||
return md5( |
|||
$this->fill->getHashCode() . |
|||
$this->font->getHashCode() . |
|||
$this->borders->getHashCode() . |
|||
$this->alignment->getHashCode() . |
|||
$this->numberFormat->getHashCode() . |
|||
$hashConditionals . |
|||
$this->protection->getHashCode() . |
|||
($this->quotePrefix ? 't' : 'f') . |
|||
__CLASS__ |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* Get own index in style collection |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function getIndex() |
|||
{ |
|||
return $this->index; |
|||
} |
|||
|
|||
/** |
|||
* Set own index in style collection |
|||
* |
|||
* @param int $pValue |
|||
*/ |
|||
public function setIndex($pValue) |
|||
{ |
|||
$this->index = $pValue; |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,108 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_WorksheetIterator |
|||
* |
|||
* 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_WorksheetIterator implements Iterator |
|||
{ |
|||
/** |
|||
* Spreadsheet to iterate |
|||
* |
|||
* @var PHPExcel |
|||
*/ |
|||
private $subject; |
|||
|
|||
/** |
|||
* Current iterator position |
|||
* |
|||
* @var int |
|||
*/ |
|||
private $position = 0; |
|||
|
|||
/** |
|||
* Create a new worksheet iterator |
|||
* |
|||
* @param PHPExcel $subject |
|||
*/ |
|||
public function __construct(PHPExcel $subject = null) |
|||
{ |
|||
// Set subject |
|||
$this->subject = $subject; |
|||
} |
|||
|
|||
/** |
|||
* Destructor |
|||
*/ |
|||
public function __destruct() |
|||
{ |
|||
unset($this->subject); |
|||
} |
|||
|
|||
/** |
|||
* Rewind iterator |
|||
*/ |
|||
public function rewind() |
|||
{ |
|||
$this->position = 0; |
|||
} |
|||
|
|||
/** |
|||
* Current PHPExcel_Worksheet |
|||
* |
|||
* @return PHPExcel_Worksheet |
|||
*/ |
|||
public function current() |
|||
{ |
|||
return $this->subject->getSheet($this->position); |
|||
} |
|||
|
|||
/** |
|||
* Current key |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function key() |
|||
{ |
|||
return $this->position; |
|||
} |
|||
|
|||
/** |
|||
* Next value |
|||
*/ |
|||
public function next() |
|||
{ |
|||
++$this->position; |
|||
} |
|||
|
|||
/** |
|||
* More PHPExcel_Worksheet instances available? |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function valid() |
|||
{ |
|||
return $this->position < $this->subject->getSheetCount(); |
|||
} |
|||
} |
|||
@ -0,0 +1,157 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Abstract |
|||
* |
|||
* 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 |
|||
* @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## |
|||
*/ |
|||
abstract class PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* Write charts that are defined in the workbook? |
|||
* Identifies whether the Writer should write definitions for any charts that exist in the PHPExcel object; |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
protected $includeCharts = false; |
|||
|
|||
/** |
|||
* Pre-calculate formulas |
|||
* Forces PHPExcel to recalculate all formulae in a workbook when saving, so that the pre-calculated values are |
|||
* immediately available to MS Excel or other office spreadsheet viewer when opening the file |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
protected $preCalculateFormulas = true; |
|||
|
|||
/** |
|||
* Use disk caching where possible? |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
protected $_useDiskCaching = false; |
|||
|
|||
/** |
|||
* Disk caching directory |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $_diskCachingDirectory = './'; |
|||
|
|||
/** |
|||
* Write charts in workbook? |
|||
* If this is true, then the Writer will write definitions for any charts that exist in the PHPExcel object. |
|||
* If false (the default) it will ignore any charts defined in the PHPExcel object. |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getIncludeCharts() |
|||
{ |
|||
return $this->includeCharts; |
|||
} |
|||
|
|||
/** |
|||
* Set write charts in workbook |
|||
* Set to true, to advise the Writer to include any charts that exist in the PHPExcel object. |
|||
* Set to false (the default) to ignore charts. |
|||
* |
|||
* @param boolean $pValue |
|||
* @return PHPExcel_Writer_IWriter |
|||
*/ |
|||
public function setIncludeCharts($pValue = false) |
|||
{ |
|||
$this->includeCharts = (boolean) $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Pre-Calculate Formulas flag |
|||
* If this is true (the default), then the writer will recalculate all formulae in a workbook when saving, |
|||
* so that the pre-calculated values are immediately available to MS Excel or other office spreadsheet |
|||
* viewer when opening the file |
|||
* If false, then formulae are not calculated on save. This is faster for saving in PHPExcel, but slower |
|||
* when opening the resulting file in MS Excel, because Excel has to recalculate the formulae itself |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getPreCalculateFormulas() |
|||
{ |
|||
return $this->preCalculateFormulas; |
|||
} |
|||
|
|||
/** |
|||
* Set Pre-Calculate Formulas |
|||
* Set to true (the default) to advise the Writer to calculate all formulae on save |
|||
* Set to false to prevent precalculation of formulae on save. |
|||
* |
|||
* @param boolean $pValue Pre-Calculate Formulas? |
|||
* @return PHPExcel_Writer_IWriter |
|||
*/ |
|||
public function setPreCalculateFormulas($pValue = true) |
|||
{ |
|||
$this->preCalculateFormulas = (boolean) $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get use disk caching where possible? |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getUseDiskCaching() |
|||
{ |
|||
return $this->_useDiskCaching; |
|||
} |
|||
|
|||
/** |
|||
* Set use disk caching where possible? |
|||
* |
|||
* @param boolean $pValue |
|||
* @param string $pDirectory Disk caching directory |
|||
* @throws PHPExcel_Writer_Exception when directory does not exist |
|||
* @return PHPExcel_Writer_Excel2007 |
|||
*/ |
|||
public function setUseDiskCaching($pValue = false, $pDirectory = null) |
|||
{ |
|||
$this->_useDiskCaching = $pValue; |
|||
|
|||
if ($pDirectory !== null) { |
|||
if (is_dir($pDirectory)) { |
|||
$this->_diskCachingDirectory = $pDirectory; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Directory does not exist: $pDirectory"); |
|||
} |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get disk caching directory |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getDiskCachingDirectory() |
|||
{ |
|||
return $this->_diskCachingDirectory; |
|||
} |
|||
} |
|||
@ -0,0 +1,352 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_CSV |
|||
* |
|||
* 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_CSV |
|||
* @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_CSV extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* PHPExcel object |
|||
* |
|||
* @var PHPExcel |
|||
*/ |
|||
private $phpExcel; |
|||
|
|||
/** |
|||
* Delimiter |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $delimiter = ','; |
|||
|
|||
/** |
|||
* Enclosure |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $enclosure = '"'; |
|||
|
|||
/** |
|||
* Line ending |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $lineEnding = PHP_EOL; |
|||
|
|||
/** |
|||
* Sheet index to write |
|||
* |
|||
* @var int |
|||
*/ |
|||
private $sheetIndex = 0; |
|||
|
|||
/** |
|||
* Whether to write a BOM (for UTF8). |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $useBOM = false; |
|||
|
|||
/** |
|||
* Whether to write a Separator line as the first line of the file |
|||
* sep=x |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $includeSeparatorLine = false; |
|||
|
|||
/** |
|||
* Whether to write a fully Excel compatible CSV file. |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $excelCompatibility = false; |
|||
|
|||
/** |
|||
* Create a new PHPExcel_Writer_CSV |
|||
* |
|||
* @param PHPExcel $phpExcel PHPExcel object |
|||
*/ |
|||
public function __construct(PHPExcel $phpExcel) |
|||
{ |
|||
$this->phpExcel = $phpExcel; |
|||
} |
|||
|
|||
/** |
|||
* Save PHPExcel to file |
|||
* |
|||
* @param string $pFilename |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function save($pFilename = null) |
|||
{ |
|||
// Fetch sheet |
|||
$sheet = $this->phpExcel->getSheet($this->sheetIndex); |
|||
|
|||
$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); |
|||
|
|||
// Open file |
|||
$fileHandle = fopen($pFilename, 'wb+'); |
|||
if ($fileHandle === false) { |
|||
throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing."); |
|||
} |
|||
|
|||
if ($this->excelCompatibility) { |
|||
$this->setUseBOM(true); // Enforce UTF-8 BOM Header |
|||
$this->setIncludeSeparatorLine(true); // Set separator line |
|||
$this->setEnclosure('"'); // Set enclosure to " |
|||
$this->setDelimiter(";"); // Set delimiter to a semi-colon |
|||
$this->setLineEnding("\r\n"); |
|||
} |
|||
if ($this->useBOM) { |
|||
// Write the UTF-8 BOM code if required |
|||
fwrite($fileHandle, "\xEF\xBB\xBF"); |
|||
} |
|||
if ($this->includeSeparatorLine) { |
|||
// Write the separator line if required |
|||
fwrite($fileHandle, 'sep=' . $this->getDelimiter() . $this->lineEnding); |
|||
} |
|||
|
|||
// Identify the range that we need to extract from the worksheet |
|||
$maxCol = $sheet->getHighestDataColumn(); |
|||
$maxRow = $sheet->getHighestDataRow(); |
|||
|
|||
// Write rows to file |
|||
for ($row = 1; $row <= $maxRow; ++$row) { |
|||
// Convert the row to an array... |
|||
$cellsArray = $sheet->rangeToArray('A'.$row.':'.$maxCol.$row, '', $this->preCalculateFormulas); |
|||
// ... and write to the file |
|||
$this->writeLine($fileHandle, $cellsArray[0]); |
|||
} |
|||
|
|||
// Close file |
|||
fclose($fileHandle); |
|||
|
|||
PHPExcel_Calculation::setArrayReturnType($saveArrayReturnType); |
|||
PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog); |
|||
} |
|||
|
|||
/** |
|||
* Get delimiter |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getDelimiter() |
|||
{ |
|||
return $this->delimiter; |
|||
} |
|||
|
|||
/** |
|||
* Set delimiter |
|||
* |
|||
* @param string $pValue Delimiter, defaults to , |
|||
* @return PHPExcel_Writer_CSV |
|||
*/ |
|||
public function setDelimiter($pValue = ',') |
|||
{ |
|||
$this->delimiter = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get enclosure |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getEnclosure() |
|||
{ |
|||
return $this->enclosure; |
|||
} |
|||
|
|||
/** |
|||
* Set enclosure |
|||
* |
|||
* @param string $pValue Enclosure, defaults to " |
|||
* @return PHPExcel_Writer_CSV |
|||
*/ |
|||
public function setEnclosure($pValue = '"') |
|||
{ |
|||
if ($pValue == '') { |
|||
$pValue = null; |
|||
} |
|||
$this->enclosure = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get line ending |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getLineEnding() |
|||
{ |
|||
return $this->lineEnding; |
|||
} |
|||
|
|||
/** |
|||
* Set line ending |
|||
* |
|||
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL) |
|||
* @return PHPExcel_Writer_CSV |
|||
*/ |
|||
public function setLineEnding($pValue = PHP_EOL) |
|||
{ |
|||
$this->lineEnding = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get whether BOM should be used |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getUseBOM() |
|||
{ |
|||
return $this->useBOM; |
|||
} |
|||
|
|||
/** |
|||
* Set whether BOM should be used |
|||
* |
|||
* @param boolean $pValue Use UTF-8 byte-order mark? Defaults to false |
|||
* @return PHPExcel_Writer_CSV |
|||
*/ |
|||
public function setUseBOM($pValue = false) |
|||
{ |
|||
$this->useBOM = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get whether a separator line should be included |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getIncludeSeparatorLine() |
|||
{ |
|||
return $this->includeSeparatorLine; |
|||
} |
|||
|
|||
/** |
|||
* Set whether a separator line should be included as the first line of the file |
|||
* |
|||
* @param boolean $pValue Use separator line? Defaults to false |
|||
* @return PHPExcel_Writer_CSV |
|||
*/ |
|||
public function setIncludeSeparatorLine($pValue = false) |
|||
{ |
|||
$this->includeSeparatorLine = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get whether the file should be saved with full Excel Compatibility |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getExcelCompatibility() |
|||
{ |
|||
return $this->excelCompatibility; |
|||
} |
|||
|
|||
/** |
|||
* Set whether the file should be saved with full Excel Compatibility |
|||
* |
|||
* @param boolean $pValue Set the file to be written as a fully Excel compatible csv file |
|||
* Note that this overrides other settings such as useBOM, enclosure and delimiter |
|||
* @return PHPExcel_Writer_CSV |
|||
*/ |
|||
public function setExcelCompatibility($pValue = false) |
|||
{ |
|||
$this->excelCompatibility = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get sheet index |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function getSheetIndex() |
|||
{ |
|||
return $this->sheetIndex; |
|||
} |
|||
|
|||
/** |
|||
* Set sheet index |
|||
* |
|||
* @param int $pValue Sheet index |
|||
* @return PHPExcel_Writer_CSV |
|||
*/ |
|||
public function setSheetIndex($pValue = 0) |
|||
{ |
|||
$this->sheetIndex = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Write line to CSV file |
|||
* |
|||
* @param mixed $pFileHandle PHP filehandle |
|||
* @param array $pValues Array containing values in a row |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeLine($pFileHandle = null, $pValues = null) |
|||
{ |
|||
if (is_array($pValues)) { |
|||
// No leading delimiter |
|||
$writeDelimiter = false; |
|||
|
|||
// Build the line |
|||
$line = ''; |
|||
|
|||
foreach ($pValues as $element) { |
|||
// Escape enclosures |
|||
$element = str_replace($this->enclosure, $this->enclosure . $this->enclosure, $element); |
|||
|
|||
// Add delimiter |
|||
if ($writeDelimiter) { |
|||
$line .= $this->delimiter; |
|||
} else { |
|||
$writeDelimiter = true; |
|||
} |
|||
|
|||
// Add enclosed string |
|||
$line .= $this->enclosure . $element . $this->enclosure; |
|||
} |
|||
|
|||
// Add line ending |
|||
$line .= $this->lineEnding; |
|||
|
|||
// Write to file |
|||
fwrite($pFileHandle, $line); |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Invalid data row passed to CSV writer."); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,533 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007 |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007 extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* Pre-calculate formulas |
|||
* Forces PHPExcel to recalculate all formulae in a workbook when saving, so that the pre-calculated values are |
|||
* immediately available to MS Excel or other office spreadsheet viewer when opening the file |
|||
* |
|||
* Overrides the default TRUE for this specific writer for performance reasons |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
protected $preCalculateFormulas = false; |
|||
|
|||
/** |
|||
* Office2003 compatibility |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $office2003compatibility = false; |
|||
|
|||
/** |
|||
* Private writer parts |
|||
* |
|||
* @var PHPExcel_Writer_Excel2007_WriterPart[] |
|||
*/ |
|||
private $writerParts = array(); |
|||
|
|||
/** |
|||
* Private PHPExcel |
|||
* |
|||
* @var PHPExcel |
|||
*/ |
|||
private $spreadSheet; |
|||
|
|||
/** |
|||
* Private string table |
|||
* |
|||
* @var string[] |
|||
*/ |
|||
private $stringTable = array(); |
|||
|
|||
/** |
|||
* Private unique PHPExcel_Style_Conditional HashTable |
|||
* |
|||
* @var PHPExcel_HashTable |
|||
*/ |
|||
private $stylesConditionalHashTable; |
|||
|
|||
/** |
|||
* Private unique PHPExcel_Style HashTable |
|||
* |
|||
* @var PHPExcel_HashTable |
|||
*/ |
|||
private $styleHashTable; |
|||
|
|||
/** |
|||
* Private unique PHPExcel_Style_Fill HashTable |
|||
* |
|||
* @var PHPExcel_HashTable |
|||
*/ |
|||
private $fillHashTable; |
|||
|
|||
/** |
|||
* Private unique PHPExcel_Style_Font HashTable |
|||
* |
|||
* @var PHPExcel_HashTable |
|||
*/ |
|||
private $fontHashTable; |
|||
|
|||
/** |
|||
* Private unique PHPExcel_Style_Borders HashTable |
|||
* |
|||
* @var PHPExcel_HashTable |
|||
*/ |
|||
private $bordersHashTable ; |
|||
|
|||
/** |
|||
* Private unique PHPExcel_Style_NumberFormat HashTable |
|||
* |
|||
* @var PHPExcel_HashTable |
|||
*/ |
|||
private $numFmtHashTable; |
|||
|
|||
/** |
|||
* Private unique PHPExcel_Worksheet_BaseDrawing HashTable |
|||
* |
|||
* @var PHPExcel_HashTable |
|||
*/ |
|||
private $drawingHashTable; |
|||
|
|||
/** |
|||
* Create a new PHPExcel_Writer_Excel2007 |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
*/ |
|||
public function __construct(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Assign PHPExcel |
|||
$this->setPHPExcel($pPHPExcel); |
|||
|
|||
$writerPartsArray = array( 'stringtable' => 'PHPExcel_Writer_Excel2007_StringTable', |
|||
'contenttypes' => 'PHPExcel_Writer_Excel2007_ContentTypes', |
|||
'docprops' => 'PHPExcel_Writer_Excel2007_DocProps', |
|||
'rels' => 'PHPExcel_Writer_Excel2007_Rels', |
|||
'theme' => 'PHPExcel_Writer_Excel2007_Theme', |
|||
'style' => 'PHPExcel_Writer_Excel2007_Style', |
|||
'workbook' => 'PHPExcel_Writer_Excel2007_Workbook', |
|||
'worksheet' => 'PHPExcel_Writer_Excel2007_Worksheet', |
|||
'drawing' => 'PHPExcel_Writer_Excel2007_Drawing', |
|||
'comments' => 'PHPExcel_Writer_Excel2007_Comments', |
|||
'chart' => 'PHPExcel_Writer_Excel2007_Chart', |
|||
'relsvba' => 'PHPExcel_Writer_Excel2007_RelsVBA', |
|||
'relsribbonobjects' => 'PHPExcel_Writer_Excel2007_RelsRibbon' |
|||
); |
|||
|
|||
// Initialise writer parts |
|||
// and Assign their parent IWriters |
|||
foreach ($writerPartsArray as $writer => $class) { |
|||
$this->writerParts[$writer] = new $class($this); |
|||
} |
|||
|
|||
$hashTablesArray = array( 'stylesConditionalHashTable', 'fillHashTable', 'fontHashTable', |
|||
'bordersHashTable', 'numFmtHashTable', 'drawingHashTable', |
|||
'styleHashTable' |
|||
); |
|||
|
|||
// Set HashTable variables |
|||
foreach ($hashTablesArray as $tableName) { |
|||
$this->$tableName = new PHPExcel_HashTable(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get writer part |
|||
* |
|||
* @param string $pPartName Writer part name |
|||
* @return PHPExcel_Writer_Excel2007_WriterPart |
|||
*/ |
|||
public function getWriterPart($pPartName = '') |
|||
{ |
|||
if ($pPartName != '' && isset($this->writerParts[strtolower($pPartName)])) { |
|||
return $this->writerParts[strtolower($pPartName)]; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Save PHPExcel to file |
|||
* |
|||
* @param string $pFilename |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function save($pFilename = null) |
|||
{ |
|||
if ($this->spreadSheet !== null) { |
|||
// garbage collect |
|||
$this->spreadSheet->garbageCollect(); |
|||
|
|||
// If $pFilename is php://output or php://stdout, make it a temporary file... |
|||
$originalFilename = $pFilename; |
|||
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { |
|||
$pFilename = @tempnam(PHPExcel_Shared_File::sys_get_temp_dir(), 'phpxltmp'); |
|||
if ($pFilename == '') { |
|||
$pFilename = $originalFilename; |
|||
} |
|||
} |
|||
|
|||
$saveDebugLog = PHPExcel_Calculation::getInstance($this->spreadSheet)->getDebugLog()->getWriteDebugLog(); |
|||
PHPExcel_Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog(false); |
|||
$saveDateReturnType = PHPExcel_Calculation_Functions::getReturnDateType(); |
|||
PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL); |
|||
|
|||
// Create string lookup table |
|||
$this->stringTable = array(); |
|||
for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) { |
|||
$this->stringTable = $this->getWriterPart('StringTable')->createStringTable($this->spreadSheet->getSheet($i), $this->stringTable); |
|||
} |
|||
|
|||
// Create styles dictionaries |
|||
$this->styleHashTable->addFromSource($this->getWriterPart('Style')->allStyles($this->spreadSheet)); |
|||
$this->stylesConditionalHashTable->addFromSource($this->getWriterPart('Style')->allConditionalStyles($this->spreadSheet)); |
|||
$this->fillHashTable->addFromSource($this->getWriterPart('Style')->allFills($this->spreadSheet)); |
|||
$this->fontHashTable->addFromSource($this->getWriterPart('Style')->allFonts($this->spreadSheet)); |
|||
$this->bordersHashTable->addFromSource($this->getWriterPart('Style')->allBorders($this->spreadSheet)); |
|||
$this->numFmtHashTable->addFromSource($this->getWriterPart('Style')->allNumberFormats($this->spreadSheet)); |
|||
|
|||
// Create drawing dictionary |
|||
$this->drawingHashTable->addFromSource($this->getWriterPart('Drawing')->allDrawings($this->spreadSheet)); |
|||
|
|||
// Create new ZIP file and open it for writing |
|||
$zipClass = PHPExcel_Settings::getZipClass(); |
|||
$objZip = new $zipClass(); |
|||
|
|||
// Retrieve OVERWRITE and CREATE constants from the instantiated zip class |
|||
// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP |
|||
$ro = new ReflectionObject($objZip); |
|||
$zipOverWrite = $ro->getConstant('OVERWRITE'); |
|||
$zipCreate = $ro->getConstant('CREATE'); |
|||
|
|||
if (file_exists($pFilename)) { |
|||
unlink($pFilename); |
|||
} |
|||
// Try opening the ZIP file |
|||
if ($objZip->open($pFilename, $zipOverWrite) !== true) { |
|||
if ($objZip->open($pFilename, $zipCreate) !== true) { |
|||
throw new PHPExcel_Writer_Exception("Could not open " . $pFilename . " for writing."); |
|||
} |
|||
} |
|||
|
|||
// Add [Content_Types].xml to ZIP file |
|||
$objZip->addFromString('[Content_Types].xml', $this->getWriterPart('ContentTypes')->writeContentTypes($this->spreadSheet, $this->includeCharts)); |
|||
|
|||
//if hasMacros, add the vbaProject.bin file, Certificate file(if exists) |
|||
if ($this->spreadSheet->hasMacros()) { |
|||
$macrosCode=$this->spreadSheet->getMacrosCode(); |
|||
if (!is_null($macrosCode)) {// we have the code ? |
|||
$objZip->addFromString('xl/vbaProject.bin', $macrosCode);//allways in 'xl', allways named vbaProject.bin |
|||
if ($this->spreadSheet->hasMacrosCertificate()) {//signed macros ? |
|||
// Yes : add the certificate file and the related rels file |
|||
$objZip->addFromString('xl/vbaProjectSignature.bin', $this->spreadSheet->getMacrosCertificate()); |
|||
$objZip->addFromString('xl/_rels/vbaProject.bin.rels', $this->getWriterPart('RelsVBA')->writeVBARelationships($this->spreadSheet)); |
|||
} |
|||
} |
|||
} |
|||
//a custom UI in this workbook ? add it ("base" xml and additional objects (pictures) and rels) |
|||
if ($this->spreadSheet->hasRibbon()) { |
|||
$tmpRibbonTarget=$this->spreadSheet->getRibbonXMLData('target'); |
|||
$objZip->addFromString($tmpRibbonTarget, $this->spreadSheet->getRibbonXMLData('data')); |
|||
if ($this->spreadSheet->hasRibbonBinObjects()) { |
|||
$tmpRootPath=dirname($tmpRibbonTarget).'/'; |
|||
$ribbonBinObjects=$this->spreadSheet->getRibbonBinObjects('data');//the files to write |
|||
foreach ($ribbonBinObjects as $aPath => $aContent) { |
|||
$objZip->addFromString($tmpRootPath.$aPath, $aContent); |
|||
} |
|||
//the rels for files |
|||
$objZip->addFromString($tmpRootPath.'_rels/'.basename($tmpRibbonTarget).'.rels', $this->getWriterPart('RelsRibbonObjects')->writeRibbonRelationships($this->spreadSheet)); |
|||
} |
|||
} |
|||
|
|||
// Add relationships to ZIP file |
|||
$objZip->addFromString('_rels/.rels', $this->getWriterPart('Rels')->writeRelationships($this->spreadSheet)); |
|||
$objZip->addFromString('xl/_rels/workbook.xml.rels', $this->getWriterPart('Rels')->writeWorkbookRelationships($this->spreadSheet)); |
|||
|
|||
// Add document properties to ZIP file |
|||
$objZip->addFromString('docProps/app.xml', $this->getWriterPart('DocProps')->writeDocPropsApp($this->spreadSheet)); |
|||
$objZip->addFromString('docProps/core.xml', $this->getWriterPart('DocProps')->writeDocPropsCore($this->spreadSheet)); |
|||
$customPropertiesPart = $this->getWriterPart('DocProps')->writeDocPropsCustom($this->spreadSheet); |
|||
if ($customPropertiesPart !== null) { |
|||
$objZip->addFromString('docProps/custom.xml', $customPropertiesPart); |
|||
} |
|||
|
|||
// Add theme to ZIP file |
|||
$objZip->addFromString('xl/theme/theme1.xml', $this->getWriterPart('Theme')->writeTheme($this->spreadSheet)); |
|||
|
|||
// Add string table to ZIP file |
|||
$objZip->addFromString('xl/sharedStrings.xml', $this->getWriterPart('StringTable')->writeStringTable($this->stringTable)); |
|||
|
|||
// Add styles to ZIP file |
|||
$objZip->addFromString('xl/styles.xml', $this->getWriterPart('Style')->writeStyles($this->spreadSheet)); |
|||
|
|||
// Add workbook to ZIP file |
|||
$objZip->addFromString('xl/workbook.xml', $this->getWriterPart('Workbook')->writeWorkbook($this->spreadSheet, $this->preCalculateFormulas)); |
|||
|
|||
$chartCount = 0; |
|||
// Add worksheets |
|||
for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) { |
|||
$objZip->addFromString('xl/worksheets/sheet' . ($i + 1) . '.xml', $this->getWriterPart('Worksheet')->writeWorksheet($this->spreadSheet->getSheet($i), $this->stringTable, $this->includeCharts)); |
|||
if ($this->includeCharts) { |
|||
$charts = $this->spreadSheet->getSheet($i)->getChartCollection(); |
|||
if (count($charts) > 0) { |
|||
foreach ($charts as $chart) { |
|||
$objZip->addFromString('xl/charts/chart' . ($chartCount + 1) . '.xml', $this->getWriterPart('Chart')->writeChart($chart, $this->preCalculateFormulas)); |
|||
$chartCount++; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
$chartRef1 = $chartRef2 = 0; |
|||
// Add worksheet relationships (drawings, ...) |
|||
for ($i = 0; $i < $this->spreadSheet->getSheetCount(); ++$i) { |
|||
// Add relationships |
|||
$objZip->addFromString('xl/worksheets/_rels/sheet' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeWorksheetRelationships($this->spreadSheet->getSheet($i), ($i + 1), $this->includeCharts)); |
|||
|
|||
$drawings = $this->spreadSheet->getSheet($i)->getDrawingCollection(); |
|||
$drawingCount = count($drawings); |
|||
if ($this->includeCharts) { |
|||
$chartCount = $this->spreadSheet->getSheet($i)->getChartCount(); |
|||
} |
|||
|
|||
// Add drawing and image relationship parts |
|||
if (($drawingCount > 0) || ($chartCount > 0)) { |
|||
// Drawing relationships |
|||
$objZip->addFromString('xl/drawings/_rels/drawing' . ($i + 1) . '.xml.rels', $this->getWriterPart('Rels')->writeDrawingRelationships($this->spreadSheet->getSheet($i), $chartRef1, $this->includeCharts)); |
|||
|
|||
// Drawings |
|||
$objZip->addFromString('xl/drawings/drawing' . ($i + 1) . '.xml', $this->getWriterPart('Drawing')->writeDrawings($this->spreadSheet->getSheet($i), $chartRef2, $this->includeCharts)); |
|||
} |
|||
|
|||
// Add comment relationship parts |
|||
if (count($this->spreadSheet->getSheet($i)->getComments()) > 0) { |
|||
// VML Comments |
|||
$objZip->addFromString('xl/drawings/vmlDrawing' . ($i + 1) . '.vml', $this->getWriterPart('Comments')->writeVMLComments($this->spreadSheet->getSheet($i))); |
|||
|
|||
// Comments |
|||
$objZip->addFromString('xl/comments' . ($i + 1) . '.xml', $this->getWriterPart('Comments')->writeComments($this->spreadSheet->getSheet($i))); |
|||
} |
|||
|
|||
// Add header/footer relationship parts |
|||
if (count($this->spreadSheet->getSheet($i)->getHeaderFooter()->getImages()) > 0) { |
|||
// VML Drawings |
|||
$objZip->addFromString('xl/drawings/vmlDrawingHF' . ($i + 1) . '.vml', $this->getWriterPart('Drawing')->writeVMLHeaderFooterImages($this->spreadSheet->getSheet($i))); |
|||
|
|||
// VML Drawing relationships |
|||
$objZip->addFromString('xl/drawings/_rels/vmlDrawingHF' . ($i + 1) . '.vml.rels', $this->getWriterPart('Rels')->writeHeaderFooterDrawingRelationships($this->spreadSheet->getSheet($i))); |
|||
|
|||
// Media |
|||
foreach ($this->spreadSheet->getSheet($i)->getHeaderFooter()->getImages() as $image) { |
|||
$objZip->addFromString('xl/media/' . $image->getIndexedFilename(), file_get_contents($image->getPath())); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Add media |
|||
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) { |
|||
if ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPExcel_Worksheet_Drawing) { |
|||
$imageContents = null; |
|||
$imagePath = $this->getDrawingHashTable()->getByIndex($i)->getPath(); |
|||
if (strpos($imagePath, 'zip://') !== false) { |
|||
$imagePath = substr($imagePath, 6); |
|||
$imagePathSplitted = explode('#', $imagePath); |
|||
|
|||
$imageZip = new ZipArchive(); |
|||
$imageZip->open($imagePathSplitted[0]); |
|||
$imageContents = $imageZip->getFromName($imagePathSplitted[1]); |
|||
$imageZip->close(); |
|||
unset($imageZip); |
|||
} else { |
|||
$imageContents = file_get_contents($imagePath); |
|||
} |
|||
|
|||
$objZip->addFromString('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); |
|||
} elseif ($this->getDrawingHashTable()->getByIndex($i) instanceof PHPExcel_Worksheet_MemoryDrawing) { |
|||
ob_start(); |
|||
call_user_func( |
|||
$this->getDrawingHashTable()->getByIndex($i)->getRenderingFunction(), |
|||
$this->getDrawingHashTable()->getByIndex($i)->getImageResource() |
|||
); |
|||
$imageContents = ob_get_contents(); |
|||
ob_end_clean(); |
|||
|
|||
$objZip->addFromString('xl/media/' . str_replace(' ', '_', $this->getDrawingHashTable()->getByIndex($i)->getIndexedFilename()), $imageContents); |
|||
} |
|||
} |
|||
|
|||
PHPExcel_Calculation_Functions::setReturnDateType($saveDateReturnType); |
|||
PHPExcel_Calculation::getInstance($this->spreadSheet)->getDebugLog()->setWriteDebugLog($saveDebugLog); |
|||
|
|||
// Close file |
|||
if ($objZip->close() === false) { |
|||
throw new PHPExcel_Writer_Exception("Could not close zip file $pFilename."); |
|||
} |
|||
|
|||
// If a temporary file was used, copy it to the correct file stream |
|||
if ($originalFilename != $pFilename) { |
|||
if (copy($pFilename, $originalFilename) === false) { |
|||
throw new PHPExcel_Writer_Exception("Could not copy temporary zip file $pFilename to $originalFilename."); |
|||
} |
|||
@unlink($pFilename); |
|||
} |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("PHPExcel object unassigned."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel object |
|||
* |
|||
* @return PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function getPHPExcel() |
|||
{ |
|||
if ($this->spreadSheet !== null) { |
|||
return $this->spreadSheet; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("No PHPExcel object assigned."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Set PHPExcel object |
|||
* |
|||
* @param PHPExcel $pPHPExcel PHPExcel object |
|||
* @throws PHPExcel_Writer_Exception |
|||
* @return PHPExcel_Writer_Excel2007 |
|||
*/ |
|||
public function setPHPExcel(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
$this->spreadSheet = $pPHPExcel; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get string table |
|||
* |
|||
* @return string[] |
|||
*/ |
|||
public function getStringTable() |
|||
{ |
|||
return $this->stringTable; |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel_Style HashTable |
|||
* |
|||
* @return PHPExcel_HashTable |
|||
*/ |
|||
public function getStyleHashTable() |
|||
{ |
|||
return $this->styleHashTable; |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel_Style_Conditional HashTable |
|||
* |
|||
* @return PHPExcel_HashTable |
|||
*/ |
|||
public function getStylesConditionalHashTable() |
|||
{ |
|||
return $this->stylesConditionalHashTable; |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel_Style_Fill HashTable |
|||
* |
|||
* @return PHPExcel_HashTable |
|||
*/ |
|||
public function getFillHashTable() |
|||
{ |
|||
return $this->fillHashTable; |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel_Style_Font HashTable |
|||
* |
|||
* @return PHPExcel_HashTable |
|||
*/ |
|||
public function getFontHashTable() |
|||
{ |
|||
return $this->fontHashTable; |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel_Style_Borders HashTable |
|||
* |
|||
* @return PHPExcel_HashTable |
|||
*/ |
|||
public function getBordersHashTable() |
|||
{ |
|||
return $this->bordersHashTable; |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel_Style_NumberFormat HashTable |
|||
* |
|||
* @return PHPExcel_HashTable |
|||
*/ |
|||
public function getNumFmtHashTable() |
|||
{ |
|||
return $this->numFmtHashTable; |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel_Worksheet_BaseDrawing HashTable |
|||
* |
|||
* @return PHPExcel_HashTable |
|||
*/ |
|||
public function getDrawingHashTable() |
|||
{ |
|||
return $this->drawingHashTable; |
|||
} |
|||
|
|||
/** |
|||
* Get Office2003 compatibility |
|||
* |
|||
* @return boolean |
|||
*/ |
|||
public function getOffice2003Compatibility() |
|||
{ |
|||
return $this->office2003compatibility; |
|||
} |
|||
|
|||
/** |
|||
* Set Office2003 compatibility |
|||
* |
|||
* @param boolean $pValue Office2003 compatibility? |
|||
* @return PHPExcel_Writer_Excel2007 |
|||
*/ |
|||
public function setOffice2003Compatibility($pValue = false) |
|||
{ |
|||
$this->office2003compatibility = $pValue; |
|||
return $this; |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,260 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_Comments |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_Comments extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write comments to XML format |
|||
* |
|||
* @param PHPExcel_Worksheet $pWorksheet |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeComments(PHPExcel_Worksheet $pWorksheet = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Comments cache |
|||
$comments = $pWorksheet->getComments(); |
|||
|
|||
// Authors cache |
|||
$authors = array(); |
|||
$authorId = 0; |
|||
foreach ($comments as $comment) { |
|||
if (!isset($authors[$comment->getAuthor()])) { |
|||
$authors[$comment->getAuthor()] = $authorId++; |
|||
} |
|||
} |
|||
|
|||
// comments |
|||
$objWriter->startElement('comments'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'); |
|||
|
|||
// Loop through authors |
|||
$objWriter->startElement('authors'); |
|||
foreach ($authors as $author => $index) { |
|||
$objWriter->writeElement('author', $author); |
|||
} |
|||
$objWriter->endElement(); |
|||
|
|||
// Loop through comments |
|||
$objWriter->startElement('commentList'); |
|||
foreach ($comments as $key => $value) { |
|||
$this->writeComment($objWriter, $key, $value, $authors); |
|||
} |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write comment to XML format |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param string $pCellReference Cell reference |
|||
* @param PHPExcel_Comment $pComment Comment |
|||
* @param array $pAuthors Array of authors |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null, $pAuthors = null) |
|||
{ |
|||
// comment |
|||
$objWriter->startElement('comment'); |
|||
$objWriter->writeAttribute('ref', $pCellReference); |
|||
$objWriter->writeAttribute('authorId', $pAuthors[$pComment->getAuthor()]); |
|||
|
|||
// text |
|||
$objWriter->startElement('text'); |
|||
$this->getParentWriter()->getWriterPart('stringtable')->writeRichText($objWriter, $pComment->getText()); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write VML comments to XML format |
|||
* |
|||
* @param PHPExcel_Worksheet $pWorksheet |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeVMLComments(PHPExcel_Worksheet $pWorksheet = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Comments cache |
|||
$comments = $pWorksheet->getComments(); |
|||
|
|||
// xml |
|||
$objWriter->startElement('xml'); |
|||
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); |
|||
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); |
|||
$objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel'); |
|||
|
|||
// o:shapelayout |
|||
$objWriter->startElement('o:shapelayout'); |
|||
$objWriter->writeAttribute('v:ext', 'edit'); |
|||
|
|||
// o:idmap |
|||
$objWriter->startElement('o:idmap'); |
|||
$objWriter->writeAttribute('v:ext', 'edit'); |
|||
$objWriter->writeAttribute('data', '1'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// v:shapetype |
|||
$objWriter->startElement('v:shapetype'); |
|||
$objWriter->writeAttribute('id', '_x0000_t202'); |
|||
$objWriter->writeAttribute('coordsize', '21600,21600'); |
|||
$objWriter->writeAttribute('o:spt', '202'); |
|||
$objWriter->writeAttribute('path', 'm,l,21600r21600,l21600,xe'); |
|||
|
|||
// v:stroke |
|||
$objWriter->startElement('v:stroke'); |
|||
$objWriter->writeAttribute('joinstyle', 'miter'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:path |
|||
$objWriter->startElement('v:path'); |
|||
$objWriter->writeAttribute('gradientshapeok', 't'); |
|||
$objWriter->writeAttribute('o:connecttype', 'rect'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Loop through comments |
|||
foreach ($comments as $key => $value) { |
|||
$this->writeVMLComment($objWriter, $key, $value); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write VML comment to XML format |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param string $pCellReference Cell reference |
|||
* @param PHPExcel_Comment $pComment Comment |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeVMLComment(PHPExcel_Shared_XMLWriter $objWriter = null, $pCellReference = 'A1', PHPExcel_Comment $pComment = null) |
|||
{ |
|||
// Metadata |
|||
list($column, $row) = PHPExcel_Cell::coordinateFromString($pCellReference); |
|||
$column = PHPExcel_Cell::columnIndexFromString($column); |
|||
$id = 1024 + $column + $row; |
|||
$id = substr($id, 0, 4); |
|||
|
|||
// v:shape |
|||
$objWriter->startElement('v:shape'); |
|||
$objWriter->writeAttribute('id', '_x0000_s' . $id); |
|||
$objWriter->writeAttribute('type', '#_x0000_t202'); |
|||
$objWriter->writeAttribute('style', 'position:absolute;margin-left:' . $pComment->getMarginLeft() . ';margin-top:' . $pComment->getMarginTop() . ';width:' . $pComment->getWidth() . ';height:' . $pComment->getHeight() . ';z-index:1;visibility:' . ($pComment->getVisible() ? 'visible' : 'hidden')); |
|||
$objWriter->writeAttribute('fillcolor', '#' . $pComment->getFillColor()->getRGB()); |
|||
$objWriter->writeAttribute('o:insetmode', 'auto'); |
|||
|
|||
// v:fill |
|||
$objWriter->startElement('v:fill'); |
|||
$objWriter->writeAttribute('color2', '#' . $pComment->getFillColor()->getRGB()); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:shadow |
|||
$objWriter->startElement('v:shadow'); |
|||
$objWriter->writeAttribute('on', 't'); |
|||
$objWriter->writeAttribute('color', 'black'); |
|||
$objWriter->writeAttribute('obscured', 't'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:path |
|||
$objWriter->startElement('v:path'); |
|||
$objWriter->writeAttribute('o:connecttype', 'none'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:textbox |
|||
$objWriter->startElement('v:textbox'); |
|||
$objWriter->writeAttribute('style', 'mso-direction-alt:auto'); |
|||
|
|||
// div |
|||
$objWriter->startElement('div'); |
|||
$objWriter->writeAttribute('style', 'text-align:left'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// x:ClientData |
|||
$objWriter->startElement('x:ClientData'); |
|||
$objWriter->writeAttribute('ObjectType', 'Note'); |
|||
|
|||
// x:MoveWithCells |
|||
$objWriter->writeElement('x:MoveWithCells', ''); |
|||
|
|||
// x:SizeWithCells |
|||
$objWriter->writeElement('x:SizeWithCells', ''); |
|||
|
|||
// x:Anchor |
|||
//$objWriter->writeElement('x:Anchor', $column . ', 15, ' . ($row - 2) . ', 10, ' . ($column + 4) . ', 15, ' . ($row + 5) . ', 18'); |
|||
|
|||
// x:AutoFill |
|||
$objWriter->writeElement('x:AutoFill', 'False'); |
|||
|
|||
// x:Row |
|||
$objWriter->writeElement('x:Row', ($row - 1)); |
|||
|
|||
// x:Column |
|||
$objWriter->writeElement('x:Column', ($column - 1)); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
@ -0,0 +1,240 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_ContentTypes |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_ContentTypes extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write content types to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @param boolean $includeCharts Flag indicating if we should include drawing details for charts |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeContentTypes(PHPExcel $pPHPExcel = null, $includeCharts = false) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Types |
|||
$objWriter->startElement('Types'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/content-types'); |
|||
|
|||
// Theme |
|||
$this->writeOverrideContentType($objWriter, '/xl/theme/theme1.xml', 'application/vnd.openxmlformats-officedocument.theme+xml'); |
|||
|
|||
// Styles |
|||
$this->writeOverrideContentType($objWriter, '/xl/styles.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml'); |
|||
|
|||
// Rels |
|||
$this->writeDefaultContentType($objWriter, 'rels', 'application/vnd.openxmlformats-package.relationships+xml'); |
|||
|
|||
// XML |
|||
$this->writeDefaultContentType($objWriter, 'xml', 'application/xml'); |
|||
|
|||
// VML |
|||
$this->writeDefaultContentType($objWriter, 'vml', 'application/vnd.openxmlformats-officedocument.vmlDrawing'); |
|||
|
|||
// Workbook |
|||
if ($pPHPExcel->hasMacros()) { //Macros in workbook ? |
|||
// Yes : not standard content but "macroEnabled" |
|||
$this->writeOverrideContentType($objWriter, '/xl/workbook.xml', 'application/vnd.ms-excel.sheet.macroEnabled.main+xml'); |
|||
//... and define a new type for the VBA project |
|||
$this->writeDefaultContentType($objWriter, 'bin', 'application/vnd.ms-office.vbaProject'); |
|||
if ($pPHPExcel->hasMacrosCertificate()) {// signed macros ? |
|||
// Yes : add needed information |
|||
$this->writeOverrideContentType($objWriter, '/xl/vbaProjectSignature.bin', 'application/vnd.ms-office.vbaProjectSignature'); |
|||
} |
|||
} else {// no macros in workbook, so standard type |
|||
$this->writeOverrideContentType($objWriter, '/xl/workbook.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'); |
|||
} |
|||
|
|||
// DocProps |
|||
$this->writeOverrideContentType($objWriter, '/docProps/app.xml', 'application/vnd.openxmlformats-officedocument.extended-properties+xml'); |
|||
|
|||
$this->writeOverrideContentType($objWriter, '/docProps/core.xml', 'application/vnd.openxmlformats-package.core-properties+xml'); |
|||
|
|||
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties(); |
|||
if (!empty($customPropertyList)) { |
|||
$this->writeOverrideContentType($objWriter, '/docProps/custom.xml', 'application/vnd.openxmlformats-officedocument.custom-properties+xml'); |
|||
} |
|||
|
|||
// Worksheets |
|||
$sheetCount = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
$this->writeOverrideContentType($objWriter, '/xl/worksheets/sheet' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'); |
|||
} |
|||
|
|||
// Shared strings |
|||
$this->writeOverrideContentType($objWriter, '/xl/sharedStrings.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'); |
|||
|
|||
// Add worksheet relationship content types |
|||
$chart = 1; |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
$drawings = $pPHPExcel->getSheet($i)->getDrawingCollection(); |
|||
$drawingCount = count($drawings); |
|||
$chartCount = ($includeCharts) ? $pPHPExcel->getSheet($i)->getChartCount() : 0; |
|||
|
|||
// We need a drawing relationship for the worksheet if we have either drawings or charts |
|||
if (($drawingCount > 0) || ($chartCount > 0)) { |
|||
$this->writeOverrideContentType($objWriter, '/xl/drawings/drawing' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.drawing+xml'); |
|||
} |
|||
|
|||
// If we have charts, then we need a chart relationship for every individual chart |
|||
if ($chartCount > 0) { |
|||
for ($c = 0; $c < $chartCount; ++$c) { |
|||
$this->writeOverrideContentType($objWriter, '/xl/charts/chart' . $chart++ . '.xml', 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml'); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Comments |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
if (count($pPHPExcel->getSheet($i)->getComments()) > 0) { |
|||
$this->writeOverrideContentType($objWriter, '/xl/comments' . ($i + 1) . '.xml', 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml'); |
|||
} |
|||
} |
|||
|
|||
// Add media content-types |
|||
$aMediaContentTypes = array(); |
|||
$mediaCount = $this->getParentWriter()->getDrawingHashTable()->count(); |
|||
for ($i = 0; $i < $mediaCount; ++$i) { |
|||
$extension = ''; |
|||
$mimeType = ''; |
|||
|
|||
if ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPExcel_Worksheet_Drawing) { |
|||
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getExtension()); |
|||
$mimeType = $this->getImageMimeType($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getPath()); |
|||
} elseif ($this->getParentWriter()->getDrawingHashTable()->getByIndex($i) instanceof PHPExcel_Worksheet_MemoryDrawing) { |
|||
$extension = strtolower($this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType()); |
|||
$extension = explode('/', $extension); |
|||
$extension = $extension[1]; |
|||
|
|||
$mimeType = $this->getParentWriter()->getDrawingHashTable()->getByIndex($i)->getMimeType(); |
|||
} |
|||
|
|||
if (!isset( $aMediaContentTypes[$extension])) { |
|||
$aMediaContentTypes[$extension] = $mimeType; |
|||
|
|||
$this->writeDefaultContentType($objWriter, $extension, $mimeType); |
|||
} |
|||
} |
|||
if ($pPHPExcel->hasRibbonBinObjects()) { |
|||
// Some additional objects in the ribbon ? |
|||
// we need to write "Extension" but not already write for media content |
|||
$tabRibbonTypes=array_diff($pPHPExcel->getRibbonBinObjects('types'), array_keys($aMediaContentTypes)); |
|||
foreach ($tabRibbonTypes as $aRibbonType) { |
|||
$mimeType='image/.'.$aRibbonType;//we wrote $mimeType like customUI Editor |
|||
$this->writeDefaultContentType($objWriter, $aRibbonType, $mimeType); |
|||
} |
|||
} |
|||
$sheetCount = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
if (count($pPHPExcel->getSheet()->getHeaderFooter()->getImages()) > 0) { |
|||
foreach ($pPHPExcel->getSheet()->getHeaderFooter()->getImages() as $image) { |
|||
if (!isset( $aMediaContentTypes[strtolower($image->getExtension())])) { |
|||
$aMediaContentTypes[strtolower($image->getExtension())] = $this->getImageMimeType($image->getPath()); |
|||
|
|||
$this->writeDefaultContentType($objWriter, strtolower($image->getExtension()), $aMediaContentTypes[strtolower($image->getExtension())]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Get image mime type |
|||
* |
|||
* @param string $pFile Filename |
|||
* @return string Mime Type |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function getImageMimeType($pFile = '') |
|||
{ |
|||
if (PHPExcel_Shared_File::file_exists($pFile)) { |
|||
$image = getimagesize($pFile); |
|||
return image_type_to_mime_type($image[2]); |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("File $pFile does not exist"); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Default content type |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param string $pPartname Part name |
|||
* @param string $pContentType Content type |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeDefaultContentType(PHPExcel_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') |
|||
{ |
|||
if ($pPartname != '' && $pContentType != '') { |
|||
// Write content type |
|||
$objWriter->startElement('Default'); |
|||
$objWriter->writeAttribute('Extension', $pPartname); |
|||
$objWriter->writeAttribute('ContentType', $pContentType); |
|||
$objWriter->endElement(); |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Invalid parameters passed."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Override content type |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param string $pPartname Part name |
|||
* @param string $pContentType Content type |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeOverrideContentType(PHPExcel_Shared_XMLWriter $objWriter = null, $pPartname = '', $pContentType = '') |
|||
{ |
|||
if ($pPartname != '' && $pContentType != '') { |
|||
// Write content type |
|||
$objWriter->startElement('Override'); |
|||
$objWriter->writeAttribute('PartName', $pPartname); |
|||
$objWriter->writeAttribute('ContentType', $pContentType); |
|||
$objWriter->endElement(); |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Invalid parameters passed."); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,262 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_DocProps |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_DocProps extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write docProps/app.xml to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeDocPropsApp(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Properties |
|||
$objWriter->startElement('Properties'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties'); |
|||
$objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); |
|||
|
|||
// Application |
|||
$objWriter->writeElement('Application', 'Microsoft Excel'); |
|||
|
|||
// DocSecurity |
|||
$objWriter->writeElement('DocSecurity', '0'); |
|||
|
|||
// ScaleCrop |
|||
$objWriter->writeElement('ScaleCrop', 'false'); |
|||
|
|||
// HeadingPairs |
|||
$objWriter->startElement('HeadingPairs'); |
|||
|
|||
// Vector |
|||
$objWriter->startElement('vt:vector'); |
|||
$objWriter->writeAttribute('size', '2'); |
|||
$objWriter->writeAttribute('baseType', 'variant'); |
|||
|
|||
// Variant |
|||
$objWriter->startElement('vt:variant'); |
|||
$objWriter->writeElement('vt:lpstr', 'Worksheets'); |
|||
$objWriter->endElement(); |
|||
|
|||
// Variant |
|||
$objWriter->startElement('vt:variant'); |
|||
$objWriter->writeElement('vt:i4', $pPHPExcel->getSheetCount()); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// TitlesOfParts |
|||
$objWriter->startElement('TitlesOfParts'); |
|||
|
|||
// Vector |
|||
$objWriter->startElement('vt:vector'); |
|||
$objWriter->writeAttribute('size', $pPHPExcel->getSheetCount()); |
|||
$objWriter->writeAttribute('baseType', 'lpstr'); |
|||
|
|||
$sheetCount = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
$objWriter->writeElement('vt:lpstr', $pPHPExcel->getSheet($i)->getTitle()); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Company |
|||
$objWriter->writeElement('Company', $pPHPExcel->getProperties()->getCompany()); |
|||
|
|||
// Company |
|||
$objWriter->writeElement('Manager', $pPHPExcel->getProperties()->getManager()); |
|||
|
|||
// LinksUpToDate |
|||
$objWriter->writeElement('LinksUpToDate', 'false'); |
|||
|
|||
// SharedDoc |
|||
$objWriter->writeElement('SharedDoc', 'false'); |
|||
|
|||
// HyperlinksChanged |
|||
$objWriter->writeElement('HyperlinksChanged', 'false'); |
|||
|
|||
// AppVersion |
|||
$objWriter->writeElement('AppVersion', '12.0000'); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write docProps/core.xml to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeDocPropsCore(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// cp:coreProperties |
|||
$objWriter->startElement('cp:coreProperties'); |
|||
$objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties'); |
|||
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
|||
$objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/'); |
|||
$objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/'); |
|||
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
|||
|
|||
// dc:creator |
|||
$objWriter->writeElement('dc:creator', $pPHPExcel->getProperties()->getCreator()); |
|||
|
|||
// cp:lastModifiedBy |
|||
$objWriter->writeElement('cp:lastModifiedBy', $pPHPExcel->getProperties()->getLastModifiedBy()); |
|||
|
|||
// dcterms:created |
|||
$objWriter->startElement('dcterms:created'); |
|||
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); |
|||
$objWriter->writeRawData(date(DATE_W3C, $pPHPExcel->getProperties()->getCreated())); |
|||
$objWriter->endElement(); |
|||
|
|||
// dcterms:modified |
|||
$objWriter->startElement('dcterms:modified'); |
|||
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF'); |
|||
$objWriter->writeRawData(date(DATE_W3C, $pPHPExcel->getProperties()->getModified())); |
|||
$objWriter->endElement(); |
|||
|
|||
// dc:title |
|||
$objWriter->writeElement('dc:title', $pPHPExcel->getProperties()->getTitle()); |
|||
|
|||
// dc:description |
|||
$objWriter->writeElement('dc:description', $pPHPExcel->getProperties()->getDescription()); |
|||
|
|||
// dc:subject |
|||
$objWriter->writeElement('dc:subject', $pPHPExcel->getProperties()->getSubject()); |
|||
|
|||
// cp:keywords |
|||
$objWriter->writeElement('cp:keywords', $pPHPExcel->getProperties()->getKeywords()); |
|||
|
|||
// cp:category |
|||
$objWriter->writeElement('cp:category', $pPHPExcel->getProperties()->getCategory()); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write docProps/custom.xml to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeDocPropsCustom(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties(); |
|||
if (empty($customPropertyList)) { |
|||
return; |
|||
} |
|||
|
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// cp:coreProperties |
|||
$objWriter->startElement('Properties'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/custom-properties'); |
|||
$objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); |
|||
|
|||
|
|||
foreach ($customPropertyList as $key => $customProperty) { |
|||
$propertyValue = $pPHPExcel->getProperties()->getCustomPropertyValue($customProperty); |
|||
$propertyType = $pPHPExcel->getProperties()->getCustomPropertyType($customProperty); |
|||
|
|||
$objWriter->startElement('property'); |
|||
$objWriter->writeAttribute('fmtid', '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'); |
|||
$objWriter->writeAttribute('pid', $key+2); |
|||
$objWriter->writeAttribute('name', $customProperty); |
|||
|
|||
switch ($propertyType) { |
|||
case 'i': |
|||
$objWriter->writeElement('vt:i4', $propertyValue); |
|||
break; |
|||
case 'f': |
|||
$objWriter->writeElement('vt:r8', $propertyValue); |
|||
break; |
|||
case 'b': |
|||
$objWriter->writeElement('vt:bool', ($propertyValue) ? 'true' : 'false'); |
|||
break; |
|||
case 'd': |
|||
$objWriter->startElement('vt:filetime'); |
|||
$objWriter->writeRawData(date(DATE_W3C, $propertyValue)); |
|||
$objWriter->endElement(); |
|||
break; |
|||
default: |
|||
$objWriter->writeElement('vt:lpwstr', $propertyValue); |
|||
break; |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
} |
|||
@ -0,0 +1,589 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_Drawing |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_Drawing extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write drawings to XML format |
|||
* |
|||
* @param PHPExcel_Worksheet $pWorksheet |
|||
* @param int &$chartRef Chart ID |
|||
* @param boolean $includeCharts Flag indicating if we should include drawing details for charts |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeDrawings(PHPExcel_Worksheet $pWorksheet = null, &$chartRef, $includeCharts = false) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// xdr:wsDr |
|||
$objWriter->startElement('xdr:wsDr'); |
|||
$objWriter->writeAttribute('xmlns:xdr', 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing'); |
|||
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); |
|||
|
|||
// Loop through images and write drawings |
|||
$i = 1; |
|||
$iterator = $pWorksheet->getDrawingCollection()->getIterator(); |
|||
while ($iterator->valid()) { |
|||
$this->writeDrawing($objWriter, $iterator->current(), $i); |
|||
|
|||
$iterator->next(); |
|||
++$i; |
|||
} |
|||
|
|||
if ($includeCharts) { |
|||
$chartCount = $pWorksheet->getChartCount(); |
|||
// Loop through charts and write the chart position |
|||
if ($chartCount > 0) { |
|||
for ($c = 0; $c < $chartCount; ++$c) { |
|||
$this->writeChart($objWriter, $pWorksheet->getChartByIndex($c), $c+$i); |
|||
} |
|||
} |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write drawings to XML format |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Chart $pChart |
|||
* @param int $pRelationId |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeChart(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Chart $pChart = null, $pRelationId = -1) |
|||
{ |
|||
$tl = $pChart->getTopLeftPosition(); |
|||
$tl['colRow'] = PHPExcel_Cell::coordinateFromString($tl['cell']); |
|||
$br = $pChart->getBottomRightPosition(); |
|||
$br['colRow'] = PHPExcel_Cell::coordinateFromString($br['cell']); |
|||
|
|||
$objWriter->startElement('xdr:twoCellAnchor'); |
|||
|
|||
$objWriter->startElement('xdr:from'); |
|||
$objWriter->writeElement('xdr:col', PHPExcel_Cell::columnIndexFromString($tl['colRow'][0]) - 1); |
|||
$objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($tl['xOffset'])); |
|||
$objWriter->writeElement('xdr:row', $tl['colRow'][1] - 1); |
|||
$objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($tl['yOffset'])); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('xdr:to'); |
|||
$objWriter->writeElement('xdr:col', PHPExcel_Cell::columnIndexFromString($br['colRow'][0]) - 1); |
|||
$objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($br['xOffset'])); |
|||
$objWriter->writeElement('xdr:row', $br['colRow'][1] - 1); |
|||
$objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($br['yOffset'])); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->startElement('xdr:graphicFrame'); |
|||
$objWriter->writeAttribute('macro', ''); |
|||
$objWriter->startElement('xdr:nvGraphicFramePr'); |
|||
$objWriter->startElement('xdr:cNvPr'); |
|||
$objWriter->writeAttribute('name', 'Chart '.$pRelationId); |
|||
$objWriter->writeAttribute('id', 1025 * $pRelationId); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('xdr:cNvGraphicFramePr'); |
|||
$objWriter->startElement('a:graphicFrameLocks'); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->startElement('xdr:xfrm'); |
|||
$objWriter->startElement('a:off'); |
|||
$objWriter->writeAttribute('x', '0'); |
|||
$objWriter->writeAttribute('y', '0'); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('a:ext'); |
|||
$objWriter->writeAttribute('cx', '0'); |
|||
$objWriter->writeAttribute('cy', '0'); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->startElement('a:graphic'); |
|||
$objWriter->startElement('a:graphicData'); |
|||
$objWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); |
|||
$objWriter->startElement('c:chart'); |
|||
$objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); |
|||
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|||
$objWriter->writeAttribute('r:id', 'rId'.$pRelationId); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->startElement('xdr:clientData'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write drawings to XML format |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Worksheet_BaseDrawing $pDrawing |
|||
* @param int $pRelationId |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeDrawing(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet_BaseDrawing $pDrawing = null, $pRelationId = -1) |
|||
{ |
|||
if ($pRelationId >= 0) { |
|||
// xdr:oneCellAnchor |
|||
$objWriter->startElement('xdr:oneCellAnchor'); |
|||
// Image location |
|||
$aCoordinates = PHPExcel_Cell::coordinateFromString($pDrawing->getCoordinates()); |
|||
$aCoordinates[0] = PHPExcel_Cell::columnIndexFromString($aCoordinates[0]); |
|||
|
|||
// xdr:from |
|||
$objWriter->startElement('xdr:from'); |
|||
$objWriter->writeElement('xdr:col', $aCoordinates[0] - 1); |
|||
$objWriter->writeElement('xdr:colOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetX())); |
|||
$objWriter->writeElement('xdr:row', $aCoordinates[1] - 1); |
|||
$objWriter->writeElement('xdr:rowOff', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getOffsetY())); |
|||
$objWriter->endElement(); |
|||
|
|||
// xdr:ext |
|||
$objWriter->startElement('xdr:ext'); |
|||
$objWriter->writeAttribute('cx', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getWidth())); |
|||
$objWriter->writeAttribute('cy', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getHeight())); |
|||
$objWriter->endElement(); |
|||
|
|||
// xdr:pic |
|||
$objWriter->startElement('xdr:pic'); |
|||
|
|||
// xdr:nvPicPr |
|||
$objWriter->startElement('xdr:nvPicPr'); |
|||
|
|||
// xdr:cNvPr |
|||
$objWriter->startElement('xdr:cNvPr'); |
|||
$objWriter->writeAttribute('id', $pRelationId); |
|||
$objWriter->writeAttribute('name', $pDrawing->getName()); |
|||
$objWriter->writeAttribute('descr', $pDrawing->getDescription()); |
|||
$objWriter->endElement(); |
|||
|
|||
// xdr:cNvPicPr |
|||
$objWriter->startElement('xdr:cNvPicPr'); |
|||
|
|||
// a:picLocks |
|||
$objWriter->startElement('a:picLocks'); |
|||
$objWriter->writeAttribute('noChangeAspect', '1'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// xdr:blipFill |
|||
$objWriter->startElement('xdr:blipFill'); |
|||
|
|||
// a:blip |
|||
$objWriter->startElement('a:blip'); |
|||
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|||
$objWriter->writeAttribute('r:embed', 'rId' . $pRelationId); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:stretch |
|||
$objWriter->startElement('a:stretch'); |
|||
$objWriter->writeElement('a:fillRect', null); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// xdr:spPr |
|||
$objWriter->startElement('xdr:spPr'); |
|||
|
|||
// a:xfrm |
|||
$objWriter->startElement('a:xfrm'); |
|||
$objWriter->writeAttribute('rot', PHPExcel_Shared_Drawing::degreesToAngle($pDrawing->getRotation())); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:prstGeom |
|||
$objWriter->startElement('a:prstGeom'); |
|||
$objWriter->writeAttribute('prst', 'rect'); |
|||
|
|||
// a:avLst |
|||
$objWriter->writeElement('a:avLst', null); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// // a:solidFill |
|||
// $objWriter->startElement('a:solidFill'); |
|||
|
|||
// // a:srgbClr |
|||
// $objWriter->startElement('a:srgbClr'); |
|||
// $objWriter->writeAttribute('val', 'FFFFFF'); |
|||
|
|||
///* SHADE |
|||
// // a:shade |
|||
// $objWriter->startElement('a:shade'); |
|||
// $objWriter->writeAttribute('val', '85000'); |
|||
// $objWriter->endElement(); |
|||
//*/ |
|||
|
|||
// $objWriter->endElement(); |
|||
|
|||
// $objWriter->endElement(); |
|||
/* |
|||
// a:ln |
|||
$objWriter->startElement('a:ln'); |
|||
$objWriter->writeAttribute('w', '88900'); |
|||
$objWriter->writeAttribute('cap', 'sq'); |
|||
|
|||
// a:solidFill |
|||
$objWriter->startElement('a:solidFill'); |
|||
|
|||
// a:srgbClr |
|||
$objWriter->startElement('a:srgbClr'); |
|||
$objWriter->writeAttribute('val', 'FFFFFF'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:miter |
|||
$objWriter->startElement('a:miter'); |
|||
$objWriter->writeAttribute('lim', '800000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
*/ |
|||
|
|||
if ($pDrawing->getShadow()->getVisible()) { |
|||
// a:effectLst |
|||
$objWriter->startElement('a:effectLst'); |
|||
|
|||
// a:outerShdw |
|||
$objWriter->startElement('a:outerShdw'); |
|||
$objWriter->writeAttribute('blurRad', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getShadow()->getBlurRadius())); |
|||
$objWriter->writeAttribute('dist', PHPExcel_Shared_Drawing::pixelsToEMU($pDrawing->getShadow()->getDistance())); |
|||
$objWriter->writeAttribute('dir', PHPExcel_Shared_Drawing::degreesToAngle($pDrawing->getShadow()->getDirection())); |
|||
$objWriter->writeAttribute('algn', $pDrawing->getShadow()->getAlignment()); |
|||
$objWriter->writeAttribute('rotWithShape', '0'); |
|||
|
|||
// a:srgbClr |
|||
$objWriter->startElement('a:srgbClr'); |
|||
$objWriter->writeAttribute('val', $pDrawing->getShadow()->getColor()->getRGB()); |
|||
|
|||
// a:alpha |
|||
$objWriter->startElement('a:alpha'); |
|||
$objWriter->writeAttribute('val', $pDrawing->getShadow()->getAlpha() * 1000); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
/* |
|||
|
|||
// a:scene3d |
|||
$objWriter->startElement('a:scene3d'); |
|||
|
|||
// a:camera |
|||
$objWriter->startElement('a:camera'); |
|||
$objWriter->writeAttribute('prst', 'orthographicFront'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:lightRig |
|||
$objWriter->startElement('a:lightRig'); |
|||
$objWriter->writeAttribute('rig', 'twoPt'); |
|||
$objWriter->writeAttribute('dir', 't'); |
|||
|
|||
// a:rot |
|||
$objWriter->startElement('a:rot'); |
|||
$objWriter->writeAttribute('lat', '0'); |
|||
$objWriter->writeAttribute('lon', '0'); |
|||
$objWriter->writeAttribute('rev', '0'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
*/ |
|||
/* |
|||
// a:sp3d |
|||
$objWriter->startElement('a:sp3d'); |
|||
|
|||
// a:bevelT |
|||
$objWriter->startElement('a:bevelT'); |
|||
$objWriter->writeAttribute('w', '25400'); |
|||
$objWriter->writeAttribute('h', '19050'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:contourClr |
|||
$objWriter->startElement('a:contourClr'); |
|||
|
|||
// a:srgbClr |
|||
$objWriter->startElement('a:srgbClr'); |
|||
$objWriter->writeAttribute('val', 'FFFFFF'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
*/ |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// xdr:clientData |
|||
$objWriter->writeElement('xdr:clientData', null); |
|||
|
|||
$objWriter->endElement(); |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Invalid parameters passed."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write VML header/footer images to XML format |
|||
* |
|||
* @param PHPExcel_Worksheet $pWorksheet |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeVMLHeaderFooterImages(PHPExcel_Worksheet $pWorksheet = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Header/footer images |
|||
$images = $pWorksheet->getHeaderFooter()->getImages(); |
|||
|
|||
// xml |
|||
$objWriter->startElement('xml'); |
|||
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml'); |
|||
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office'); |
|||
$objWriter->writeAttribute('xmlns:x', 'urn:schemas-microsoft-com:office:excel'); |
|||
|
|||
// o:shapelayout |
|||
$objWriter->startElement('o:shapelayout'); |
|||
$objWriter->writeAttribute('v:ext', 'edit'); |
|||
|
|||
// o:idmap |
|||
$objWriter->startElement('o:idmap'); |
|||
$objWriter->writeAttribute('v:ext', 'edit'); |
|||
$objWriter->writeAttribute('data', '1'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// v:shapetype |
|||
$objWriter->startElement('v:shapetype'); |
|||
$objWriter->writeAttribute('id', '_x0000_t75'); |
|||
$objWriter->writeAttribute('coordsize', '21600,21600'); |
|||
$objWriter->writeAttribute('o:spt', '75'); |
|||
$objWriter->writeAttribute('o:preferrelative', 't'); |
|||
$objWriter->writeAttribute('path', 'm@4@5l@4@11@9@11@9@5xe'); |
|||
$objWriter->writeAttribute('filled', 'f'); |
|||
$objWriter->writeAttribute('stroked', 'f'); |
|||
|
|||
// v:stroke |
|||
$objWriter->startElement('v:stroke'); |
|||
$objWriter->writeAttribute('joinstyle', 'miter'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:formulas |
|||
$objWriter->startElement('v:formulas'); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'if lineDrawn pixelLineWidth 0'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'sum @0 1 0'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'sum 0 0 @1'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'prod @2 1 2'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'prod @3 21600 pixelWidth'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'prod @3 21600 pixelHeight'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'sum @0 0 1'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'prod @6 1 2'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'prod @7 21600 pixelWidth'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'sum @8 21600 0'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'prod @7 21600 pixelHeight'); |
|||
$objWriter->endElement(); |
|||
|
|||
// v:f |
|||
$objWriter->startElement('v:f'); |
|||
$objWriter->writeAttribute('eqn', 'sum @10 21600 0'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// v:path |
|||
$objWriter->startElement('v:path'); |
|||
$objWriter->writeAttribute('o:extrusionok', 'f'); |
|||
$objWriter->writeAttribute('gradientshapeok', 't'); |
|||
$objWriter->writeAttribute('o:connecttype', 'rect'); |
|||
$objWriter->endElement(); |
|||
|
|||
// o:lock |
|||
$objWriter->startElement('o:lock'); |
|||
$objWriter->writeAttribute('v:ext', 'edit'); |
|||
$objWriter->writeAttribute('aspectratio', 't'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Loop through images |
|||
foreach ($images as $key => $value) { |
|||
$this->writeVMLHeaderFooterImage($objWriter, $key, $value); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write VML comment to XML format |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param string $pReference Reference |
|||
* @param PHPExcel_Worksheet_HeaderFooterDrawing $pImage Image |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeVMLHeaderFooterImage(PHPExcel_Shared_XMLWriter $objWriter = null, $pReference = '', PHPExcel_Worksheet_HeaderFooterDrawing $pImage = null) |
|||
{ |
|||
// Calculate object id |
|||
preg_match('{(\d+)}', md5($pReference), $m); |
|||
$id = 1500 + (substr($m[1], 0, 2) * 1); |
|||
|
|||
// Calculate offset |
|||
$width = $pImage->getWidth(); |
|||
$height = $pImage->getHeight(); |
|||
$marginLeft = $pImage->getOffsetX(); |
|||
$marginTop = $pImage->getOffsetY(); |
|||
|
|||
// v:shape |
|||
$objWriter->startElement('v:shape'); |
|||
$objWriter->writeAttribute('id', $pReference); |
|||
$objWriter->writeAttribute('o:spid', '_x0000_s' . $id); |
|||
$objWriter->writeAttribute('type', '#_x0000_t75'); |
|||
$objWriter->writeAttribute('style', "position:absolute;margin-left:{$marginLeft}px;margin-top:{$marginTop}px;width:{$width}px;height:{$height}px;z-index:1"); |
|||
|
|||
// v:imagedata |
|||
$objWriter->startElement('v:imagedata'); |
|||
$objWriter->writeAttribute('o:relid', 'rId' . $pReference); |
|||
$objWriter->writeAttribute('o:title', $pImage->getName()); |
|||
$objWriter->endElement(); |
|||
|
|||
// o:lock |
|||
$objWriter->startElement('o:lock'); |
|||
$objWriter->writeAttribute('v:ext', 'edit'); |
|||
$objWriter->writeAttribute('rotation', 't'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Get an array of all drawings |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return PHPExcel_Worksheet_Drawing[] All drawings in PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function allDrawings(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Get an array of all drawings |
|||
$aDrawings = array(); |
|||
|
|||
// Loop through PHPExcel |
|||
$sheetCount = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
// Loop through images and add to array |
|||
$iterator = $pPHPExcel->getSheet($i)->getDrawingCollection()->getIterator(); |
|||
while ($iterator->valid()) { |
|||
$aDrawings[] = $iterator->current(); |
|||
|
|||
$iterator->next(); |
|||
} |
|||
} |
|||
|
|||
return $aDrawings; |
|||
} |
|||
} |
|||
@ -0,0 +1,424 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_Rels |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_Rels extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write relationships to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeRelationships(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Relationships |
|||
$objWriter->startElement('Relationships'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|||
|
|||
$customPropertyList = $pPHPExcel->getProperties()->getCustomProperties(); |
|||
if (!empty($customPropertyList)) { |
|||
// Relationship docProps/app.xml |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
4, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties', |
|||
'docProps/custom.xml' |
|||
); |
|||
|
|||
} |
|||
|
|||
// Relationship docProps/app.xml |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
3, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties', |
|||
'docProps/app.xml' |
|||
); |
|||
|
|||
// Relationship docProps/core.xml |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
2, |
|||
'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties', |
|||
'docProps/core.xml' |
|||
); |
|||
|
|||
// Relationship xl/workbook.xml |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
1, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument', |
|||
'xl/workbook.xml' |
|||
); |
|||
// a custom UI in workbook ? |
|||
if ($pPHPExcel->hasRibbon()) { |
|||
$this->writeRelationShip( |
|||
$objWriter, |
|||
5, |
|||
'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility', |
|||
$pPHPExcel->getRibbonXMLData('target') |
|||
); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write workbook relationships to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeWorkbookRelationships(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Relationships |
|||
$objWriter->startElement('Relationships'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|||
|
|||
// Relationship styles.xml |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
1, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles', |
|||
'styles.xml' |
|||
); |
|||
|
|||
// Relationship theme/theme1.xml |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
2, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme', |
|||
'theme/theme1.xml' |
|||
); |
|||
|
|||
// Relationship sharedStrings.xml |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
3, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings', |
|||
'sharedStrings.xml' |
|||
); |
|||
|
|||
// Relationships with sheets |
|||
$sheetCount = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
($i + 1 + 3), |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet', |
|||
'worksheets/sheet' . ($i + 1) . '.xml' |
|||
); |
|||
} |
|||
// Relationships for vbaProject if needed |
|||
// id : just after the last sheet |
|||
if ($pPHPExcel->hasMacros()) { |
|||
$this->writeRelationShip( |
|||
$objWriter, |
|||
($i + 1 + 3), |
|||
'http://schemas.microsoft.com/office/2006/relationships/vbaProject', |
|||
'vbaProject.bin' |
|||
); |
|||
++$i;//increment i if needed for an another relation |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write worksheet relationships to XML format |
|||
* |
|||
* Numbering is as follows: |
|||
* rId1 - Drawings |
|||
* rId_hyperlink_x - Hyperlinks |
|||
* |
|||
* @param PHPExcel_Worksheet $pWorksheet |
|||
* @param int $pWorksheetId |
|||
* @param boolean $includeCharts Flag indicating if we should write charts |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeWorksheetRelationships(PHPExcel_Worksheet $pWorksheet = null, $pWorksheetId = 1, $includeCharts = false) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Relationships |
|||
$objWriter->startElement('Relationships'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|||
|
|||
// Write drawing relationships? |
|||
$d = 0; |
|||
if ($includeCharts) { |
|||
$charts = $pWorksheet->getChartCollection(); |
|||
} else { |
|||
$charts = array(); |
|||
} |
|||
if (($pWorksheet->getDrawingCollection()->count() > 0) || |
|||
(count($charts) > 0)) { |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
++$d, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing', |
|||
'../drawings/drawing' . $pWorksheetId . '.xml' |
|||
); |
|||
} |
|||
|
|||
// Write chart relationships? |
|||
// $chartCount = 0; |
|||
// $charts = $pWorksheet->getChartCollection(); |
|||
// echo 'Chart Rels: ' , count($charts) , '<br />'; |
|||
// if (count($charts) > 0) { |
|||
// foreach ($charts as $chart) { |
|||
// $this->writeRelationship( |
|||
// $objWriter, |
|||
// ++$d, |
|||
// 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', |
|||
// '../charts/chart' . ++$chartCount . '.xml' |
|||
// ); |
|||
// } |
|||
// } |
|||
// |
|||
// Write hyperlink relationships? |
|||
$i = 1; |
|||
foreach ($pWorksheet->getHyperlinkCollection() as $hyperlink) { |
|||
if (!$hyperlink->isInternal()) { |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
'_hyperlink_' . $i, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', |
|||
$hyperlink->getUrl(), |
|||
'External' |
|||
); |
|||
|
|||
++$i; |
|||
} |
|||
} |
|||
|
|||
// Write comments relationship? |
|||
$i = 1; |
|||
if (count($pWorksheet->getComments()) > 0) { |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
'_comments_vml' . $i, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing', |
|||
'../drawings/vmlDrawing' . $pWorksheetId . '.vml' |
|||
); |
|||
|
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
'_comments' . $i, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments', |
|||
'../comments' . $pWorksheetId . '.xml' |
|||
); |
|||
} |
|||
|
|||
// Write header/footer relationship? |
|||
$i = 1; |
|||
if (count($pWorksheet->getHeaderFooter()->getImages()) > 0) { |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
'_headerfooter_vml' . $i, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing', |
|||
'../drawings/vmlDrawingHF' . $pWorksheetId . '.vml' |
|||
); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write drawing relationships to XML format |
|||
* |
|||
* @param PHPExcel_Worksheet $pWorksheet |
|||
* @param int &$chartRef Chart ID |
|||
* @param boolean $includeCharts Flag indicating if we should write charts |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeDrawingRelationships(PHPExcel_Worksheet $pWorksheet = null, &$chartRef, $includeCharts = false) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Relationships |
|||
$objWriter->startElement('Relationships'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|||
|
|||
// Loop through images and write relationships |
|||
$i = 1; |
|||
$iterator = $pWorksheet->getDrawingCollection()->getIterator(); |
|||
while ($iterator->valid()) { |
|||
if ($iterator->current() instanceof PHPExcel_Worksheet_Drawing |
|||
|| $iterator->current() instanceof PHPExcel_Worksheet_MemoryDrawing) { |
|||
// Write relationship for image drawing |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
$i, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', |
|||
'../media/' . str_replace(' ', '', $iterator->current()->getIndexedFilename()) |
|||
); |
|||
} |
|||
|
|||
$iterator->next(); |
|||
++$i; |
|||
} |
|||
|
|||
if ($includeCharts) { |
|||
// Loop through charts and write relationships |
|||
$chartCount = $pWorksheet->getChartCount(); |
|||
if ($chartCount > 0) { |
|||
for ($c = 0; $c < $chartCount; ++$c) { |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
$i++, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', |
|||
'../charts/chart' . ++$chartRef . '.xml' |
|||
); |
|||
} |
|||
} |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write header/footer drawing relationships to XML format |
|||
* |
|||
* @param PHPExcel_Worksheet $pWorksheet |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeHeaderFooterDrawingRelationships(PHPExcel_Worksheet $pWorksheet = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Relationships |
|||
$objWriter->startElement('Relationships'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|||
|
|||
// Loop through images and write relationships |
|||
foreach ($pWorksheet->getHeaderFooter()->getImages() as $key => $value) { |
|||
// Write relationship for image drawing |
|||
$this->writeRelationship( |
|||
$objWriter, |
|||
$key, |
|||
'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', |
|||
'../media/' . $value->getIndexedFilename() |
|||
); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write Override content type |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param int $pId Relationship ID. rId will be prepended! |
|||
* @param string $pType Relationship type |
|||
* @param string $pTarget Relationship target |
|||
* @param string $pTargetMode Relationship target mode |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeRelationship(PHPExcel_Shared_XMLWriter $objWriter = null, $pId = 1, $pType = '', $pTarget = '', $pTargetMode = '') |
|||
{ |
|||
if ($pType != '' && $pTarget != '') { |
|||
// Write relationship |
|||
$objWriter->startElement('Relationship'); |
|||
$objWriter->writeAttribute('Id', 'rId' . $pId); |
|||
$objWriter->writeAttribute('Type', $pType); |
|||
$objWriter->writeAttribute('Target', $pTarget); |
|||
|
|||
if ($pTargetMode != '') { |
|||
$objWriter->writeAttribute('TargetMode', $pTargetMode); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Invalid parameters passed."); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_RelsRibbon |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_RelsRibbon extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write relationships for additional objects of custom UI (ribbon) |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeRibbonRelationships(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Relationships |
|||
$objWriter->startElement('Relationships'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|||
$localRels = $pPHPExcel->getRibbonBinObjects('names'); |
|||
if (is_array($localRels)) { |
|||
foreach ($localRels as $aId => $aTarget) { |
|||
$objWriter->startElement('Relationship'); |
|||
$objWriter->writeAttribute('Id', $aId); |
|||
$objWriter->writeAttribute('Type', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image'); |
|||
$objWriter->writeAttribute('Target', $aTarget); |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_RelsVBA |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_RelsVBA extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write relationships for a signed VBA Project |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeVBARelationships(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// Relationships |
|||
$objWriter->startElement('Relationships'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|||
$objWriter->startElement('Relationship'); |
|||
$objWriter->writeAttribute('Id', 'rId1'); |
|||
$objWriter->writeAttribute('Type', 'http://schemas.microsoft.com/office/2006/relationships/vbaProjectSignature'); |
|||
$objWriter->writeAttribute('Target', 'vbaProjectSignature.bin'); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,313 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_StringTable |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_StringTable extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Create worksheet stringtable |
|||
* |
|||
* @param PHPExcel_Worksheet $pSheet Worksheet |
|||
* @param string[] $pExistingTable Existing table to eventually merge with |
|||
* @return string[] String table for worksheet |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function createStringTable($pSheet = null, $pExistingTable = null) |
|||
{ |
|||
if ($pSheet !== null) { |
|||
// Create string lookup table |
|||
$aStringTable = array(); |
|||
$cellCollection = null; |
|||
$aFlippedStringTable = null; // For faster lookup |
|||
|
|||
// Is an existing table given? |
|||
if (($pExistingTable !== null) && is_array($pExistingTable)) { |
|||
$aStringTable = $pExistingTable; |
|||
} |
|||
|
|||
// Fill index array |
|||
$aFlippedStringTable = $this->flipStringTable($aStringTable); |
|||
|
|||
// Loop through cells |
|||
foreach ($pSheet->getCellCollection() as $cellID) { |
|||
$cell = $pSheet->getCell($cellID); |
|||
$cellValue = $cell->getValue(); |
|||
if (!is_object($cellValue) && |
|||
($cellValue !== null) && |
|||
$cellValue !== '' && |
|||
!isset($aFlippedStringTable[$cellValue]) && |
|||
($cell->getDataType() == PHPExcel_Cell_DataType::TYPE_STRING || $cell->getDataType() == PHPExcel_Cell_DataType::TYPE_STRING2 || $cell->getDataType() == PHPExcel_Cell_DataType::TYPE_NULL)) { |
|||
$aStringTable[] = $cellValue; |
|||
$aFlippedStringTable[$cellValue] = true; |
|||
} elseif ($cellValue instanceof PHPExcel_RichText && |
|||
($cellValue !== null) && |
|||
!isset($aFlippedStringTable[$cellValue->getHashCode()])) { |
|||
$aStringTable[] = $cellValue; |
|||
$aFlippedStringTable[$cellValue->getHashCode()] = true; |
|||
} |
|||
} |
|||
|
|||
return $aStringTable; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Invalid PHPExcel_Worksheet object passed."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write string table to XML format |
|||
* |
|||
* @param string[] $pStringTable |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeStringTable($pStringTable = null) |
|||
{ |
|||
if ($pStringTable !== null) { |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// String table |
|||
$objWriter->startElement('sst'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'); |
|||
$objWriter->writeAttribute('uniqueCount', count($pStringTable)); |
|||
|
|||
// Loop through string table |
|||
foreach ($pStringTable as $textElement) { |
|||
$objWriter->startElement('si'); |
|||
|
|||
if (! $textElement instanceof PHPExcel_RichText) { |
|||
$textToWrite = PHPExcel_Shared_String::ControlCharacterPHP2OOXML($textElement); |
|||
$objWriter->startElement('t'); |
|||
if ($textToWrite !== trim($textToWrite)) { |
|||
$objWriter->writeAttribute('xml:space', 'preserve'); |
|||
} |
|||
$objWriter->writeRawData($textToWrite); |
|||
$objWriter->endElement(); |
|||
} elseif ($textElement instanceof PHPExcel_RichText) { |
|||
$this->writeRichText($objWriter, $textElement); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Invalid string table array passed."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Rich Text |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_RichText $pRichText Rich text |
|||
* @param string $prefix Optional Namespace prefix |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeRichText(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_RichText $pRichText = null, $prefix = null) |
|||
{ |
|||
if ($prefix !== null) { |
|||
$prefix .= ':'; |
|||
} |
|||
|
|||
// Loop through rich text elements |
|||
$elements = $pRichText->getRichTextElements(); |
|||
foreach ($elements as $element) { |
|||
// r |
|||
$objWriter->startElement($prefix.'r'); |
|||
|
|||
// rPr |
|||
if ($element instanceof PHPExcel_RichText_Run) { |
|||
// rPr |
|||
$objWriter->startElement($prefix.'rPr'); |
|||
|
|||
// rFont |
|||
$objWriter->startElement($prefix.'rFont'); |
|||
$objWriter->writeAttribute('val', $element->getFont()->getName()); |
|||
$objWriter->endElement(); |
|||
|
|||
// Bold |
|||
$objWriter->startElement($prefix.'b'); |
|||
$objWriter->writeAttribute('val', ($element->getFont()->getBold() ? 'true' : 'false')); |
|||
$objWriter->endElement(); |
|||
|
|||
// Italic |
|||
$objWriter->startElement($prefix.'i'); |
|||
$objWriter->writeAttribute('val', ($element->getFont()->getItalic() ? 'true' : 'false')); |
|||
$objWriter->endElement(); |
|||
|
|||
// Superscript / subscript |
|||
if ($element->getFont()->getSuperScript() || $element->getFont()->getSubScript()) { |
|||
$objWriter->startElement($prefix.'vertAlign'); |
|||
if ($element->getFont()->getSuperScript()) { |
|||
$objWriter->writeAttribute('val', 'superscript'); |
|||
} elseif ($element->getFont()->getSubScript()) { |
|||
$objWriter->writeAttribute('val', 'subscript'); |
|||
} |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// Strikethrough |
|||
$objWriter->startElement($prefix.'strike'); |
|||
$objWriter->writeAttribute('val', ($element->getFont()->getStrikethrough() ? 'true' : 'false')); |
|||
$objWriter->endElement(); |
|||
|
|||
// Color |
|||
$objWriter->startElement($prefix.'color'); |
|||
$objWriter->writeAttribute('rgb', $element->getFont()->getColor()->getARGB()); |
|||
$objWriter->endElement(); |
|||
|
|||
// Size |
|||
$objWriter->startElement($prefix.'sz'); |
|||
$objWriter->writeAttribute('val', $element->getFont()->getSize()); |
|||
$objWriter->endElement(); |
|||
|
|||
// Underline |
|||
$objWriter->startElement($prefix.'u'); |
|||
$objWriter->writeAttribute('val', $element->getFont()->getUnderline()); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// t |
|||
$objWriter->startElement($prefix.'t'); |
|||
$objWriter->writeAttribute('xml:space', 'preserve'); |
|||
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML($element->getText())); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Rich Text |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param string|PHPExcel_RichText $pRichText text string or Rich text |
|||
* @param string $prefix Optional Namespace prefix |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeRichTextForCharts(PHPExcel_Shared_XMLWriter $objWriter = null, $pRichText = null, $prefix = null) |
|||
{ |
|||
if (!$pRichText instanceof PHPExcel_RichText) { |
|||
$textRun = $pRichText; |
|||
$pRichText = new PHPExcel_RichText(); |
|||
$pRichText->createTextRun($textRun); |
|||
} |
|||
|
|||
if ($prefix !== null) { |
|||
$prefix .= ':'; |
|||
} |
|||
|
|||
// Loop through rich text elements |
|||
$elements = $pRichText->getRichTextElements(); |
|||
foreach ($elements as $element) { |
|||
// r |
|||
$objWriter->startElement($prefix.'r'); |
|||
|
|||
// rPr |
|||
$objWriter->startElement($prefix.'rPr'); |
|||
|
|||
// Bold |
|||
$objWriter->writeAttribute('b', ($element->getFont()->getBold() ? 1 : 0)); |
|||
// Italic |
|||
$objWriter->writeAttribute('i', ($element->getFont()->getItalic() ? 1 : 0)); |
|||
// Underline |
|||
$underlineType = $element->getFont()->getUnderline(); |
|||
switch ($underlineType) { |
|||
case 'single': |
|||
$underlineType = 'sng'; |
|||
break; |
|||
case 'double': |
|||
$underlineType = 'dbl'; |
|||
break; |
|||
} |
|||
$objWriter->writeAttribute('u', $underlineType); |
|||
// Strikethrough |
|||
$objWriter->writeAttribute('strike', ($element->getFont()->getStrikethrough() ? 'sngStrike' : 'noStrike')); |
|||
|
|||
// rFont |
|||
$objWriter->startElement($prefix.'latin'); |
|||
$objWriter->writeAttribute('typeface', $element->getFont()->getName()); |
|||
$objWriter->endElement(); |
|||
|
|||
// Superscript / subscript |
|||
// if ($element->getFont()->getSuperScript() || $element->getFont()->getSubScript()) { |
|||
// $objWriter->startElement($prefix.'vertAlign'); |
|||
// if ($element->getFont()->getSuperScript()) { |
|||
// $objWriter->writeAttribute('val', 'superscript'); |
|||
// } elseif ($element->getFont()->getSubScript()) { |
|||
// $objWriter->writeAttribute('val', 'subscript'); |
|||
// } |
|||
// $objWriter->endElement(); |
|||
// } |
|||
// |
|||
$objWriter->endElement(); |
|||
|
|||
// t |
|||
$objWriter->startElement($prefix.'t'); |
|||
// $objWriter->writeAttribute('xml:space', 'preserve'); // Excel2010 accepts, Excel2007 complains |
|||
$objWriter->writeRawData(PHPExcel_Shared_String::ControlCharacterPHP2OOXML($element->getText())); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Flip string table (for index searching) |
|||
* |
|||
* @param array $stringTable Stringtable |
|||
* @return array |
|||
*/ |
|||
public function flipStringTable($stringTable = array()) |
|||
{ |
|||
// Return value |
|||
$returnValue = array(); |
|||
|
|||
// Loop through stringtable and add flipped items to $returnValue |
|||
foreach ($stringTable as $key => $value) { |
|||
if (! $value instanceof PHPExcel_RichText) { |
|||
$returnValue[$value] = $key; |
|||
} elseif ($value instanceof PHPExcel_RichText) { |
|||
$returnValue[$value->getHashCode()] = $key; |
|||
} |
|||
} |
|||
|
|||
return $returnValue; |
|||
} |
|||
} |
|||
@ -0,0 +1,696 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_Style |
|||
* |
|||
* 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_Excel2007 |
|||
* @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_Excel2007_Style extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write styles to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeStyles(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// styleSheet |
|||
$objWriter->startElement('styleSheet'); |
|||
$objWriter->writeAttribute('xml:space', 'preserve'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'); |
|||
|
|||
// numFmts |
|||
$objWriter->startElement('numFmts'); |
|||
$objWriter->writeAttribute('count', $this->getParentWriter()->getNumFmtHashTable()->count()); |
|||
|
|||
// numFmt |
|||
for ($i = 0; $i < $this->getParentWriter()->getNumFmtHashTable()->count(); ++$i) { |
|||
$this->writeNumFmt($objWriter, $this->getParentWriter()->getNumFmtHashTable()->getByIndex($i), $i); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// fonts |
|||
$objWriter->startElement('fonts'); |
|||
$objWriter->writeAttribute('count', $this->getParentWriter()->getFontHashTable()->count()); |
|||
|
|||
// font |
|||
for ($i = 0; $i < $this->getParentWriter()->getFontHashTable()->count(); ++$i) { |
|||
$this->writeFont($objWriter, $this->getParentWriter()->getFontHashTable()->getByIndex($i)); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// fills |
|||
$objWriter->startElement('fills'); |
|||
$objWriter->writeAttribute('count', $this->getParentWriter()->getFillHashTable()->count()); |
|||
|
|||
// fill |
|||
for ($i = 0; $i < $this->getParentWriter()->getFillHashTable()->count(); ++$i) { |
|||
$this->writeFill($objWriter, $this->getParentWriter()->getFillHashTable()->getByIndex($i)); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// borders |
|||
$objWriter->startElement('borders'); |
|||
$objWriter->writeAttribute('count', $this->getParentWriter()->getBordersHashTable()->count()); |
|||
|
|||
// border |
|||
for ($i = 0; $i < $this->getParentWriter()->getBordersHashTable()->count(); ++$i) { |
|||
$this->writeBorder($objWriter, $this->getParentWriter()->getBordersHashTable()->getByIndex($i)); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// cellStyleXfs |
|||
$objWriter->startElement('cellStyleXfs'); |
|||
$objWriter->writeAttribute('count', 1); |
|||
|
|||
// xf |
|||
$objWriter->startElement('xf'); |
|||
$objWriter->writeAttribute('numFmtId', 0); |
|||
$objWriter->writeAttribute('fontId', 0); |
|||
$objWriter->writeAttribute('fillId', 0); |
|||
$objWriter->writeAttribute('borderId', 0); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// cellXfs |
|||
$objWriter->startElement('cellXfs'); |
|||
$objWriter->writeAttribute('count', count($pPHPExcel->getCellXfCollection())); |
|||
|
|||
// xf |
|||
foreach ($pPHPExcel->getCellXfCollection() as $cellXf) { |
|||
$this->writeCellStyleXf($objWriter, $cellXf, $pPHPExcel); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// cellStyles |
|||
$objWriter->startElement('cellStyles'); |
|||
$objWriter->writeAttribute('count', 1); |
|||
|
|||
// cellStyle |
|||
$objWriter->startElement('cellStyle'); |
|||
$objWriter->writeAttribute('name', 'Normal'); |
|||
$objWriter->writeAttribute('xfId', 0); |
|||
$objWriter->writeAttribute('builtinId', 0); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// dxfs |
|||
$objWriter->startElement('dxfs'); |
|||
$objWriter->writeAttribute('count', $this->getParentWriter()->getStylesConditionalHashTable()->count()); |
|||
|
|||
// dxf |
|||
for ($i = 0; $i < $this->getParentWriter()->getStylesConditionalHashTable()->count(); ++$i) { |
|||
$this->writeCellStyleDxf($objWriter, $this->getParentWriter()->getStylesConditionalHashTable()->getByIndex($i)->getStyle()); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// tableStyles |
|||
$objWriter->startElement('tableStyles'); |
|||
$objWriter->writeAttribute('defaultTableStyle', 'TableStyleMedium9'); |
|||
$objWriter->writeAttribute('defaultPivotStyle', 'PivotTableStyle1'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write Fill |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Style_Fill $pFill Fill style |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null) |
|||
{ |
|||
// Check if this is a pattern type or gradient type |
|||
if ($pFill->getFillType() === PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR || |
|||
$pFill->getFillType() === PHPExcel_Style_Fill::FILL_GRADIENT_PATH) { |
|||
// Gradient fill |
|||
$this->writeGradientFill($objWriter, $pFill); |
|||
} elseif ($pFill->getFillType() !== null) { |
|||
// Pattern fill |
|||
$this->writePatternFill($objWriter, $pFill); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Gradient Fill |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Style_Fill $pFill Fill style |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeGradientFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null) |
|||
{ |
|||
// fill |
|||
$objWriter->startElement('fill'); |
|||
|
|||
// gradientFill |
|||
$objWriter->startElement('gradientFill'); |
|||
$objWriter->writeAttribute('type', $pFill->getFillType()); |
|||
$objWriter->writeAttribute('degree', $pFill->getRotation()); |
|||
|
|||
// stop |
|||
$objWriter->startElement('stop'); |
|||
$objWriter->writeAttribute('position', '0'); |
|||
|
|||
// color |
|||
$objWriter->startElement('color'); |
|||
$objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB()); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// stop |
|||
$objWriter->startElement('stop'); |
|||
$objWriter->writeAttribute('position', '1'); |
|||
|
|||
// color |
|||
$objWriter->startElement('color'); |
|||
$objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB()); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write Pattern Fill |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Style_Fill $pFill Fill style |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writePatternFill(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Fill $pFill = null) |
|||
{ |
|||
// fill |
|||
$objWriter->startElement('fill'); |
|||
|
|||
// patternFill |
|||
$objWriter->startElement('patternFill'); |
|||
$objWriter->writeAttribute('patternType', $pFill->getFillType()); |
|||
|
|||
if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) { |
|||
// fgColor |
|||
if ($pFill->getStartColor()->getARGB()) { |
|||
$objWriter->startElement('fgColor'); |
|||
$objWriter->writeAttribute('rgb', $pFill->getStartColor()->getARGB()); |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
if ($pFill->getFillType() !== PHPExcel_Style_Fill::FILL_NONE) { |
|||
// bgColor |
|||
if ($pFill->getEndColor()->getARGB()) { |
|||
$objWriter->startElement('bgColor'); |
|||
$objWriter->writeAttribute('rgb', $pFill->getEndColor()->getARGB()); |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write Font |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Style_Font $pFont Font style |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeFont(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Font $pFont = null) |
|||
{ |
|||
// font |
|||
$objWriter->startElement('font'); |
|||
// Weird! The order of these elements actually makes a difference when opening Excel2007 |
|||
// files in Excel2003 with the compatibility pack. It's not documented behaviour, |
|||
// and makes for a real WTF! |
|||
|
|||
// Bold. We explicitly write this element also when false (like MS Office Excel 2007 does |
|||
// for conditional formatting). Otherwise it will apparently not be picked up in conditional |
|||
// formatting style dialog |
|||
if ($pFont->getBold() !== null) { |
|||
$objWriter->startElement('b'); |
|||
$objWriter->writeAttribute('val', $pFont->getBold() ? '1' : '0'); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// Italic |
|||
if ($pFont->getItalic() !== null) { |
|||
$objWriter->startElement('i'); |
|||
$objWriter->writeAttribute('val', $pFont->getItalic() ? '1' : '0'); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// Strikethrough |
|||
if ($pFont->getStrikethrough() !== null) { |
|||
$objWriter->startElement('strike'); |
|||
$objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0'); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// Underline |
|||
if ($pFont->getUnderline() !== null) { |
|||
$objWriter->startElement('u'); |
|||
$objWriter->writeAttribute('val', $pFont->getUnderline()); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// Superscript / subscript |
|||
if ($pFont->getSuperScript() === true || $pFont->getSubScript() === true) { |
|||
$objWriter->startElement('vertAlign'); |
|||
if ($pFont->getSuperScript() === true) { |
|||
$objWriter->writeAttribute('val', 'superscript'); |
|||
} elseif ($pFont->getSubScript() === true) { |
|||
$objWriter->writeAttribute('val', 'subscript'); |
|||
} |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// Size |
|||
if ($pFont->getSize() !== null) { |
|||
$objWriter->startElement('sz'); |
|||
$objWriter->writeAttribute('val', $pFont->getSize()); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// Foreground color |
|||
if ($pFont->getColor()->getARGB() !== null) { |
|||
$objWriter->startElement('color'); |
|||
$objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB()); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
// Name |
|||
if ($pFont->getName() !== null) { |
|||
$objWriter->startElement('name'); |
|||
$objWriter->writeAttribute('val', $pFont->getName()); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write Border |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Style_Borders $pBorders Borders style |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeBorder(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_Borders $pBorders = null) |
|||
{ |
|||
// Write border |
|||
$objWriter->startElement('border'); |
|||
// Diagonal? |
|||
switch ($pBorders->getDiagonalDirection()) { |
|||
case PHPExcel_Style_Borders::DIAGONAL_UP: |
|||
$objWriter->writeAttribute('diagonalUp', 'true'); |
|||
$objWriter->writeAttribute('diagonalDown', 'false'); |
|||
break; |
|||
case PHPExcel_Style_Borders::DIAGONAL_DOWN: |
|||
$objWriter->writeAttribute('diagonalUp', 'false'); |
|||
$objWriter->writeAttribute('diagonalDown', 'true'); |
|||
break; |
|||
case PHPExcel_Style_Borders::DIAGONAL_BOTH: |
|||
$objWriter->writeAttribute('diagonalUp', 'true'); |
|||
$objWriter->writeAttribute('diagonalDown', 'true'); |
|||
break; |
|||
} |
|||
|
|||
// BorderPr |
|||
$this->writeBorderPr($objWriter, 'left', $pBorders->getLeft()); |
|||
$this->writeBorderPr($objWriter, 'right', $pBorders->getRight()); |
|||
$this->writeBorderPr($objWriter, 'top', $pBorders->getTop()); |
|||
$this->writeBorderPr($objWriter, 'bottom', $pBorders->getBottom()); |
|||
$this->writeBorderPr($objWriter, 'diagonal', $pBorders->getDiagonal()); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write Cell Style Xf |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Style $pStyle Style |
|||
* @param PHPExcel $pPHPExcel Workbook |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeCellStyleXf(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style $pStyle = null, PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// xf |
|||
$objWriter->startElement('xf'); |
|||
$objWriter->writeAttribute('xfId', 0); |
|||
$objWriter->writeAttribute('fontId', (int)$this->getParentWriter()->getFontHashTable()->getIndexForHashCode($pStyle->getFont()->getHashCode())); |
|||
if ($pStyle->getQuotePrefix()) { |
|||
$objWriter->writeAttribute('quotePrefix', 1); |
|||
} |
|||
|
|||
if ($pStyle->getNumberFormat()->getBuiltInFormatCode() === false) { |
|||
$objWriter->writeAttribute('numFmtId', (int)($this->getParentWriter()->getNumFmtHashTable()->getIndexForHashCode($pStyle->getNumberFormat()->getHashCode()) + 164)); |
|||
} else { |
|||
$objWriter->writeAttribute('numFmtId', (int)$pStyle->getNumberFormat()->getBuiltInFormatCode()); |
|||
} |
|||
|
|||
$objWriter->writeAttribute('fillId', (int)$this->getParentWriter()->getFillHashTable()->getIndexForHashCode($pStyle->getFill()->getHashCode())); |
|||
$objWriter->writeAttribute('borderId', (int)$this->getParentWriter()->getBordersHashTable()->getIndexForHashCode($pStyle->getBorders()->getHashCode())); |
|||
|
|||
// Apply styles? |
|||
$objWriter->writeAttribute('applyFont', ($pPHPExcel->getDefaultStyle()->getFont()->getHashCode() != $pStyle->getFont()->getHashCode()) ? '1' : '0'); |
|||
$objWriter->writeAttribute('applyNumberFormat', ($pPHPExcel->getDefaultStyle()->getNumberFormat()->getHashCode() != $pStyle->getNumberFormat()->getHashCode()) ? '1' : '0'); |
|||
$objWriter->writeAttribute('applyFill', ($pPHPExcel->getDefaultStyle()->getFill()->getHashCode() != $pStyle->getFill()->getHashCode()) ? '1' : '0'); |
|||
$objWriter->writeAttribute('applyBorder', ($pPHPExcel->getDefaultStyle()->getBorders()->getHashCode() != $pStyle->getBorders()->getHashCode()) ? '1' : '0'); |
|||
$objWriter->writeAttribute('applyAlignment', ($pPHPExcel->getDefaultStyle()->getAlignment()->getHashCode() != $pStyle->getAlignment()->getHashCode()) ? '1' : '0'); |
|||
if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) { |
|||
$objWriter->writeAttribute('applyProtection', 'true'); |
|||
} |
|||
|
|||
// alignment |
|||
$objWriter->startElement('alignment'); |
|||
$objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal()); |
|||
$objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical()); |
|||
|
|||
$textRotation = 0; |
|||
if ($pStyle->getAlignment()->getTextRotation() >= 0) { |
|||
$textRotation = $pStyle->getAlignment()->getTextRotation(); |
|||
} elseif ($pStyle->getAlignment()->getTextRotation() < 0) { |
|||
$textRotation = 90 - $pStyle->getAlignment()->getTextRotation(); |
|||
} |
|||
$objWriter->writeAttribute('textRotation', $textRotation); |
|||
|
|||
$objWriter->writeAttribute('wrapText', ($pStyle->getAlignment()->getWrapText() ? 'true' : 'false')); |
|||
$objWriter->writeAttribute('shrinkToFit', ($pStyle->getAlignment()->getShrinkToFit() ? 'true' : 'false')); |
|||
|
|||
if ($pStyle->getAlignment()->getIndent() > 0) { |
|||
$objWriter->writeAttribute('indent', $pStyle->getAlignment()->getIndent()); |
|||
} |
|||
if ($pStyle->getAlignment()->getReadorder() > 0) { |
|||
$objWriter->writeAttribute('readingOrder', $pStyle->getAlignment()->getReadorder()); |
|||
} |
|||
$objWriter->endElement(); |
|||
|
|||
// protection |
|||
if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT || $pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) { |
|||
$objWriter->startElement('protection'); |
|||
if ($pStyle->getProtection()->getLocked() != PHPExcel_Style_Protection::PROTECTION_INHERIT) { |
|||
$objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false')); |
|||
} |
|||
if ($pStyle->getProtection()->getHidden() != PHPExcel_Style_Protection::PROTECTION_INHERIT) { |
|||
$objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false')); |
|||
} |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write Cell Style Dxf |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Style $pStyle Style |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeCellStyleDxf(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style $pStyle = null) |
|||
{ |
|||
// dxf |
|||
$objWriter->startElement('dxf'); |
|||
|
|||
// font |
|||
$this->writeFont($objWriter, $pStyle->getFont()); |
|||
|
|||
// numFmt |
|||
$this->writeNumFmt($objWriter, $pStyle->getNumberFormat()); |
|||
|
|||
// fill |
|||
$this->writeFill($objWriter, $pStyle->getFill()); |
|||
|
|||
// alignment |
|||
$objWriter->startElement('alignment'); |
|||
if ($pStyle->getAlignment()->getHorizontal() !== null) { |
|||
$objWriter->writeAttribute('horizontal', $pStyle->getAlignment()->getHorizontal()); |
|||
} |
|||
if ($pStyle->getAlignment()->getVertical() !== null) { |
|||
$objWriter->writeAttribute('vertical', $pStyle->getAlignment()->getVertical()); |
|||
} |
|||
|
|||
if ($pStyle->getAlignment()->getTextRotation() !== null) { |
|||
$textRotation = 0; |
|||
if ($pStyle->getAlignment()->getTextRotation() >= 0) { |
|||
$textRotation = $pStyle->getAlignment()->getTextRotation(); |
|||
} elseif ($pStyle->getAlignment()->getTextRotation() < 0) { |
|||
$textRotation = 90 - $pStyle->getAlignment()->getTextRotation(); |
|||
} |
|||
$objWriter->writeAttribute('textRotation', $textRotation); |
|||
} |
|||
$objWriter->endElement(); |
|||
|
|||
// border |
|||
$this->writeBorder($objWriter, $pStyle->getBorders()); |
|||
|
|||
// protection |
|||
if (($pStyle->getProtection()->getLocked() !== null) || ($pStyle->getProtection()->getHidden() !== null)) { |
|||
if ($pStyle->getProtection()->getLocked() !== PHPExcel_Style_Protection::PROTECTION_INHERIT || |
|||
$pStyle->getProtection()->getHidden() !== PHPExcel_Style_Protection::PROTECTION_INHERIT) { |
|||
$objWriter->startElement('protection'); |
|||
if (($pStyle->getProtection()->getLocked() !== null) && |
|||
($pStyle->getProtection()->getLocked() !== PHPExcel_Style_Protection::PROTECTION_INHERIT)) { |
|||
$objWriter->writeAttribute('locked', ($pStyle->getProtection()->getLocked() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false')); |
|||
} |
|||
if (($pStyle->getProtection()->getHidden() !== null) && |
|||
($pStyle->getProtection()->getHidden() !== PHPExcel_Style_Protection::PROTECTION_INHERIT)) { |
|||
$objWriter->writeAttribute('hidden', ($pStyle->getProtection()->getHidden() == PHPExcel_Style_Protection::PROTECTION_PROTECTED ? 'true' : 'false')); |
|||
} |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write BorderPr |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param string $pName Element name |
|||
* @param PHPExcel_Style_Border $pBorder Border style |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeBorderPr(PHPExcel_Shared_XMLWriter $objWriter = null, $pName = 'left', PHPExcel_Style_Border $pBorder = null) |
|||
{ |
|||
// Write BorderPr |
|||
if ($pBorder->getBorderStyle() != PHPExcel_Style_Border::BORDER_NONE) { |
|||
$objWriter->startElement($pName); |
|||
$objWriter->writeAttribute('style', $pBorder->getBorderStyle()); |
|||
|
|||
// color |
|||
$objWriter->startElement('color'); |
|||
$objWriter->writeAttribute('rgb', $pBorder->getColor()->getARGB()); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write NumberFormat |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Style_NumberFormat $pNumberFormat Number Format |
|||
* @param int $pId Number Format identifier |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeNumFmt(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Style_NumberFormat $pNumberFormat = null, $pId = 0) |
|||
{ |
|||
// Translate formatcode |
|||
$formatCode = $pNumberFormat->getFormatCode(); |
|||
|
|||
// numFmt |
|||
if ($formatCode !== null) { |
|||
$objWriter->startElement('numFmt'); |
|||
$objWriter->writeAttribute('numFmtId', ($pId + 164)); |
|||
$objWriter->writeAttribute('formatCode', $formatCode); |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get an array of all styles |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return PHPExcel_Style[] All styles in PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function allStyles(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
return $pPHPExcel->getCellXfCollection(); |
|||
} |
|||
|
|||
/** |
|||
* Get an array of all conditional styles |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return PHPExcel_Style_Conditional[] All conditional styles in PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function allConditionalStyles(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Get an array of all styles |
|||
$aStyles = array(); |
|||
|
|||
$sheetCount = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
foreach ($pPHPExcel->getSheet($i)->getConditionalStylesCollection() as $conditionalStyles) { |
|||
foreach ($conditionalStyles as $conditionalStyle) { |
|||
$aStyles[] = $conditionalStyle; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return $aStyles; |
|||
} |
|||
|
|||
/** |
|||
* Get an array of all fills |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return PHPExcel_Style_Fill[] All fills in PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function allFills(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Get an array of unique fills |
|||
$aFills = array(); |
|||
|
|||
// Two first fills are predefined |
|||
$fill0 = new PHPExcel_Style_Fill(); |
|||
$fill0->setFillType(PHPExcel_Style_Fill::FILL_NONE); |
|||
$aFills[] = $fill0; |
|||
|
|||
$fill1 = new PHPExcel_Style_Fill(); |
|||
$fill1->setFillType(PHPExcel_Style_Fill::FILL_PATTERN_GRAY125); |
|||
$aFills[] = $fill1; |
|||
// The remaining fills |
|||
$aStyles = $this->allStyles($pPHPExcel); |
|||
foreach ($aStyles as $style) { |
|||
if (!array_key_exists($style->getFill()->getHashCode(), $aFills)) { |
|||
$aFills[ $style->getFill()->getHashCode() ] = $style->getFill(); |
|||
} |
|||
} |
|||
|
|||
return $aFills; |
|||
} |
|||
|
|||
/** |
|||
* Get an array of all fonts |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return PHPExcel_Style_Font[] All fonts in PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function allFonts(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Get an array of unique fonts |
|||
$aFonts = array(); |
|||
$aStyles = $this->allStyles($pPHPExcel); |
|||
|
|||
foreach ($aStyles as $style) { |
|||
if (!array_key_exists($style->getFont()->getHashCode(), $aFonts)) { |
|||
$aFonts[ $style->getFont()->getHashCode() ] = $style->getFont(); |
|||
} |
|||
} |
|||
|
|||
return $aFonts; |
|||
} |
|||
|
|||
/** |
|||
* Get an array of all borders |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return PHPExcel_Style_Borders[] All borders in PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function allBorders(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Get an array of unique borders |
|||
$aBorders = array(); |
|||
$aStyles = $this->allStyles($pPHPExcel); |
|||
|
|||
foreach ($aStyles as $style) { |
|||
if (!array_key_exists($style->getBorders()->getHashCode(), $aBorders)) { |
|||
$aBorders[ $style->getBorders()->getHashCode() ] = $style->getBorders(); |
|||
} |
|||
} |
|||
|
|||
return $aBorders; |
|||
} |
|||
|
|||
/** |
|||
* Get an array of all number formats |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return PHPExcel_Style_NumberFormat[] All number formats in PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function allNumberFormats(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Get an array of unique number formats |
|||
$aNumFmts = array(); |
|||
$aStyles = $this->allStyles($pPHPExcel); |
|||
|
|||
foreach ($aStyles as $style) { |
|||
if ($style->getNumberFormat()->getBuiltInFormatCode() === false && !array_key_exists($style->getNumberFormat()->getHashCode(), $aNumFmts)) { |
|||
$aNumFmts[ $style->getNumberFormat()->getHashCode() ] = $style->getNumberFormat(); |
|||
} |
|||
} |
|||
|
|||
return $aNumFmts; |
|||
} |
|||
} |
|||
@ -0,0 +1,869 @@ |
|||
<?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_Writer_Excel2007 |
|||
* @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## |
|||
*/ |
|||
|
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_Theme |
|||
* |
|||
* @category PHPExcel |
|||
* @package PHPExcel_Writer_Excel2007 |
|||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) |
|||
*/ |
|||
class PHPExcel_Writer_Excel2007_Theme extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Map of Major fonts to write |
|||
* @static array of string |
|||
* |
|||
*/ |
|||
private static $majorFonts = array( |
|||
'Jpan' => 'MS Pゴシック', |
|||
'Hang' => '맑은 고딕', |
|||
'Hans' => '宋体', |
|||
'Hant' => '新細明體', |
|||
'Arab' => 'Times New Roman', |
|||
'Hebr' => 'Times New Roman', |
|||
'Thai' => 'Tahoma', |
|||
'Ethi' => 'Nyala', |
|||
'Beng' => 'Vrinda', |
|||
'Gujr' => 'Shruti', |
|||
'Khmr' => 'MoolBoran', |
|||
'Knda' => 'Tunga', |
|||
'Guru' => 'Raavi', |
|||
'Cans' => 'Euphemia', |
|||
'Cher' => 'Plantagenet Cherokee', |
|||
'Yiii' => 'Microsoft Yi Baiti', |
|||
'Tibt' => 'Microsoft Himalaya', |
|||
'Thaa' => 'MV Boli', |
|||
'Deva' => 'Mangal', |
|||
'Telu' => 'Gautami', |
|||
'Taml' => 'Latha', |
|||
'Syrc' => 'Estrangelo Edessa', |
|||
'Orya' => 'Kalinga', |
|||
'Mlym' => 'Kartika', |
|||
'Laoo' => 'DokChampa', |
|||
'Sinh' => 'Iskoola Pota', |
|||
'Mong' => 'Mongolian Baiti', |
|||
'Viet' => 'Times New Roman', |
|||
'Uigh' => 'Microsoft Uighur', |
|||
'Geor' => 'Sylfaen', |
|||
); |
|||
|
|||
/** |
|||
* Map of Minor fonts to write |
|||
* @static array of string |
|||
* |
|||
*/ |
|||
private static $minorFonts = array( |
|||
'Jpan' => 'MS Pゴシック', |
|||
'Hang' => '맑은 고딕', |
|||
'Hans' => '宋体', |
|||
'Hant' => '新細明體', |
|||
'Arab' => 'Arial', |
|||
'Hebr' => 'Arial', |
|||
'Thai' => 'Tahoma', |
|||
'Ethi' => 'Nyala', |
|||
'Beng' => 'Vrinda', |
|||
'Gujr' => 'Shruti', |
|||
'Khmr' => 'DaunPenh', |
|||
'Knda' => 'Tunga', |
|||
'Guru' => 'Raavi', |
|||
'Cans' => 'Euphemia', |
|||
'Cher' => 'Plantagenet Cherokee', |
|||
'Yiii' => 'Microsoft Yi Baiti', |
|||
'Tibt' => 'Microsoft Himalaya', |
|||
'Thaa' => 'MV Boli', |
|||
'Deva' => 'Mangal', |
|||
'Telu' => 'Gautami', |
|||
'Taml' => 'Latha', |
|||
'Syrc' => 'Estrangelo Edessa', |
|||
'Orya' => 'Kalinga', |
|||
'Mlym' => 'Kartika', |
|||
'Laoo' => 'DokChampa', |
|||
'Sinh' => 'Iskoola Pota', |
|||
'Mong' => 'Mongolian Baiti', |
|||
'Viet' => 'Arial', |
|||
'Uigh' => 'Microsoft Uighur', |
|||
'Geor' => 'Sylfaen', |
|||
); |
|||
|
|||
/** |
|||
* Map of core colours |
|||
* @static array of string |
|||
* |
|||
*/ |
|||
private static $colourScheme = array( |
|||
'dk2' => '1F497D', |
|||
'lt2' => 'EEECE1', |
|||
'accent1' => '4F81BD', |
|||
'accent2' => 'C0504D', |
|||
'accent3' => '9BBB59', |
|||
'accent4' => '8064A2', |
|||
'accent5' => '4BACC6', |
|||
'accent6' => 'F79646', |
|||
'hlink' => '0000FF', |
|||
'folHlink' => '800080', |
|||
); |
|||
|
|||
/** |
|||
* Write theme to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeTheme(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// a:theme |
|||
$objWriter->startElement('a:theme'); |
|||
$objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); |
|||
$objWriter->writeAttribute('name', 'Office Theme'); |
|||
|
|||
// a:themeElements |
|||
$objWriter->startElement('a:themeElements'); |
|||
|
|||
// a:clrScheme |
|||
$objWriter->startElement('a:clrScheme'); |
|||
$objWriter->writeAttribute('name', 'Office'); |
|||
|
|||
// a:dk1 |
|||
$objWriter->startElement('a:dk1'); |
|||
|
|||
// a:sysClr |
|||
$objWriter->startElement('a:sysClr'); |
|||
$objWriter->writeAttribute('val', 'windowText'); |
|||
$objWriter->writeAttribute('lastClr', '000000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:lt1 |
|||
$objWriter->startElement('a:lt1'); |
|||
|
|||
// a:sysClr |
|||
$objWriter->startElement('a:sysClr'); |
|||
$objWriter->writeAttribute('val', 'window'); |
|||
$objWriter->writeAttribute('lastClr', 'FFFFFF'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:dk2 |
|||
$this->writeColourScheme($objWriter); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:fontScheme |
|||
$objWriter->startElement('a:fontScheme'); |
|||
$objWriter->writeAttribute('name', 'Office'); |
|||
|
|||
// a:majorFont |
|||
$objWriter->startElement('a:majorFont'); |
|||
$this->writeFonts($objWriter, 'Cambria', self::$majorFonts); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:minorFont |
|||
$objWriter->startElement('a:minorFont'); |
|||
$this->writeFonts($objWriter, 'Calibri', self::$minorFonts); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:fmtScheme |
|||
$objWriter->startElement('a:fmtScheme'); |
|||
$objWriter->writeAttribute('name', 'Office'); |
|||
|
|||
// a:fillStyleLst |
|||
$objWriter->startElement('a:fillStyleLst'); |
|||
|
|||
// a:solidFill |
|||
$objWriter->startElement('a:solidFill'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gradFill |
|||
$objWriter->startElement('a:gradFill'); |
|||
$objWriter->writeAttribute('rotWithShape', '1'); |
|||
|
|||
// a:gsLst |
|||
$objWriter->startElement('a:gsLst'); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '0'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:tint |
|||
$objWriter->startElement('a:tint'); |
|||
$objWriter->writeAttribute('val', '50000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '300000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '35000'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:tint |
|||
$objWriter->startElement('a:tint'); |
|||
$objWriter->writeAttribute('val', '37000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '300000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '100000'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:tint |
|||
$objWriter->startElement('a:tint'); |
|||
$objWriter->writeAttribute('val', '15000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '350000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:lin |
|||
$objWriter->startElement('a:lin'); |
|||
$objWriter->writeAttribute('ang', '16200000'); |
|||
$objWriter->writeAttribute('scaled', '1'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gradFill |
|||
$objWriter->startElement('a:gradFill'); |
|||
$objWriter->writeAttribute('rotWithShape', '1'); |
|||
|
|||
// a:gsLst |
|||
$objWriter->startElement('a:gsLst'); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '0'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:shade |
|||
$objWriter->startElement('a:shade'); |
|||
$objWriter->writeAttribute('val', '51000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '130000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '80000'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:shade |
|||
$objWriter->startElement('a:shade'); |
|||
$objWriter->writeAttribute('val', '93000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '130000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '100000'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:shade |
|||
$objWriter->startElement('a:shade'); |
|||
$objWriter->writeAttribute('val', '94000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '135000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:lin |
|||
$objWriter->startElement('a:lin'); |
|||
$objWriter->writeAttribute('ang', '16200000'); |
|||
$objWriter->writeAttribute('scaled', '0'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:lnStyleLst |
|||
$objWriter->startElement('a:lnStyleLst'); |
|||
|
|||
// a:ln |
|||
$objWriter->startElement('a:ln'); |
|||
$objWriter->writeAttribute('w', '9525'); |
|||
$objWriter->writeAttribute('cap', 'flat'); |
|||
$objWriter->writeAttribute('cmpd', 'sng'); |
|||
$objWriter->writeAttribute('algn', 'ctr'); |
|||
|
|||
// a:solidFill |
|||
$objWriter->startElement('a:solidFill'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:shade |
|||
$objWriter->startElement('a:shade'); |
|||
$objWriter->writeAttribute('val', '95000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '105000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:prstDash |
|||
$objWriter->startElement('a:prstDash'); |
|||
$objWriter->writeAttribute('val', 'solid'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:ln |
|||
$objWriter->startElement('a:ln'); |
|||
$objWriter->writeAttribute('w', '25400'); |
|||
$objWriter->writeAttribute('cap', 'flat'); |
|||
$objWriter->writeAttribute('cmpd', 'sng'); |
|||
$objWriter->writeAttribute('algn', 'ctr'); |
|||
|
|||
// a:solidFill |
|||
$objWriter->startElement('a:solidFill'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:prstDash |
|||
$objWriter->startElement('a:prstDash'); |
|||
$objWriter->writeAttribute('val', 'solid'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:ln |
|||
$objWriter->startElement('a:ln'); |
|||
$objWriter->writeAttribute('w', '38100'); |
|||
$objWriter->writeAttribute('cap', 'flat'); |
|||
$objWriter->writeAttribute('cmpd', 'sng'); |
|||
$objWriter->writeAttribute('algn', 'ctr'); |
|||
|
|||
// a:solidFill |
|||
$objWriter->startElement('a:solidFill'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:prstDash |
|||
$objWriter->startElement('a:prstDash'); |
|||
$objWriter->writeAttribute('val', 'solid'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
|
|||
|
|||
// a:effectStyleLst |
|||
$objWriter->startElement('a:effectStyleLst'); |
|||
|
|||
// a:effectStyle |
|||
$objWriter->startElement('a:effectStyle'); |
|||
|
|||
// a:effectLst |
|||
$objWriter->startElement('a:effectLst'); |
|||
|
|||
// a:outerShdw |
|||
$objWriter->startElement('a:outerShdw'); |
|||
$objWriter->writeAttribute('blurRad', '40000'); |
|||
$objWriter->writeAttribute('dist', '20000'); |
|||
$objWriter->writeAttribute('dir', '5400000'); |
|||
$objWriter->writeAttribute('rotWithShape', '0'); |
|||
|
|||
// a:srgbClr |
|||
$objWriter->startElement('a:srgbClr'); |
|||
$objWriter->writeAttribute('val', '000000'); |
|||
|
|||
// a:alpha |
|||
$objWriter->startElement('a:alpha'); |
|||
$objWriter->writeAttribute('val', '38000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:effectStyle |
|||
$objWriter->startElement('a:effectStyle'); |
|||
|
|||
// a:effectLst |
|||
$objWriter->startElement('a:effectLst'); |
|||
|
|||
// a:outerShdw |
|||
$objWriter->startElement('a:outerShdw'); |
|||
$objWriter->writeAttribute('blurRad', '40000'); |
|||
$objWriter->writeAttribute('dist', '23000'); |
|||
$objWriter->writeAttribute('dir', '5400000'); |
|||
$objWriter->writeAttribute('rotWithShape', '0'); |
|||
|
|||
// a:srgbClr |
|||
$objWriter->startElement('a:srgbClr'); |
|||
$objWriter->writeAttribute('val', '000000'); |
|||
|
|||
// a:alpha |
|||
$objWriter->startElement('a:alpha'); |
|||
$objWriter->writeAttribute('val', '35000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:effectStyle |
|||
$objWriter->startElement('a:effectStyle'); |
|||
|
|||
// a:effectLst |
|||
$objWriter->startElement('a:effectLst'); |
|||
|
|||
// a:outerShdw |
|||
$objWriter->startElement('a:outerShdw'); |
|||
$objWriter->writeAttribute('blurRad', '40000'); |
|||
$objWriter->writeAttribute('dist', '23000'); |
|||
$objWriter->writeAttribute('dir', '5400000'); |
|||
$objWriter->writeAttribute('rotWithShape', '0'); |
|||
|
|||
// a:srgbClr |
|||
$objWriter->startElement('a:srgbClr'); |
|||
$objWriter->writeAttribute('val', '000000'); |
|||
|
|||
// a:alpha |
|||
$objWriter->startElement('a:alpha'); |
|||
$objWriter->writeAttribute('val', '35000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:scene3d |
|||
$objWriter->startElement('a:scene3d'); |
|||
|
|||
// a:camera |
|||
$objWriter->startElement('a:camera'); |
|||
$objWriter->writeAttribute('prst', 'orthographicFront'); |
|||
|
|||
// a:rot |
|||
$objWriter->startElement('a:rot'); |
|||
$objWriter->writeAttribute('lat', '0'); |
|||
$objWriter->writeAttribute('lon', '0'); |
|||
$objWriter->writeAttribute('rev', '0'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:lightRig |
|||
$objWriter->startElement('a:lightRig'); |
|||
$objWriter->writeAttribute('rig', 'threePt'); |
|||
$objWriter->writeAttribute('dir', 't'); |
|||
|
|||
// a:rot |
|||
$objWriter->startElement('a:rot'); |
|||
$objWriter->writeAttribute('lat', '0'); |
|||
$objWriter->writeAttribute('lon', '0'); |
|||
$objWriter->writeAttribute('rev', '1200000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:sp3d |
|||
$objWriter->startElement('a:sp3d'); |
|||
|
|||
// a:bevelT |
|||
$objWriter->startElement('a:bevelT'); |
|||
$objWriter->writeAttribute('w', '63500'); |
|||
$objWriter->writeAttribute('h', '25400'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:bgFillStyleLst |
|||
$objWriter->startElement('a:bgFillStyleLst'); |
|||
|
|||
// a:solidFill |
|||
$objWriter->startElement('a:solidFill'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gradFill |
|||
$objWriter->startElement('a:gradFill'); |
|||
$objWriter->writeAttribute('rotWithShape', '1'); |
|||
|
|||
// a:gsLst |
|||
$objWriter->startElement('a:gsLst'); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '0'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:tint |
|||
$objWriter->startElement('a:tint'); |
|||
$objWriter->writeAttribute('val', '40000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '350000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '40000'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:tint |
|||
$objWriter->startElement('a:tint'); |
|||
$objWriter->writeAttribute('val', '45000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:shade |
|||
$objWriter->startElement('a:shade'); |
|||
$objWriter->writeAttribute('val', '99000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '350000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '100000'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:shade |
|||
$objWriter->startElement('a:shade'); |
|||
$objWriter->writeAttribute('val', '20000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '255000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:path |
|||
$objWriter->startElement('a:path'); |
|||
$objWriter->writeAttribute('path', 'circle'); |
|||
|
|||
// a:fillToRect |
|||
$objWriter->startElement('a:fillToRect'); |
|||
$objWriter->writeAttribute('l', '50000'); |
|||
$objWriter->writeAttribute('t', '-80000'); |
|||
$objWriter->writeAttribute('r', '50000'); |
|||
$objWriter->writeAttribute('b', '180000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gradFill |
|||
$objWriter->startElement('a:gradFill'); |
|||
$objWriter->writeAttribute('rotWithShape', '1'); |
|||
|
|||
// a:gsLst |
|||
$objWriter->startElement('a:gsLst'); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '0'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:tint |
|||
$objWriter->startElement('a:tint'); |
|||
$objWriter->writeAttribute('val', '80000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '300000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:gs |
|||
$objWriter->startElement('a:gs'); |
|||
$objWriter->writeAttribute('pos', '100000'); |
|||
|
|||
// a:schemeClr |
|||
$objWriter->startElement('a:schemeClr'); |
|||
$objWriter->writeAttribute('val', 'phClr'); |
|||
|
|||
// a:shade |
|||
$objWriter->startElement('a:shade'); |
|||
$objWriter->writeAttribute('val', '30000'); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:satMod |
|||
$objWriter->startElement('a:satMod'); |
|||
$objWriter->writeAttribute('val', '200000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:path |
|||
$objWriter->startElement('a:path'); |
|||
$objWriter->writeAttribute('path', 'circle'); |
|||
|
|||
// a:fillToRect |
|||
$objWriter->startElement('a:fillToRect'); |
|||
$objWriter->writeAttribute('l', '50000'); |
|||
$objWriter->writeAttribute('t', '50000'); |
|||
$objWriter->writeAttribute('r', '50000'); |
|||
$objWriter->writeAttribute('b', '50000'); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// a:objectDefaults |
|||
$objWriter->writeElement('a:objectDefaults', null); |
|||
|
|||
// a:extraClrSchemeLst |
|||
$objWriter->writeElement('a:extraClrSchemeLst', null); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write fonts to XML format |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter |
|||
* @param string $latinFont |
|||
* @param array of string $fontSet |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeFonts($objWriter, $latinFont, $fontSet) |
|||
{ |
|||
// a:latin |
|||
$objWriter->startElement('a:latin'); |
|||
$objWriter->writeAttribute('typeface', $latinFont); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:ea |
|||
$objWriter->startElement('a:ea'); |
|||
$objWriter->writeAttribute('typeface', ''); |
|||
$objWriter->endElement(); |
|||
|
|||
// a:cs |
|||
$objWriter->startElement('a:cs'); |
|||
$objWriter->writeAttribute('typeface', ''); |
|||
$objWriter->endElement(); |
|||
|
|||
foreach ($fontSet as $fontScript => $typeface) { |
|||
$objWriter->startElement('a:font'); |
|||
$objWriter->writeAttribute('script', $fontScript); |
|||
$objWriter->writeAttribute('typeface', $typeface); |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write colour scheme to XML format |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeColourScheme($objWriter) |
|||
{ |
|||
foreach (self::$colourScheme as $colourName => $colourValue) { |
|||
$objWriter->startElement('a:'.$colourName); |
|||
|
|||
$objWriter->startElement('a:srgbClr'); |
|||
$objWriter->writeAttribute('val', $colourValue); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,448 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_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_Excel2007 |
|||
* @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_Excel2007_Workbook extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Write workbook to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @param boolean $recalcRequired Indicate whether formulas should be recalculated before writing |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeWorkbook(PHPExcel $pPHPExcel = null, $recalcRequired = false) |
|||
{ |
|||
// Create XML writer |
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|||
|
|||
// workbook |
|||
$objWriter->startElement('workbook'); |
|||
$objWriter->writeAttribute('xml:space', 'preserve'); |
|||
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'); |
|||
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|||
|
|||
// fileVersion |
|||
$this->writeFileVersion($objWriter); |
|||
|
|||
// workbookPr |
|||
$this->writeWorkbookPr($objWriter); |
|||
|
|||
// workbookProtection |
|||
$this->writeWorkbookProtection($objWriter, $pPHPExcel); |
|||
|
|||
// bookViews |
|||
if ($this->getParentWriter()->getOffice2003Compatibility() === false) { |
|||
$this->writeBookViews($objWriter, $pPHPExcel); |
|||
} |
|||
|
|||
// sheets |
|||
$this->writeSheets($objWriter, $pPHPExcel); |
|||
|
|||
// definedNames |
|||
$this->writeDefinedNames($objWriter, $pPHPExcel); |
|||
|
|||
// calcPr |
|||
$this->writeCalcPr($objWriter, $recalcRequired); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
// Return |
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write file version |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeFileVersion(PHPExcel_Shared_XMLWriter $objWriter = null) |
|||
{ |
|||
$objWriter->startElement('fileVersion'); |
|||
$objWriter->writeAttribute('appName', 'xl'); |
|||
$objWriter->writeAttribute('lastEdited', '4'); |
|||
$objWriter->writeAttribute('lowestEdited', '4'); |
|||
$objWriter->writeAttribute('rupBuild', '4505'); |
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write WorkbookPr |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeWorkbookPr(PHPExcel_Shared_XMLWriter $objWriter = null) |
|||
{ |
|||
$objWriter->startElement('workbookPr'); |
|||
|
|||
if (PHPExcel_Shared_Date::getExcelCalendar() == PHPExcel_Shared_Date::CALENDAR_MAC_1904) { |
|||
$objWriter->writeAttribute('date1904', '1'); |
|||
} |
|||
|
|||
$objWriter->writeAttribute('codeName', 'ThisWorkbook'); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write BookViews |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel $pPHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeBookViews(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// bookViews |
|||
$objWriter->startElement('bookViews'); |
|||
|
|||
// workbookView |
|||
$objWriter->startElement('workbookView'); |
|||
|
|||
$objWriter->writeAttribute('activeTab', $pPHPExcel->getActiveSheetIndex()); |
|||
$objWriter->writeAttribute('autoFilterDateGrouping', '1'); |
|||
$objWriter->writeAttribute('firstSheet', '0'); |
|||
$objWriter->writeAttribute('minimized', '0'); |
|||
$objWriter->writeAttribute('showHorizontalScroll', '1'); |
|||
$objWriter->writeAttribute('showSheetTabs', '1'); |
|||
$objWriter->writeAttribute('showVerticalScroll', '1'); |
|||
$objWriter->writeAttribute('tabRatio', '600'); |
|||
$objWriter->writeAttribute('visibility', 'visible'); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write WorkbookProtection |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel $pPHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeWorkbookProtection(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel = null) |
|||
{ |
|||
if ($pPHPExcel->getSecurity()->isSecurityEnabled()) { |
|||
$objWriter->startElement('workbookProtection'); |
|||
$objWriter->writeAttribute('lockRevision', ($pPHPExcel->getSecurity()->getLockRevision() ? 'true' : 'false')); |
|||
$objWriter->writeAttribute('lockStructure', ($pPHPExcel->getSecurity()->getLockStructure() ? 'true' : 'false')); |
|||
$objWriter->writeAttribute('lockWindows', ($pPHPExcel->getSecurity()->getLockWindows() ? 'true' : 'false')); |
|||
|
|||
if ($pPHPExcel->getSecurity()->getRevisionsPassword() != '') { |
|||
$objWriter->writeAttribute('revisionsPassword', $pPHPExcel->getSecurity()->getRevisionsPassword()); |
|||
} |
|||
|
|||
if ($pPHPExcel->getSecurity()->getWorkbookPassword() != '') { |
|||
$objWriter->writeAttribute('workbookPassword', $pPHPExcel->getSecurity()->getWorkbookPassword()); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write calcPr |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param boolean $recalcRequired Indicate whether formulas should be recalculated before writing |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeCalcPr(PHPExcel_Shared_XMLWriter $objWriter = null, $recalcRequired = true) |
|||
{ |
|||
$objWriter->startElement('calcPr'); |
|||
|
|||
// Set the calcid to a higher value than Excel itself will use, otherwise Excel will always recalc |
|||
// If MS Excel does do a recalc, then users opening a file in MS Excel will be prompted to save on exit |
|||
// because the file has changed |
|||
$objWriter->writeAttribute('calcId', '999999'); |
|||
$objWriter->writeAttribute('calcMode', 'auto'); |
|||
// fullCalcOnLoad isn't needed if we've recalculating for the save |
|||
$objWriter->writeAttribute('calcCompleted', ($recalcRequired) ? 1 : 0); |
|||
$objWriter->writeAttribute('fullCalcOnLoad', ($recalcRequired) ? 0 : 1); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write sheets |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel $pPHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeSheets(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Write sheets |
|||
$objWriter->startElement('sheets'); |
|||
$sheetCount = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
// sheet |
|||
$this->writeSheet( |
|||
$objWriter, |
|||
$pPHPExcel->getSheet($i)->getTitle(), |
|||
($i + 1), |
|||
($i + 1 + 3), |
|||
$pPHPExcel->getSheet($i)->getSheetState() |
|||
); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write sheet |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param string $pSheetname Sheet name |
|||
* @param int $pSheetId Sheet id |
|||
* @param int $pRelId Relationship ID |
|||
* @param string $sheetState Sheet state (visible, hidden, veryHidden) |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeSheet(PHPExcel_Shared_XMLWriter $objWriter = null, $pSheetname = '', $pSheetId = 1, $pRelId = 1, $sheetState = 'visible') |
|||
{ |
|||
if ($pSheetname != '') { |
|||
// Write sheet |
|||
$objWriter->startElement('sheet'); |
|||
$objWriter->writeAttribute('name', $pSheetname); |
|||
$objWriter->writeAttribute('sheetId', $pSheetId); |
|||
if ($sheetState != 'visible' && $sheetState != '') { |
|||
$objWriter->writeAttribute('state', $sheetState); |
|||
} |
|||
$objWriter->writeAttribute('r:id', 'rId' . $pRelId); |
|||
$objWriter->endElement(); |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Invalid parameters passed."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Defined Names |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel $pPHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeDefinedNames(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel = null) |
|||
{ |
|||
// Write defined names |
|||
$objWriter->startElement('definedNames'); |
|||
|
|||
// Named ranges |
|||
if (count($pPHPExcel->getNamedRanges()) > 0) { |
|||
// Named ranges |
|||
$this->writeNamedRanges($objWriter, $pPHPExcel); |
|||
} |
|||
|
|||
// Other defined names |
|||
$sheetCount = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheetCount; ++$i) { |
|||
// definedName for autoFilter |
|||
$this->writeDefinedNameForAutofilter($objWriter, $pPHPExcel->getSheet($i), $i); |
|||
|
|||
// definedName for Print_Titles |
|||
$this->writeDefinedNameForPrintTitles($objWriter, $pPHPExcel->getSheet($i), $i); |
|||
|
|||
// definedName for Print_Area |
|||
$this->writeDefinedNameForPrintArea($objWriter, $pPHPExcel->getSheet($i), $i); |
|||
} |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write named ranges |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel $pPHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeNamedRanges(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel $pPHPExcel) |
|||
{ |
|||
// Loop named ranges |
|||
$namedRanges = $pPHPExcel->getNamedRanges(); |
|||
foreach ($namedRanges as $namedRange) { |
|||
$this->writeDefinedNameForNamedRange($objWriter, $namedRange); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Defined Name for named range |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_NamedRange $pNamedRange |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeDefinedNameForNamedRange(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_NamedRange $pNamedRange) |
|||
{ |
|||
// definedName for named range |
|||
$objWriter->startElement('definedName'); |
|||
$objWriter->writeAttribute('name', $pNamedRange->getName()); |
|||
if ($pNamedRange->getLocalOnly()) { |
|||
$objWriter->writeAttribute('localSheetId', $pNamedRange->getScope()->getParent()->getIndex($pNamedRange->getScope())); |
|||
} |
|||
|
|||
// Create absolute coordinate and write as raw text |
|||
$range = PHPExcel_Cell::splitRange($pNamedRange->getRange()); |
|||
for ($i = 0; $i < count($range); $i++) { |
|||
$range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . PHPExcel_Cell::absoluteReference($range[$i][0]); |
|||
if (isset($range[$i][1])) { |
|||
$range[$i][1] = PHPExcel_Cell::absoluteReference($range[$i][1]); |
|||
} |
|||
} |
|||
$range = PHPExcel_Cell::buildRange($range); |
|||
|
|||
$objWriter->writeRawData($range); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
|
|||
/** |
|||
* Write Defined Name for autoFilter |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Worksheet $pSheet |
|||
* @param int $pSheetId |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeDefinedNameForAutofilter(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pSheetId = 0) |
|||
{ |
|||
// definedName for autoFilter |
|||
$autoFilterRange = $pSheet->getAutoFilter()->getRange(); |
|||
if (!empty($autoFilterRange)) { |
|||
$objWriter->startElement('definedName'); |
|||
$objWriter->writeAttribute('name', '_xlnm._FilterDatabase'); |
|||
$objWriter->writeAttribute('localSheetId', $pSheetId); |
|||
$objWriter->writeAttribute('hidden', '1'); |
|||
|
|||
// Create absolute coordinate and write as raw text |
|||
$range = PHPExcel_Cell::splitRange($autoFilterRange); |
|||
$range = $range[0]; |
|||
// Strip any worksheet ref so we can make the cell ref absolute |
|||
if (strpos($range[0], '!') !== false) { |
|||
list($ws, $range[0]) = explode('!', $range[0]); |
|||
} |
|||
|
|||
$range[0] = PHPExcel_Cell::absoluteCoordinate($range[0]); |
|||
$range[1] = PHPExcel_Cell::absoluteCoordinate($range[1]); |
|||
$range = implode(':', $range); |
|||
|
|||
$objWriter->writeRawData('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Defined Name for PrintTitles |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Worksheet $pSheet |
|||
* @param int $pSheetId |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeDefinedNameForPrintTitles(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pSheetId = 0) |
|||
{ |
|||
// definedName for PrintTitles |
|||
if ($pSheet->getPageSetup()->isColumnsToRepeatAtLeftSet() || $pSheet->getPageSetup()->isRowsToRepeatAtTopSet()) { |
|||
$objWriter->startElement('definedName'); |
|||
$objWriter->writeAttribute('name', '_xlnm.Print_Titles'); |
|||
$objWriter->writeAttribute('localSheetId', $pSheetId); |
|||
|
|||
// Setting string |
|||
$settingString = ''; |
|||
|
|||
// Columns to repeat |
|||
if ($pSheet->getPageSetup()->isColumnsToRepeatAtLeftSet()) { |
|||
$repeat = $pSheet->getPageSetup()->getColumnsToRepeatAtLeft(); |
|||
|
|||
$settingString .= '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!$' . $repeat[0] . ':$' . $repeat[1]; |
|||
} |
|||
|
|||
// Rows to repeat |
|||
if ($pSheet->getPageSetup()->isRowsToRepeatAtTopSet()) { |
|||
if ($pSheet->getPageSetup()->isColumnsToRepeatAtLeftSet()) { |
|||
$settingString .= ','; |
|||
} |
|||
|
|||
$repeat = $pSheet->getPageSetup()->getRowsToRepeatAtTop(); |
|||
|
|||
$settingString .= '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!$' . $repeat[0] . ':$' . $repeat[1]; |
|||
} |
|||
|
|||
$objWriter->writeRawData($settingString); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write Defined Name for PrintTitles |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter XML Writer |
|||
* @param PHPExcel_Worksheet $pSheet |
|||
* @param int $pSheetId |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeDefinedNameForPrintArea(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pSheetId = 0) |
|||
{ |
|||
// definedName for PrintArea |
|||
if ($pSheet->getPageSetup()->isPrintAreaSet()) { |
|||
$objWriter->startElement('definedName'); |
|||
$objWriter->writeAttribute('name', '_xlnm.Print_Area'); |
|||
$objWriter->writeAttribute('localSheetId', $pSheetId); |
|||
|
|||
// Setting string |
|||
$settingString = ''; |
|||
|
|||
// Print area |
|||
$printArea = PHPExcel_Cell::splitRange($pSheet->getPageSetup()->getPrintArea()); |
|||
|
|||
$chunks = array(); |
|||
foreach ($printArea as $printAreaRect) { |
|||
$printAreaRect[0] = PHPExcel_Cell::absoluteReference($printAreaRect[0]); |
|||
$printAreaRect[1] = PHPExcel_Cell::absoluteReference($printAreaRect[1]); |
|||
$chunks[] = '\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . implode(':', $printAreaRect); |
|||
} |
|||
|
|||
$objWriter->writeRawData(implode(',', $chunks)); |
|||
|
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,75 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel2007_WriterPart |
|||
* |
|||
* 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_Excel2007 |
|||
* @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## |
|||
*/ |
|||
abstract class PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
/** |
|||
* Parent IWriter object |
|||
* |
|||
* @var PHPExcel_Writer_IWriter |
|||
*/ |
|||
private $parentWriter; |
|||
|
|||
/** |
|||
* Set parent IWriter object |
|||
* |
|||
* @param PHPExcel_Writer_IWriter $pWriter |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function setParentWriter(PHPExcel_Writer_IWriter $pWriter = null) |
|||
{ |
|||
$this->parentWriter = $pWriter; |
|||
} |
|||
|
|||
/** |
|||
* Get parent IWriter object |
|||
* |
|||
* @return PHPExcel_Writer_IWriter |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function getParentWriter() |
|||
{ |
|||
if (!is_null($this->parentWriter)) { |
|||
return $this->parentWriter; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("No parent PHPExcel_Writer_IWriter assigned."); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Set parent IWriter object |
|||
* |
|||
* @param PHPExcel_Writer_IWriter $pWriter |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function __construct(PHPExcel_Writer_IWriter $pWriter = null) |
|||
{ |
|||
if (!is_null($pWriter)) { |
|||
$this->parentWriter = $pWriter; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,904 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel5 |
|||
* |
|||
* 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## |
|||
*/ |
|||
class PHPExcel_Writer_Excel5 extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* PHPExcel object |
|||
* |
|||
* @var PHPExcel |
|||
*/ |
|||
private $phpExcel; |
|||
|
|||
/** |
|||
* Total number of shared strings in workbook |
|||
* |
|||
* @var int |
|||
*/ |
|||
private $strTotal = 0; |
|||
|
|||
/** |
|||
* Number of unique shared strings in workbook |
|||
* |
|||
* @var int |
|||
*/ |
|||
private $strUnique = 0; |
|||
|
|||
/** |
|||
* Array of unique shared strings in workbook |
|||
* |
|||
* @var array |
|||
*/ |
|||
private $strTable = array(); |
|||
|
|||
/** |
|||
* Color cache. Mapping between RGB value and color index. |
|||
* |
|||
* @var array |
|||
*/ |
|||
private $colors; |
|||
|
|||
/** |
|||
* Formula parser |
|||
* |
|||
* @var PHPExcel_Writer_Excel5_Parser |
|||
*/ |
|||
private $parser; |
|||
|
|||
/** |
|||
* Identifier clusters for drawings. Used in MSODRAWINGGROUP record. |
|||
* |
|||
* @var array |
|||
*/ |
|||
private $IDCLs; |
|||
|
|||
/** |
|||
* Basic OLE object summary information |
|||
* |
|||
* @var array |
|||
*/ |
|||
private $summaryInformation; |
|||
|
|||
/** |
|||
* Extended OLE object document summary information |
|||
* |
|||
* @var array |
|||
*/ |
|||
private $documentSummaryInformation; |
|||
|
|||
/** |
|||
* Create a new PHPExcel_Writer_Excel5 |
|||
* |
|||
* @param PHPExcel $phpExcel PHPExcel object |
|||
*/ |
|||
public function __construct(PHPExcel $phpExcel) |
|||
{ |
|||
$this->phpExcel = $phpExcel; |
|||
|
|||
$this->parser = new PHPExcel_Writer_Excel5_Parser(); |
|||
} |
|||
|
|||
/** |
|||
* 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); |
|||
$saveDateReturnType = PHPExcel_Calculation_Functions::getReturnDateType(); |
|||
PHPExcel_Calculation_Functions::setReturnDateType(PHPExcel_Calculation_Functions::RETURNDATE_EXCEL); |
|||
|
|||
// initialize colors array |
|||
$this->colors = array(); |
|||
|
|||
// Initialise workbook writer |
|||
$this->writerWorkbook = new PHPExcel_Writer_Excel5_Workbook($this->phpExcel, $this->strTotal, $this->strUnique, $this->strTable, $this->colors, $this->parser); |
|||
|
|||
// Initialise worksheet writers |
|||
$countSheets = $this->phpExcel->getSheetCount(); |
|||
for ($i = 0; $i < $countSheets; ++$i) { |
|||
$this->writerWorksheets[$i] = new PHPExcel_Writer_Excel5_Worksheet($this->strTotal, $this->strUnique, $this->strTable, $this->colors, $this->parser, $this->preCalculateFormulas, $this->phpExcel->getSheet($i)); |
|||
} |
|||
|
|||
// build Escher objects. Escher objects for workbooks needs to be build before Escher object for workbook. |
|||
$this->buildWorksheetEschers(); |
|||
$this->buildWorkbookEscher(); |
|||
|
|||
// add 15 identical cell style Xfs |
|||
// for now, we use the first cellXf instead of cellStyleXf |
|||
$cellXfCollection = $this->phpExcel->getCellXfCollection(); |
|||
for ($i = 0; $i < 15; ++$i) { |
|||
$this->writerWorkbook->addXfWriter($cellXfCollection[0], true); |
|||
} |
|||
|
|||
// add all the cell Xfs |
|||
foreach ($this->phpExcel->getCellXfCollection() as $style) { |
|||
$this->writerWorkbook->addXfWriter($style, false); |
|||
} |
|||
|
|||
// add fonts from rich text eleemnts |
|||
for ($i = 0; $i < $countSheets; ++$i) { |
|||
foreach ($this->writerWorksheets[$i]->phpSheet->getCellCollection() as $cellID) { |
|||
$cell = $this->writerWorksheets[$i]->phpSheet->getCell($cellID); |
|||
$cVal = $cell->getValue(); |
|||
if ($cVal instanceof PHPExcel_RichText) { |
|||
$elements = $cVal->getRichTextElements(); |
|||
foreach ($elements as $element) { |
|||
if ($element instanceof PHPExcel_RichText_Run) { |
|||
$font = $element->getFont(); |
|||
$this->writerWorksheets[$i]->fontHashIndex[$font->getHashCode()] = $this->writerWorkbook->addFont($font); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
// initialize OLE file |
|||
$workbookStreamName = 'Workbook'; |
|||
$OLE = new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs($workbookStreamName)); |
|||
|
|||
// Write the worksheet streams before the global workbook stream, |
|||
// because the byte sizes of these are needed in the global workbook stream |
|||
$worksheetSizes = array(); |
|||
for ($i = 0; $i < $countSheets; ++$i) { |
|||
$this->writerWorksheets[$i]->close(); |
|||
$worksheetSizes[] = $this->writerWorksheets[$i]->_datasize; |
|||
} |
|||
|
|||
// add binary data for global workbook stream |
|||
$OLE->append($this->writerWorkbook->writeWorkbook($worksheetSizes)); |
|||
|
|||
// add binary data for sheet streams |
|||
for ($i = 0; $i < $countSheets; ++$i) { |
|||
$OLE->append($this->writerWorksheets[$i]->getData()); |
|||
} |
|||
|
|||
$this->documentSummaryInformation = $this->writeDocumentSummaryInformation(); |
|||
// initialize OLE Document Summary Information |
|||
if (isset($this->documentSummaryInformation) && !empty($this->documentSummaryInformation)) { |
|||
$OLE_DocumentSummaryInformation = new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs(chr(5) . 'DocumentSummaryInformation')); |
|||
$OLE_DocumentSummaryInformation->append($this->documentSummaryInformation); |
|||
} |
|||
|
|||
$this->summaryInformation = $this->writeSummaryInformation(); |
|||
// initialize OLE Summary Information |
|||
if (isset($this->summaryInformation) && !empty($this->summaryInformation)) { |
|||
$OLE_SummaryInformation = new PHPExcel_Shared_OLE_PPS_File(PHPExcel_Shared_OLE::Asc2Ucs(chr(5) . 'SummaryInformation')); |
|||
$OLE_SummaryInformation->append($this->summaryInformation); |
|||
} |
|||
|
|||
// define OLE Parts |
|||
$arrRootData = array($OLE); |
|||
// initialize OLE Properties file |
|||
if (isset($OLE_SummaryInformation)) { |
|||
$arrRootData[] = $OLE_SummaryInformation; |
|||
} |
|||
// initialize OLE Extended Properties file |
|||
if (isset($OLE_DocumentSummaryInformation)) { |
|||
$arrRootData[] = $OLE_DocumentSummaryInformation; |
|||
} |
|||
|
|||
$root = new PHPExcel_Shared_OLE_PPS_Root(time(), time(), $arrRootData); |
|||
// save the OLE file |
|||
$res = $root->save($pFilename); |
|||
|
|||
PHPExcel_Calculation_Functions::setReturnDateType($saveDateReturnType); |
|||
PHPExcel_Calculation::getInstance($this->phpExcel)->getDebugLog()->setWriteDebugLog($saveDebugLog); |
|||
} |
|||
|
|||
/** |
|||
* Set temporary storage directory |
|||
* |
|||
* @deprecated |
|||
* @param string $pValue Temporary storage directory |
|||
* @throws PHPExcel_Writer_Exception when directory does not exist |
|||
* @return PHPExcel_Writer_Excel5 |
|||
*/ |
|||
public function setTempDir($pValue = '') |
|||
{ |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Build the Worksheet Escher objects |
|||
* |
|||
*/ |
|||
private function buildWorksheetEschers() |
|||
{ |
|||
// 1-based index to BstoreContainer |
|||
$blipIndex = 0; |
|||
$lastReducedSpId = 0; |
|||
$lastSpId = 0; |
|||
|
|||
foreach ($this->phpExcel->getAllsheets() as $sheet) { |
|||
// sheet index |
|||
$sheetIndex = $sheet->getParent()->getIndex($sheet); |
|||
|
|||
$escher = null; |
|||
|
|||
// check if there are any shapes for this sheet |
|||
$filterRange = $sheet->getAutoFilter()->getRange(); |
|||
if (count($sheet->getDrawingCollection()) == 0 && empty($filterRange)) { |
|||
continue; |
|||
} |
|||
|
|||
// create intermediate Escher object |
|||
$escher = new PHPExcel_Shared_Escher(); |
|||
|
|||
// dgContainer |
|||
$dgContainer = new PHPExcel_Shared_Escher_DgContainer(); |
|||
|
|||
// set the drawing index (we use sheet index + 1) |
|||
$dgId = $sheet->getParent()->getIndex($sheet) + 1; |
|||
$dgContainer->setDgId($dgId); |
|||
$escher->setDgContainer($dgContainer); |
|||
|
|||
// spgrContainer |
|||
$spgrContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer(); |
|||
$dgContainer->setSpgrContainer($spgrContainer); |
|||
|
|||
// add one shape which is the group shape |
|||
$spContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer(); |
|||
$spContainer->setSpgr(true); |
|||
$spContainer->setSpType(0); |
|||
$spContainer->setSpId(($sheet->getParent()->getIndex($sheet) + 1) << 10); |
|||
$spgrContainer->addChild($spContainer); |
|||
|
|||
// add the shapes |
|||
|
|||
$countShapes[$sheetIndex] = 0; // count number of shapes (minus group shape), in sheet |
|||
|
|||
foreach ($sheet->getDrawingCollection() as $drawing) { |
|||
++$blipIndex; |
|||
|
|||
++$countShapes[$sheetIndex]; |
|||
|
|||
// add the shape |
|||
$spContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer(); |
|||
|
|||
// set the shape type |
|||
$spContainer->setSpType(0x004B); |
|||
// set the shape flag |
|||
$spContainer->setSpFlag(0x02); |
|||
|
|||
// set the shape index (we combine 1-based sheet index and $countShapes to create unique shape index) |
|||
$reducedSpId = $countShapes[$sheetIndex]; |
|||
$spId = $reducedSpId |
|||
| ($sheet->getParent()->getIndex($sheet) + 1) << 10; |
|||
$spContainer->setSpId($spId); |
|||
|
|||
// keep track of last reducedSpId |
|||
$lastReducedSpId = $reducedSpId; |
|||
|
|||
// keep track of last spId |
|||
$lastSpId = $spId; |
|||
|
|||
// set the BLIP index |
|||
$spContainer->setOPT(0x4104, $blipIndex); |
|||
|
|||
// set coordinates and offsets, client anchor |
|||
$coordinates = $drawing->getCoordinates(); |
|||
$offsetX = $drawing->getOffsetX(); |
|||
$offsetY = $drawing->getOffsetY(); |
|||
$width = $drawing->getWidth(); |
|||
$height = $drawing->getHeight(); |
|||
|
|||
$twoAnchor = PHPExcel_Shared_Excel5::oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height); |
|||
|
|||
$spContainer->setStartCoordinates($twoAnchor['startCoordinates']); |
|||
$spContainer->setStartOffsetX($twoAnchor['startOffsetX']); |
|||
$spContainer->setStartOffsetY($twoAnchor['startOffsetY']); |
|||
$spContainer->setEndCoordinates($twoAnchor['endCoordinates']); |
|||
$spContainer->setEndOffsetX($twoAnchor['endOffsetX']); |
|||
$spContainer->setEndOffsetY($twoAnchor['endOffsetY']); |
|||
|
|||
$spgrContainer->addChild($spContainer); |
|||
} |
|||
|
|||
// AutoFilters |
|||
if (!empty($filterRange)) { |
|||
$rangeBounds = PHPExcel_Cell::rangeBoundaries($filterRange); |
|||
$iNumColStart = $rangeBounds[0][0]; |
|||
$iNumColEnd = $rangeBounds[1][0]; |
|||
|
|||
$iInc = $iNumColStart; |
|||
while ($iInc <= $iNumColEnd) { |
|||
++$countShapes[$sheetIndex]; |
|||
|
|||
// create an Drawing Object for the dropdown |
|||
$oDrawing = new PHPExcel_Worksheet_BaseDrawing(); |
|||
// get the coordinates of drawing |
|||
$cDrawing = PHPExcel_Cell::stringFromColumnIndex($iInc - 1) . $rangeBounds[0][1]; |
|||
$oDrawing->setCoordinates($cDrawing); |
|||
$oDrawing->setWorksheet($sheet); |
|||
|
|||
// add the shape |
|||
$spContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer(); |
|||
// set the shape type |
|||
$spContainer->setSpType(0x00C9); |
|||
// set the shape flag |
|||
$spContainer->setSpFlag(0x01); |
|||
|
|||
// set the shape index (we combine 1-based sheet index and $countShapes to create unique shape index) |
|||
$reducedSpId = $countShapes[$sheetIndex]; |
|||
$spId = $reducedSpId |
|||
| ($sheet->getParent()->getIndex($sheet) + 1) << 10; |
|||
$spContainer->setSpId($spId); |
|||
|
|||
// keep track of last reducedSpId |
|||
$lastReducedSpId = $reducedSpId; |
|||
|
|||
// keep track of last spId |
|||
$lastSpId = $spId; |
|||
|
|||
$spContainer->setOPT(0x007F, 0x01040104); // Protection -> fLockAgainstGrouping |
|||
$spContainer->setOPT(0x00BF, 0x00080008); // Text -> fFitTextToShape |
|||
$spContainer->setOPT(0x01BF, 0x00010000); // Fill Style -> fNoFillHitTest |
|||
$spContainer->setOPT(0x01FF, 0x00080000); // Line Style -> fNoLineDrawDash |
|||
$spContainer->setOPT(0x03BF, 0x000A0000); // Group Shape -> fPrint |
|||
|
|||
// set coordinates and offsets, client anchor |
|||
$endCoordinates = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::stringFromColumnIndex($iInc - 1)); |
|||
$endCoordinates .= $rangeBounds[0][1] + 1; |
|||
|
|||
$spContainer->setStartCoordinates($cDrawing); |
|||
$spContainer->setStartOffsetX(0); |
|||
$spContainer->setStartOffsetY(0); |
|||
$spContainer->setEndCoordinates($endCoordinates); |
|||
$spContainer->setEndOffsetX(0); |
|||
$spContainer->setEndOffsetY(0); |
|||
|
|||
$spgrContainer->addChild($spContainer); |
|||
$iInc++; |
|||
} |
|||
} |
|||
|
|||
// identifier clusters, used for workbook Escher object |
|||
$this->IDCLs[$dgId] = $lastReducedSpId; |
|||
|
|||
// set last shape index |
|||
$dgContainer->setLastSpId($lastSpId); |
|||
|
|||
// set the Escher object |
|||
$this->writerWorksheets[$sheetIndex]->setEscher($escher); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Build the Escher object corresponding to the MSODRAWINGGROUP record |
|||
*/ |
|||
private function buildWorkbookEscher() |
|||
{ |
|||
$escher = null; |
|||
|
|||
// any drawings in this workbook? |
|||
$found = false; |
|||
foreach ($this->phpExcel->getAllSheets() as $sheet) { |
|||
if (count($sheet->getDrawingCollection()) > 0) { |
|||
$found = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// nothing to do if there are no drawings |
|||
if (!$found) { |
|||
return; |
|||
} |
|||
|
|||
// if we reach here, then there are drawings in the workbook |
|||
$escher = new PHPExcel_Shared_Escher(); |
|||
|
|||
// dggContainer |
|||
$dggContainer = new PHPExcel_Shared_Escher_DggContainer(); |
|||
$escher->setDggContainer($dggContainer); |
|||
|
|||
// set IDCLs (identifier clusters) |
|||
$dggContainer->setIDCLs($this->IDCLs); |
|||
|
|||
// this loop is for determining maximum shape identifier of all drawing |
|||
$spIdMax = 0; |
|||
$totalCountShapes = 0; |
|||
$countDrawings = 0; |
|||
|
|||
foreach ($this->phpExcel->getAllsheets() as $sheet) { |
|||
$sheetCountShapes = 0; // count number of shapes (minus group shape), in sheet |
|||
|
|||
if (count($sheet->getDrawingCollection()) > 0) { |
|||
++$countDrawings; |
|||
|
|||
foreach ($sheet->getDrawingCollection() as $drawing) { |
|||
++$sheetCountShapes; |
|||
++$totalCountShapes; |
|||
|
|||
$spId = $sheetCountShapes | ($this->phpExcel->getIndex($sheet) + 1) << 10; |
|||
$spIdMax = max($spId, $spIdMax); |
|||
} |
|||
} |
|||
} |
|||
|
|||
$dggContainer->setSpIdMax($spIdMax + 1); |
|||
$dggContainer->setCDgSaved($countDrawings); |
|||
$dggContainer->setCSpSaved($totalCountShapes + $countDrawings); // total number of shapes incl. one group shapes per drawing |
|||
|
|||
// bstoreContainer |
|||
$bstoreContainer = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer(); |
|||
$dggContainer->setBstoreContainer($bstoreContainer); |
|||
|
|||
// the BSE's (all the images) |
|||
foreach ($this->phpExcel->getAllsheets() as $sheet) { |
|||
foreach ($sheet->getDrawingCollection() as $drawing) { |
|||
if ($drawing instanceof PHPExcel_Worksheet_Drawing) { |
|||
$filename = $drawing->getPath(); |
|||
|
|||
list($imagesx, $imagesy, $imageFormat) = getimagesize($filename); |
|||
|
|||
switch ($imageFormat) { |
|||
case 1: // GIF, not supported by BIFF8, we convert to PNG |
|||
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG; |
|||
ob_start(); |
|||
imagepng(imagecreatefromgif($filename)); |
|||
$blipData = ob_get_contents(); |
|||
ob_end_clean(); |
|||
break; |
|||
case 2: // JPEG |
|||
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG; |
|||
$blipData = file_get_contents($filename); |
|||
break; |
|||
case 3: // PNG |
|||
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG; |
|||
$blipData = file_get_contents($filename); |
|||
break; |
|||
case 6: // Windows DIB (BMP), we convert to PNG |
|||
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG; |
|||
ob_start(); |
|||
imagepng(PHPExcel_Shared_Drawing::imagecreatefrombmp($filename)); |
|||
$blipData = ob_get_contents(); |
|||
ob_end_clean(); |
|||
break; |
|||
default: |
|||
continue 2; |
|||
} |
|||
|
|||
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip(); |
|||
$blip->setData($blipData); |
|||
|
|||
$BSE = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE(); |
|||
$BSE->setBlipType($blipType); |
|||
$BSE->setBlip($blip); |
|||
|
|||
$bstoreContainer->addBSE($BSE); |
|||
} elseif ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) { |
|||
switch ($drawing->getRenderingFunction()) { |
|||
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG: |
|||
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG; |
|||
$renderingFunction = 'imagejpeg'; |
|||
break; |
|||
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_GIF: |
|||
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG: |
|||
case PHPExcel_Worksheet_MemoryDrawing::RENDERING_DEFAULT: |
|||
$blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG; |
|||
$renderingFunction = 'imagepng'; |
|||
break; |
|||
} |
|||
|
|||
ob_start(); |
|||
call_user_func($renderingFunction, $drawing->getImageResource()); |
|||
$blipData = ob_get_contents(); |
|||
ob_end_clean(); |
|||
|
|||
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip(); |
|||
$blip->setData($blipData); |
|||
|
|||
$BSE = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE(); |
|||
$BSE->setBlipType($blipType); |
|||
$BSE->setBlip($blip); |
|||
|
|||
$bstoreContainer->addBSE($BSE); |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Set the Escher object |
|||
$this->writerWorkbook->setEscher($escher); |
|||
} |
|||
|
|||
/** |
|||
* Build the OLE Part for DocumentSummary Information |
|||
* @return string |
|||
*/ |
|||
private function writeDocumentSummaryInformation() |
|||
{ |
|||
// offset: 0; size: 2; must be 0xFE 0xFF (UTF-16 LE byte order mark) |
|||
$data = pack('v', 0xFFFE); |
|||
// offset: 2; size: 2; |
|||
$data .= pack('v', 0x0000); |
|||
// offset: 4; size: 2; OS version |
|||
$data .= pack('v', 0x0106); |
|||
// offset: 6; size: 2; OS indicator |
|||
$data .= pack('v', 0x0002); |
|||
// offset: 8; size: 16 |
|||
$data .= pack('VVVV', 0x00, 0x00, 0x00, 0x00); |
|||
// offset: 24; size: 4; section count |
|||
$data .= pack('V', 0x0001); |
|||
|
|||
// offset: 28; size: 16; first section's class id: 02 d5 cd d5 9c 2e 1b 10 93 97 08 00 2b 2c f9 ae |
|||
$data .= pack('vvvvvvvv', 0xD502, 0xD5CD, 0x2E9C, 0x101B, 0x9793, 0x0008, 0x2C2B, 0xAEF9); |
|||
// offset: 44; size: 4; offset of the start |
|||
$data .= pack('V', 0x30); |
|||
|
|||
// SECTION |
|||
$dataSection = array(); |
|||
$dataSection_NumProps = 0; |
|||
$dataSection_Summary = ''; |
|||
$dataSection_Content = ''; |
|||
|
|||
// GKPIDDSI_CODEPAGE: CodePage |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x01), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x02), // 2 byte signed integer |
|||
'data' => array('data' => 1252)); |
|||
$dataSection_NumProps++; |
|||
|
|||
// GKPIDDSI_CATEGORY : Category |
|||
if ($this->phpExcel->getProperties()->getCategory()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getCategory(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x02), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x1E), |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// GKPIDDSI_VERSION :Version of the application that wrote the property storage |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x17), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x03), |
|||
'data' => array('pack' => 'V', 'data' => 0x000C0000)); |
|||
$dataSection_NumProps++; |
|||
// GKPIDDSI_SCALE : FALSE |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x0B), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x0B), |
|||
'data' => array('data' => false)); |
|||
$dataSection_NumProps++; |
|||
// GKPIDDSI_LINKSDIRTY : True if any of the values for the linked properties have changed outside of the application |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x10), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x0B), |
|||
'data' => array('data' => false)); |
|||
$dataSection_NumProps++; |
|||
// GKPIDDSI_SHAREDOC : FALSE |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x13), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x0B), |
|||
'data' => array('data' => false)); |
|||
$dataSection_NumProps++; |
|||
// GKPIDDSI_HYPERLINKSCHANGED : True if any of the values for the _PID_LINKS (hyperlink text) have changed outside of the application |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x16), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x0B), |
|||
'data' => array('data' => false)); |
|||
$dataSection_NumProps++; |
|||
|
|||
// GKPIDDSI_DOCSPARTS |
|||
// MS-OSHARED p75 (2.3.3.2.2.1) |
|||
// Structure is VtVecUnalignedLpstrValue (2.3.3.1.9) |
|||
// cElements |
|||
$dataProp = pack('v', 0x0001); |
|||
$dataProp .= pack('v', 0x0000); |
|||
// array of UnalignedLpstr |
|||
// cch |
|||
$dataProp .= pack('v', 0x000A); |
|||
$dataProp .= pack('v', 0x0000); |
|||
// value |
|||
$dataProp .= 'Worksheet'.chr(0); |
|||
|
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x0D), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x101E), |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
|
|||
// GKPIDDSI_HEADINGPAIR |
|||
// VtVecHeadingPairValue |
|||
// cElements |
|||
$dataProp = pack('v', 0x0002); |
|||
$dataProp .= pack('v', 0x0000); |
|||
// Array of vtHeadingPair |
|||
// vtUnalignedString - headingString |
|||
// stringType |
|||
$dataProp .= pack('v', 0x001E); |
|||
// padding |
|||
$dataProp .= pack('v', 0x0000); |
|||
// UnalignedLpstr |
|||
// cch |
|||
$dataProp .= pack('v', 0x0013); |
|||
$dataProp .= pack('v', 0x0000); |
|||
// value |
|||
$dataProp .= 'Feuilles de calcul'; |
|||
// vtUnalignedString - headingParts |
|||
// wType : 0x0003 = 32 bit signed integer |
|||
$dataProp .= pack('v', 0x0300); |
|||
// padding |
|||
$dataProp .= pack('v', 0x0000); |
|||
// value |
|||
$dataProp .= pack('v', 0x0100); |
|||
$dataProp .= pack('v', 0x0000); |
|||
$dataProp .= pack('v', 0x0000); |
|||
$dataProp .= pack('v', 0x0000); |
|||
|
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x0C), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x100C), |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
|
|||
// 4 Section Length |
|||
// 4 Property count |
|||
// 8 * $dataSection_NumProps (8 = ID (4) + OffSet(4)) |
|||
$dataSection_Content_Offset = 8 + $dataSection_NumProps * 8; |
|||
foreach ($dataSection as $dataProp) { |
|||
// Summary |
|||
$dataSection_Summary .= pack($dataProp['summary']['pack'], $dataProp['summary']['data']); |
|||
// Offset |
|||
$dataSection_Summary .= pack($dataProp['offset']['pack'], $dataSection_Content_Offset); |
|||
// DataType |
|||
$dataSection_Content .= pack($dataProp['type']['pack'], $dataProp['type']['data']); |
|||
// Data |
|||
if ($dataProp['type']['data'] == 0x02) { // 2 byte signed integer |
|||
$dataSection_Content .= pack('V', $dataProp['data']['data']); |
|||
|
|||
$dataSection_Content_Offset += 4 + 4; |
|||
} elseif ($dataProp['type']['data'] == 0x03) { // 4 byte signed integer |
|||
$dataSection_Content .= pack('V', $dataProp['data']['data']); |
|||
|
|||
$dataSection_Content_Offset += 4 + 4; |
|||
} elseif ($dataProp['type']['data'] == 0x0B) { // Boolean |
|||
if ($dataProp['data']['data'] == false) { |
|||
$dataSection_Content .= pack('V', 0x0000); |
|||
} else { |
|||
$dataSection_Content .= pack('V', 0x0001); |
|||
} |
|||
$dataSection_Content_Offset += 4 + 4; |
|||
} elseif ($dataProp['type']['data'] == 0x1E) { // null-terminated string prepended by dword string length |
|||
// Null-terminated string |
|||
$dataProp['data']['data'] .= chr(0); |
|||
$dataProp['data']['length'] += 1; |
|||
// Complete the string with null string for being a %4 |
|||
$dataProp['data']['length'] = $dataProp['data']['length'] + ((4 - $dataProp['data']['length'] % 4)==4 ? 0 : (4 - $dataProp['data']['length'] % 4)); |
|||
$dataProp['data']['data'] = str_pad($dataProp['data']['data'], $dataProp['data']['length'], chr(0), STR_PAD_RIGHT); |
|||
|
|||
$dataSection_Content .= pack('V', $dataProp['data']['length']); |
|||
$dataSection_Content .= $dataProp['data']['data']; |
|||
|
|||
$dataSection_Content_Offset += 4 + 4 + strlen($dataProp['data']['data']); |
|||
} elseif ($dataProp['type']['data'] == 0x40) { // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601) |
|||
$dataSection_Content .= $dataProp['data']['data']; |
|||
|
|||
$dataSection_Content_Offset += 4 + 8; |
|||
} else { |
|||
// Data Type Not Used at the moment |
|||
$dataSection_Content .= $dataProp['data']['data']; |
|||
|
|||
$dataSection_Content_Offset += 4 + $dataProp['data']['length']; |
|||
} |
|||
} |
|||
// Now $dataSection_Content_Offset contains the size of the content |
|||
|
|||
// section header |
|||
// offset: $secOffset; size: 4; section length |
|||
// + x Size of the content (summary + content) |
|||
$data .= pack('V', $dataSection_Content_Offset); |
|||
// offset: $secOffset+4; size: 4; property count |
|||
$data .= pack('V', $dataSection_NumProps); |
|||
// Section Summary |
|||
$data .= $dataSection_Summary; |
|||
// Section Content |
|||
$data .= $dataSection_Content; |
|||
|
|||
return $data; |
|||
} |
|||
|
|||
/** |
|||
* Build the OLE Part for Summary Information |
|||
* @return string |
|||
*/ |
|||
private function writeSummaryInformation() |
|||
{ |
|||
// offset: 0; size: 2; must be 0xFE 0xFF (UTF-16 LE byte order mark) |
|||
$data = pack('v', 0xFFFE); |
|||
// offset: 2; size: 2; |
|||
$data .= pack('v', 0x0000); |
|||
// offset: 4; size: 2; OS version |
|||
$data .= pack('v', 0x0106); |
|||
// offset: 6; size: 2; OS indicator |
|||
$data .= pack('v', 0x0002); |
|||
// offset: 8; size: 16 |
|||
$data .= pack('VVVV', 0x00, 0x00, 0x00, 0x00); |
|||
// offset: 24; size: 4; section count |
|||
$data .= pack('V', 0x0001); |
|||
|
|||
// offset: 28; size: 16; first section's class id: e0 85 9f f2 f9 4f 68 10 ab 91 08 00 2b 27 b3 d9 |
|||
$data .= pack('vvvvvvvv', 0x85E0, 0xF29F, 0x4FF9, 0x1068, 0x91AB, 0x0008, 0x272B, 0xD9B3); |
|||
// offset: 44; size: 4; offset of the start |
|||
$data .= pack('V', 0x30); |
|||
|
|||
// SECTION |
|||
$dataSection = array(); |
|||
$dataSection_NumProps = 0; |
|||
$dataSection_Summary = ''; |
|||
$dataSection_Content = ''; |
|||
|
|||
// CodePage : CP-1252 |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x01), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x02), // 2 byte signed integer |
|||
'data' => array('data' => 1252)); |
|||
$dataSection_NumProps++; |
|||
|
|||
// Title |
|||
if ($this->phpExcel->getProperties()->getTitle()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getTitle(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x02), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x1E), // null-terminated string prepended by dword string length |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// Subject |
|||
if ($this->phpExcel->getProperties()->getSubject()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getSubject(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x03), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x1E), // null-terminated string prepended by dword string length |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// Author (Creator) |
|||
if ($this->phpExcel->getProperties()->getCreator()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getCreator(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x04), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x1E), // null-terminated string prepended by dword string length |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// Keywords |
|||
if ($this->phpExcel->getProperties()->getKeywords()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getKeywords(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x05), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x1E), // null-terminated string prepended by dword string length |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// Comments (Description) |
|||
if ($this->phpExcel->getProperties()->getDescription()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getDescription(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x06), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x1E), // null-terminated string prepended by dword string length |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// Last Saved By (LastModifiedBy) |
|||
if ($this->phpExcel->getProperties()->getLastModifiedBy()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getLastModifiedBy(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x08), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x1E), // null-terminated string prepended by dword string length |
|||
'data' => array('data' => $dataProp, 'length' => strlen($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// Created Date/Time |
|||
if ($this->phpExcel->getProperties()->getCreated()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getCreated(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x0C), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x40), // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601) |
|||
'data' => array('data' => PHPExcel_Shared_OLE::LocalDate2OLE($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// Modified Date/Time |
|||
if ($this->phpExcel->getProperties()->getModified()) { |
|||
$dataProp = $this->phpExcel->getProperties()->getModified(); |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x0D), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x40), // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601) |
|||
'data' => array('data' => PHPExcel_Shared_OLE::LocalDate2OLE($dataProp))); |
|||
$dataSection_NumProps++; |
|||
} |
|||
// Security |
|||
$dataSection[] = array('summary'=> array('pack' => 'V', 'data' => 0x13), |
|||
'offset' => array('pack' => 'V'), |
|||
'type' => array('pack' => 'V', 'data' => 0x03), // 4 byte signed integer |
|||
'data' => array('data' => 0x00)); |
|||
$dataSection_NumProps++; |
|||
|
|||
|
|||
// 4 Section Length |
|||
// 4 Property count |
|||
// 8 * $dataSection_NumProps (8 = ID (4) + OffSet(4)) |
|||
$dataSection_Content_Offset = 8 + $dataSection_NumProps * 8; |
|||
foreach ($dataSection as $dataProp) { |
|||
// Summary |
|||
$dataSection_Summary .= pack($dataProp['summary']['pack'], $dataProp['summary']['data']); |
|||
// Offset |
|||
$dataSection_Summary .= pack($dataProp['offset']['pack'], $dataSection_Content_Offset); |
|||
// DataType |
|||
$dataSection_Content .= pack($dataProp['type']['pack'], $dataProp['type']['data']); |
|||
// Data |
|||
if ($dataProp['type']['data'] == 0x02) { // 2 byte signed integer |
|||
$dataSection_Content .= pack('V', $dataProp['data']['data']); |
|||
|
|||
$dataSection_Content_Offset += 4 + 4; |
|||
} elseif ($dataProp['type']['data'] == 0x03) { // 4 byte signed integer |
|||
$dataSection_Content .= pack('V', $dataProp['data']['data']); |
|||
|
|||
$dataSection_Content_Offset += 4 + 4; |
|||
} elseif ($dataProp['type']['data'] == 0x1E) { // null-terminated string prepended by dword string length |
|||
// Null-terminated string |
|||
$dataProp['data']['data'] .= chr(0); |
|||
$dataProp['data']['length'] += 1; |
|||
// Complete the string with null string for being a %4 |
|||
$dataProp['data']['length'] = $dataProp['data']['length'] + ((4 - $dataProp['data']['length'] % 4)==4 ? 0 : (4 - $dataProp['data']['length'] % 4)); |
|||
$dataProp['data']['data'] = str_pad($dataProp['data']['data'], $dataProp['data']['length'], chr(0), STR_PAD_RIGHT); |
|||
|
|||
$dataSection_Content .= pack('V', $dataProp['data']['length']); |
|||
$dataSection_Content .= $dataProp['data']['data']; |
|||
|
|||
$dataSection_Content_Offset += 4 + 4 + strlen($dataProp['data']['data']); |
|||
} elseif ($dataProp['type']['data'] == 0x40) { // Filetime (64-bit value representing the number of 100-nanosecond intervals since January 1, 1601) |
|||
$dataSection_Content .= $dataProp['data']['data']; |
|||
|
|||
$dataSection_Content_Offset += 4 + 8; |
|||
} else { |
|||
// Data Type Not Used at the moment |
|||
} |
|||
} |
|||
// Now $dataSection_Content_Offset contains the size of the content |
|||
|
|||
// section header |
|||
// offset: $secOffset; size: 4; section length |
|||
// + x Size of the content (summary + content) |
|||
$data .= pack('V', $dataSection_Content_Offset); |
|||
// offset: $secOffset+4; size: 4; property count |
|||
$data .= pack('V', $dataSection_NumProps); |
|||
// Section Summary |
|||
$data .= $dataSection_Summary; |
|||
// Section Content |
|||
$data .= $dataSection_Content; |
|||
|
|||
return $data; |
|||
} |
|||
} |
|||
@ -0,0 +1,246 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel5_BIFFwriter |
|||
* |
|||
* 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_BIFFwriter (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_BIFFwriter |
|||
{ |
|||
/** |
|||
* The byte order of this architecture. 0 => little endian, 1 => big endian |
|||
* @var integer |
|||
*/ |
|||
private static $byteOrder; |
|||
|
|||
/** |
|||
* The string containing the data of the BIFF stream |
|||
* @var string |
|||
*/ |
|||
public $_data; |
|||
|
|||
/** |
|||
* The size of the data in bytes. Should be the same as strlen($this->_data) |
|||
* @var integer |
|||
*/ |
|||
public $_datasize; |
|||
|
|||
/** |
|||
* The maximum length for a BIFF record (excluding record header and length field). See addContinue() |
|||
* @var integer |
|||
* @see addContinue() |
|||
*/ |
|||
private $limit = 8224; |
|||
|
|||
/** |
|||
* Constructor |
|||
*/ |
|||
public function __construct() |
|||
{ |
|||
$this->_data = ''; |
|||
$this->_datasize = 0; |
|||
// $this->limit = 8224; |
|||
} |
|||
|
|||
/** |
|||
* Determine the byte order and store it as class data to avoid |
|||
* recalculating it for each call to new(). |
|||
* |
|||
* @return int |
|||
*/ |
|||
public static function getByteOrder() |
|||
{ |
|||
if (!isset(self::$byteOrder)) { |
|||
// Check if "pack" gives the required IEEE 64bit float |
|||
$teststr = pack("d", 1.2345); |
|||
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F); |
|||
if ($number == $teststr) { |
|||
$byte_order = 0; // Little Endian |
|||
} elseif ($number == strrev($teststr)) { |
|||
$byte_order = 1; // Big Endian |
|||
} else { |
|||
// Give up. I'll fix this in a later version. |
|||
throw new PHPExcel_Writer_Exception("Required floating point format not supported on this platform."); |
|||
} |
|||
self::$byteOrder = $byte_order; |
|||
} |
|||
|
|||
return self::$byteOrder; |
|||
} |
|||
|
|||
/** |
|||
* General storage function |
|||
* |
|||
* @param string $data binary data to append |
|||
* @access private |
|||
*/ |
|||
protected function append($data) |
|||
{ |
|||
if (strlen($data) - 4 > $this->limit) { |
|||
$data = $this->addContinue($data); |
|||
} |
|||
$this->_data .= $data; |
|||
$this->_datasize += strlen($data); |
|||
} |
|||
|
|||
/** |
|||
* General storage function like append, but returns string instead of modifying $this->_data |
|||
* |
|||
* @param string $data binary data to write |
|||
* @return string |
|||
*/ |
|||
public function writeData($data) |
|||
{ |
|||
if (strlen($data) - 4 > $this->limit) { |
|||
$data = $this->addContinue($data); |
|||
} |
|||
$this->_datasize += strlen($data); |
|||
|
|||
return $data; |
|||
} |
|||
|
|||
/** |
|||
* Writes Excel BOF record to indicate the beginning of a stream or |
|||
* sub-stream in the BIFF file. |
|||
* |
|||
* @param integer $type Type of BIFF file to write: 0x0005 Workbook, |
|||
* 0x0010 Worksheet. |
|||
* @access private |
|||
*/ |
|||
protected function storeBof($type) |
|||
{ |
|||
$record = 0x0809; // Record identifier (BIFF5-BIFF8) |
|||
$length = 0x0010; |
|||
|
|||
// by inspection of real files, MS Office Excel 2007 writes the following |
|||
$unknown = pack("VV", 0x000100D1, 0x00000406); |
|||
|
|||
$build = 0x0DBB; // Excel 97 |
|||
$year = 0x07CC; // Excel 97 |
|||
|
|||
$version = 0x0600; // BIFF8 |
|||
|
|||
$header = pack("vv", $record, $length); |
|||
$data = pack("vvvv", $version, $type, $build, $year); |
|||
$this->append($header . $data . $unknown); |
|||
} |
|||
|
|||
/** |
|||
* Writes Excel EOF record to indicate the end of a BIFF stream. |
|||
* |
|||
* @access private |
|||
*/ |
|||
protected function storeEof() |
|||
{ |
|||
$record = 0x000A; // Record identifier |
|||
$length = 0x0000; // Number of bytes to follow |
|||
|
|||
$header = pack("vv", $record, $length); |
|||
$this->append($header); |
|||
} |
|||
|
|||
/** |
|||
* Writes Excel EOF record to indicate the end of a BIFF stream. |
|||
* |
|||
* @access private |
|||
*/ |
|||
public function writeEof() |
|||
{ |
|||
$record = 0x000A; // Record identifier |
|||
$length = 0x0000; // Number of bytes to follow |
|||
$header = pack("vv", $record, $length); |
|||
return $this->writeData($header); |
|||
} |
|||
|
|||
/** |
|||
* Excel limits the size of BIFF records. In Excel 5 the limit is 2084 bytes. In |
|||
* Excel 97 the limit is 8228 bytes. Records that are longer than these limits |
|||
* must be split up into CONTINUE blocks. |
|||
* |
|||
* This function takes a long BIFF record and inserts CONTINUE records as |
|||
* necessary. |
|||
* |
|||
* @param string $data The original binary data to be written |
|||
* @return string A very convenient string of continue blocks |
|||
* @access private |
|||
*/ |
|||
private function addContinue($data) |
|||
{ |
|||
$limit = $this->limit; |
|||
$record = 0x003C; // Record identifier |
|||
|
|||
// The first 2080/8224 bytes remain intact. However, we have to change |
|||
// the length field of the record. |
|||
$tmp = substr($data, 0, 2) . pack("v", $limit) . substr($data, 4, $limit); |
|||
|
|||
$header = pack("vv", $record, $limit); // Headers for continue records |
|||
|
|||
// Retrieve chunks of 2080/8224 bytes +4 for the header. |
|||
$data_length = strlen($data); |
|||
for ($i = $limit + 4; $i < ($data_length - $limit); $i += $limit) { |
|||
$tmp .= $header; |
|||
$tmp .= substr($data, $i, $limit); |
|||
} |
|||
|
|||
// Retrieve the last chunk of data |
|||
$header = pack("vv", $record, strlen($data) - $i); |
|||
$tmp .= $header; |
|||
$tmp .= substr($data, $i, strlen($data) - $i); |
|||
|
|||
return $tmp; |
|||
} |
|||
} |
|||
@ -0,0 +1,523 @@ |
|||
<?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_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## |
|||
*/ |
|||
|
|||
|
|||
/** |
|||
* PHPExcel_Shared_Escher_DggContainer_BstoreContainer |
|||
* |
|||
* @category PHPExcel |
|||
* @package PHPExcel_Writer_Excel5 |
|||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) |
|||
*/ |
|||
class PHPExcel_Writer_Excel5_Escher |
|||
{ |
|||
/** |
|||
* The object we are writing |
|||
*/ |
|||
private $object; |
|||
|
|||
/** |
|||
* The written binary data |
|||
*/ |
|||
private $data; |
|||
|
|||
/** |
|||
* Shape offsets. Positions in binary stream where a new shape record begins |
|||
* |
|||
* @var array |
|||
*/ |
|||
private $spOffsets; |
|||
|
|||
/** |
|||
* Shape types. |
|||
* |
|||
* @var array |
|||
*/ |
|||
private $spTypes; |
|||
|
|||
/** |
|||
* Constructor |
|||
* |
|||
* @param mixed |
|||
*/ |
|||
public function __construct($object) |
|||
{ |
|||
$this->object = $object; |
|||
} |
|||
|
|||
/** |
|||
* Process the object to be written |
|||
*/ |
|||
public function close() |
|||
{ |
|||
// initialize |
|||
$this->data = ''; |
|||
|
|||
switch (get_class($this->object)) { |
|||
case 'PHPExcel_Shared_Escher': |
|||
if ($dggContainer = $this->object->getDggContainer()) { |
|||
$writer = new PHPExcel_Writer_Excel5_Escher($dggContainer); |
|||
$this->data = $writer->close(); |
|||
} elseif ($dgContainer = $this->object->getDgContainer()) { |
|||
$writer = new PHPExcel_Writer_Excel5_Escher($dgContainer); |
|||
$this->data = $writer->close(); |
|||
$this->spOffsets = $writer->getSpOffsets(); |
|||
$this->spTypes = $writer->getSpTypes(); |
|||
} |
|||
break; |
|||
case 'PHPExcel_Shared_Escher_DggContainer': |
|||
// this is a container record |
|||
|
|||
// initialize |
|||
$innerData = ''; |
|||
|
|||
// write the dgg |
|||
$recVer = 0x0; |
|||
$recInstance = 0x0000; |
|||
$recType = 0xF006; |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
// dgg data |
|||
$dggData = |
|||
pack( |
|||
'VVVV', |
|||
$this->object->getSpIdMax(), // maximum shape identifier increased by one |
|||
$this->object->getCDgSaved() + 1, // number of file identifier clusters increased by one |
|||
$this->object->getCSpSaved(), |
|||
$this->object->getCDgSaved() // count total number of drawings saved |
|||
); |
|||
|
|||
// add file identifier clusters (one per drawing) |
|||
$IDCLs = $this->object->getIDCLs(); |
|||
|
|||
foreach ($IDCLs as $dgId => $maxReducedSpId) { |
|||
$dggData .= pack('VV', $dgId, $maxReducedSpId + 1); |
|||
} |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, strlen($dggData)); |
|||
$innerData .= $header . $dggData; |
|||
|
|||
// write the bstoreContainer |
|||
if ($bstoreContainer = $this->object->getBstoreContainer()) { |
|||
$writer = new PHPExcel_Writer_Excel5_Escher($bstoreContainer); |
|||
$innerData .= $writer->close(); |
|||
} |
|||
|
|||
// write the record |
|||
$recVer = 0xF; |
|||
$recInstance = 0x0000; |
|||
$recType = 0xF000; |
|||
$length = strlen($innerData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$this->data = $header . $innerData; |
|||
break; |
|||
case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer': |
|||
// this is a container record |
|||
|
|||
// initialize |
|||
$innerData = ''; |
|||
|
|||
// treat the inner data |
|||
if ($BSECollection = $this->object->getBSECollection()) { |
|||
foreach ($BSECollection as $BSE) { |
|||
$writer = new PHPExcel_Writer_Excel5_Escher($BSE); |
|||
$innerData .= $writer->close(); |
|||
} |
|||
} |
|||
|
|||
// write the record |
|||
$recVer = 0xF; |
|||
$recInstance = count($this->object->getBSECollection()); |
|||
$recType = 0xF001; |
|||
$length = strlen($innerData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$this->data = $header . $innerData; |
|||
break; |
|||
case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE': |
|||
// this is a semi-container record |
|||
|
|||
// initialize |
|||
$innerData = ''; |
|||
|
|||
// here we treat the inner data |
|||
if ($blip = $this->object->getBlip()) { |
|||
$writer = new PHPExcel_Writer_Excel5_Escher($blip); |
|||
$innerData .= $writer->close(); |
|||
} |
|||
|
|||
// initialize |
|||
$data = ''; |
|||
|
|||
$btWin32 = $this->object->getBlipType(); |
|||
$btMacOS = $this->object->getBlipType(); |
|||
$data .= pack('CC', $btWin32, $btMacOS); |
|||
|
|||
$rgbUid = pack('VVVV', 0, 0, 0, 0); // todo |
|||
$data .= $rgbUid; |
|||
|
|||
$tag = 0; |
|||
$size = strlen($innerData); |
|||
$cRef = 1; |
|||
$foDelay = 0; //todo |
|||
$unused1 = 0x0; |
|||
$cbName = 0x0; |
|||
$unused2 = 0x0; |
|||
$unused3 = 0x0; |
|||
$data .= pack('vVVVCCCC', $tag, $size, $cRef, $foDelay, $unused1, $cbName, $unused2, $unused3); |
|||
|
|||
$data .= $innerData; |
|||
|
|||
// write the record |
|||
$recVer = 0x2; |
|||
$recInstance = $this->object->getBlipType(); |
|||
$recType = 0xF007; |
|||
$length = strlen($data); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$this->data = $header; |
|||
|
|||
$this->data .= $data; |
|||
break; |
|||
case 'PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip': |
|||
// this is an atom record |
|||
|
|||
// write the record |
|||
switch ($this->object->getParent()->getBlipType()) { |
|||
case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG: |
|||
// initialize |
|||
$innerData = ''; |
|||
|
|||
$rgbUid1 = pack('VVVV', 0, 0, 0, 0); // todo |
|||
$innerData .= $rgbUid1; |
|||
|
|||
$tag = 0xFF; // todo |
|||
$innerData .= pack('C', $tag); |
|||
|
|||
$innerData .= $this->object->getData(); |
|||
|
|||
$recVer = 0x0; |
|||
$recInstance = 0x46A; |
|||
$recType = 0xF01D; |
|||
$length = strlen($innerData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$this->data = $header; |
|||
|
|||
$this->data .= $innerData; |
|||
break; |
|||
|
|||
case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG: |
|||
// initialize |
|||
$innerData = ''; |
|||
|
|||
$rgbUid1 = pack('VVVV', 0, 0, 0, 0); // todo |
|||
$innerData .= $rgbUid1; |
|||
|
|||
$tag = 0xFF; // todo |
|||
$innerData .= pack('C', $tag); |
|||
|
|||
$innerData .= $this->object->getData(); |
|||
|
|||
$recVer = 0x0; |
|||
$recInstance = 0x6E0; |
|||
$recType = 0xF01E; |
|||
$length = strlen($innerData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$this->data = $header; |
|||
|
|||
$this->data .= $innerData; |
|||
break; |
|||
} |
|||
break; |
|||
case 'PHPExcel_Shared_Escher_DgContainer': |
|||
// this is a container record |
|||
|
|||
// initialize |
|||
$innerData = ''; |
|||
|
|||
// write the dg |
|||
$recVer = 0x0; |
|||
$recInstance = $this->object->getDgId(); |
|||
$recType = 0xF008; |
|||
$length = 8; |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
// number of shapes in this drawing (including group shape) |
|||
$countShapes = count($this->object->getSpgrContainer()->getChildren()); |
|||
$innerData .= $header . pack('VV', $countShapes, $this->object->getLastSpId()); |
|||
//$innerData .= $header . pack('VV', 0, 0); |
|||
|
|||
// write the spgrContainer |
|||
if ($spgrContainer = $this->object->getSpgrContainer()) { |
|||
$writer = new PHPExcel_Writer_Excel5_Escher($spgrContainer); |
|||
$innerData .= $writer->close(); |
|||
|
|||
// get the shape offsets relative to the spgrContainer record |
|||
$spOffsets = $writer->getSpOffsets(); |
|||
$spTypes = $writer->getSpTypes(); |
|||
|
|||
// save the shape offsets relative to dgContainer |
|||
foreach ($spOffsets as & $spOffset) { |
|||
$spOffset += 24; // add length of dgContainer header data (8 bytes) plus dg data (16 bytes) |
|||
} |
|||
|
|||
$this->spOffsets = $spOffsets; |
|||
$this->spTypes = $spTypes; |
|||
} |
|||
|
|||
// write the record |
|||
$recVer = 0xF; |
|||
$recInstance = 0x0000; |
|||
$recType = 0xF002; |
|||
$length = strlen($innerData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$this->data = $header . $innerData; |
|||
break; |
|||
case 'PHPExcel_Shared_Escher_DgContainer_SpgrContainer': |
|||
// this is a container record |
|||
|
|||
// initialize |
|||
$innerData = ''; |
|||
|
|||
// initialize spape offsets |
|||
$totalSize = 8; |
|||
$spOffsets = array(); |
|||
$spTypes = array(); |
|||
|
|||
// treat the inner data |
|||
foreach ($this->object->getChildren() as $spContainer) { |
|||
$writer = new PHPExcel_Writer_Excel5_Escher($spContainer); |
|||
$spData = $writer->close(); |
|||
$innerData .= $spData; |
|||
|
|||
// save the shape offsets (where new shape records begin) |
|||
$totalSize += strlen($spData); |
|||
$spOffsets[] = $totalSize; |
|||
|
|||
$spTypes = array_merge($spTypes, $writer->getSpTypes()); |
|||
} |
|||
|
|||
// write the record |
|||
$recVer = 0xF; |
|||
$recInstance = 0x0000; |
|||
$recType = 0xF003; |
|||
$length = strlen($innerData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$this->data = $header . $innerData; |
|||
$this->spOffsets = $spOffsets; |
|||
$this->spTypes = $spTypes; |
|||
break; |
|||
case 'PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer': |
|||
// initialize |
|||
$data = ''; |
|||
|
|||
// build the data |
|||
|
|||
// write group shape record, if necessary? |
|||
if ($this->object->getSpgr()) { |
|||
$recVer = 0x1; |
|||
$recInstance = 0x0000; |
|||
$recType = 0xF009; |
|||
$length = 0x00000010; |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$data .= $header . pack('VVVV', 0, 0, 0, 0); |
|||
} |
|||
$this->spTypes[] = ($this->object->getSpType()); |
|||
|
|||
// write the shape record |
|||
$recVer = 0x2; |
|||
$recInstance = $this->object->getSpType(); // shape type |
|||
$recType = 0xF00A; |
|||
$length = 0x00000008; |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$data .= $header . pack('VV', $this->object->getSpId(), $this->object->getSpgr() ? 0x0005 : 0x0A00); |
|||
|
|||
|
|||
// the options |
|||
if ($this->object->getOPTCollection()) { |
|||
$optData = ''; |
|||
|
|||
$recVer = 0x3; |
|||
$recInstance = count($this->object->getOPTCollection()); |
|||
$recType = 0xF00B; |
|||
foreach ($this->object->getOPTCollection() as $property => $value) { |
|||
$optData .= pack('vV', $property, $value); |
|||
} |
|||
$length = strlen($optData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
$data .= $header . $optData; |
|||
} |
|||
|
|||
// the client anchor |
|||
if ($this->object->getStartCoordinates()) { |
|||
$clientAnchorData = ''; |
|||
|
|||
$recVer = 0x0; |
|||
$recInstance = 0x0; |
|||
$recType = 0xF010; |
|||
|
|||
// start coordinates |
|||
list($column, $row) = PHPExcel_Cell::coordinateFromString($this->object->getStartCoordinates()); |
|||
$c1 = PHPExcel_Cell::columnIndexFromString($column) - 1; |
|||
$r1 = $row - 1; |
|||
|
|||
// start offsetX |
|||
$startOffsetX = $this->object->getStartOffsetX(); |
|||
|
|||
// start offsetY |
|||
$startOffsetY = $this->object->getStartOffsetY(); |
|||
|
|||
// end coordinates |
|||
list($column, $row) = PHPExcel_Cell::coordinateFromString($this->object->getEndCoordinates()); |
|||
$c2 = PHPExcel_Cell::columnIndexFromString($column) - 1; |
|||
$r2 = $row - 1; |
|||
|
|||
// end offsetX |
|||
$endOffsetX = $this->object->getEndOffsetX(); |
|||
|
|||
// end offsetY |
|||
$endOffsetY = $this->object->getEndOffsetY(); |
|||
|
|||
$clientAnchorData = pack('vvvvvvvvv', $this->object->getSpFlag(), $c1, $startOffsetX, $r1, $startOffsetY, $c2, $endOffsetX, $r2, $endOffsetY); |
|||
|
|||
$length = strlen($clientAnchorData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
$data .= $header . $clientAnchorData; |
|||
} |
|||
|
|||
// the client data, just empty for now |
|||
if (!$this->object->getSpgr()) { |
|||
$clientDataData = ''; |
|||
|
|||
$recVer = 0x0; |
|||
$recInstance = 0x0; |
|||
$recType = 0xF011; |
|||
|
|||
$length = strlen($clientDataData); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
$data .= $header . $clientDataData; |
|||
} |
|||
|
|||
// write the record |
|||
$recVer = 0xF; |
|||
$recInstance = 0x0000; |
|||
$recType = 0xF004; |
|||
$length = strlen($data); |
|||
|
|||
$recVerInstance = $recVer; |
|||
$recVerInstance |= $recInstance << 4; |
|||
|
|||
$header = pack('vvV', $recVerInstance, $recType, $length); |
|||
|
|||
$this->data = $header . $data; |
|||
break; |
|||
} |
|||
|
|||
return $this->data; |
|||
} |
|||
|
|||
/** |
|||
* Gets the shape offsets |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function getSpOffsets() |
|||
{ |
|||
return $this->spOffsets; |
|||
} |
|||
|
|||
/** |
|||
* Gets the shape types |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function getSpTypes() |
|||
{ |
|||
return $this->spTypes; |
|||
} |
|||
} |
|||
@ -0,0 +1,166 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel5_Font |
|||
* |
|||
* 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## |
|||
*/ |
|||
class PHPExcel_Writer_Excel5_Font |
|||
{ |
|||
/** |
|||
* Color index |
|||
* |
|||
* @var int |
|||
*/ |
|||
private $colorIndex; |
|||
|
|||
/** |
|||
* Font |
|||
* |
|||
* @var PHPExcel_Style_Font |
|||
*/ |
|||
private $font; |
|||
|
|||
/** |
|||
* Constructor |
|||
* |
|||
* @param PHPExcel_Style_Font $font |
|||
*/ |
|||
public function __construct(PHPExcel_Style_Font $font = null) |
|||
{ |
|||
$this->colorIndex = 0x7FFF; |
|||
$this->font = $font; |
|||
} |
|||
|
|||
/** |
|||
* Set the color index |
|||
* |
|||
* @param int $colorIndex |
|||
*/ |
|||
public function setColorIndex($colorIndex) |
|||
{ |
|||
$this->colorIndex = $colorIndex; |
|||
} |
|||
|
|||
/** |
|||
* Get font record data |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function writeFont() |
|||
{ |
|||
$font_outline = 0; |
|||
$font_shadow = 0; |
|||
|
|||
$icv = $this->colorIndex; // Index to color palette |
|||
if ($this->font->getSuperScript()) { |
|||
$sss = 1; |
|||
} elseif ($this->font->getSubScript()) { |
|||
$sss = 2; |
|||
} else { |
|||
$sss = 0; |
|||
} |
|||
$bFamily = 0; // Font family |
|||
$bCharSet = PHPExcel_Shared_Font::getCharsetFromFontName($this->font->getName()); // Character set |
|||
|
|||
$record = 0x31; // Record identifier |
|||
$reserved = 0x00; // Reserved |
|||
$grbit = 0x00; // Font attributes |
|||
if ($this->font->getItalic()) { |
|||
$grbit |= 0x02; |
|||
} |
|||
if ($this->font->getStrikethrough()) { |
|||
$grbit |= 0x08; |
|||
} |
|||
if ($font_outline) { |
|||
$grbit |= 0x10; |
|||
} |
|||
if ($font_shadow) { |
|||
$grbit |= 0x20; |
|||
} |
|||
|
|||
$data = pack( |
|||
"vvvvvCCCC", |
|||
// Fontsize (in twips) |
|||
$this->font->getSize() * 20, |
|||
$grbit, |
|||
// Colour |
|||
$icv, |
|||
// Font weight |
|||
self::mapBold($this->font->getBold()), |
|||
// Superscript/Subscript |
|||
$sss, |
|||
self::mapUnderline($this->font->getUnderline()), |
|||
$bFamily, |
|||
$bCharSet, |
|||
$reserved |
|||
); |
|||
$data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($this->font->getName()); |
|||
|
|||
$length = strlen($data); |
|||
$header = pack("vv", $record, $length); |
|||
|
|||
return($header . $data); |
|||
} |
|||
|
|||
/** |
|||
* Map to BIFF5-BIFF8 codes for bold |
|||
* |
|||
* @param boolean $bold |
|||
* @return int |
|||
*/ |
|||
private static function mapBold($bold) |
|||
{ |
|||
if ($bold) { |
|||
return 0x2BC; // 700 = Bold font weight |
|||
} |
|||
return 0x190; // 400 = Normal font weight |
|||
} |
|||
|
|||
/** |
|||
* Map of BIFF2-BIFF8 codes for underline styles |
|||
* @static array of int |
|||
* |
|||
*/ |
|||
private static $mapUnderline = array( |
|||
PHPExcel_Style_Font::UNDERLINE_NONE => 0x00, |
|||
PHPExcel_Style_Font::UNDERLINE_SINGLE => 0x01, |
|||
PHPExcel_Style_Font::UNDERLINE_DOUBLE => 0x02, |
|||
PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING => 0x21, |
|||
PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING => 0x22, |
|||
); |
|||
|
|||
/** |
|||
* Map underline |
|||
* |
|||
* @param string |
|||
* @return int |
|||
*/ |
|||
private static function mapUnderline($underline) |
|||
{ |
|||
if (isset(self::$mapUnderline[$underline])) { |
|||
return self::$mapUnderline[$underline]; |
|||
} |
|||
return 0x00; |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,557 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Excel5_Xf |
|||
* |
|||
* 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_Format (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_Xf |
|||
{ |
|||
/** |
|||
* Style XF or a cell XF ? |
|||
* |
|||
* @var boolean |
|||
*/ |
|||
private $isStyleXf; |
|||
|
|||
/** |
|||
* Index to the FONT record. Index 4 does not exist |
|||
* @var integer |
|||
*/ |
|||
private $fontIndex; |
|||
|
|||
/** |
|||
* An index (2 bytes) to a FORMAT record (number format). |
|||
* @var integer |
|||
*/ |
|||
private $numberFormatIndex; |
|||
|
|||
/** |
|||
* 1 bit, apparently not used. |
|||
* @var integer |
|||
*/ |
|||
private $textJustLast; |
|||
|
|||
/** |
|||
* The cell's foreground color. |
|||
* @var integer |
|||
*/ |
|||
private $foregroundColor; |
|||
|
|||
/** |
|||
* The cell's background color. |
|||
* @var integer |
|||
*/ |
|||
private $backgroundColor; |
|||
|
|||
/** |
|||
* Color of the bottom border of the cell. |
|||
* @var integer |
|||
*/ |
|||
private $bottomBorderColor; |
|||
|
|||
/** |
|||
* Color of the top border of the cell. |
|||
* @var integer |
|||
*/ |
|||
private $topBorderColor; |
|||
|
|||
/** |
|||
* Color of the left border of the cell. |
|||
* @var integer |
|||
*/ |
|||
private $leftBorderColor; |
|||
|
|||
/** |
|||
* Color of the right border of the cell. |
|||
* @var integer |
|||
*/ |
|||
private $rightBorderColor; |
|||
|
|||
/** |
|||
* Constructor |
|||
* |
|||
* @access public |
|||
* @param PHPExcel_Style The XF format |
|||
*/ |
|||
public function __construct(PHPExcel_Style $style = null) |
|||
{ |
|||
$this->isStyleXf = false; |
|||
$this->fontIndex = 0; |
|||
|
|||
$this->numberFormatIndex = 0; |
|||
|
|||
$this->textJustLast = 0; |
|||
|
|||
$this->foregroundColor = 0x40; |
|||
$this->backgroundColor = 0x41; |
|||
|
|||
$this->_diag = 0; |
|||
|
|||
$this->bottomBorderColor = 0x40; |
|||
$this->topBorderColor = 0x40; |
|||
$this->leftBorderColor = 0x40; |
|||
$this->rightBorderColor = 0x40; |
|||
$this->_diag_color = 0x40; |
|||
$this->_style = $style; |
|||
|
|||
} |
|||
|
|||
|
|||
/** |
|||
* Generate an Excel BIFF XF record (style or cell). |
|||
* |
|||
* @return string The XF record |
|||
*/ |
|||
public function writeXf() |
|||
{ |
|||
// Set the type of the XF record and some of the attributes. |
|||
if ($this->isStyleXf) { |
|||
$style = 0xFFF5; |
|||
} else { |
|||
$style = self::mapLocked($this->_style->getProtection()->getLocked()); |
|||
$style |= self::mapHidden($this->_style->getProtection()->getHidden()) << 1; |
|||
} |
|||
|
|||
// Flags to indicate if attributes have been set. |
|||
$atr_num = ($this->numberFormatIndex != 0)?1:0; |
|||
$atr_fnt = ($this->fontIndex != 0)?1:0; |
|||
$atr_alc = ((int) $this->_style->getAlignment()->getWrapText()) ? 1 : 0; |
|||
$atr_bdr = (self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) || |
|||
self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) || |
|||
self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) || |
|||
self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()))?1:0; |
|||
$atr_pat = (($this->foregroundColor != 0x40) || |
|||
($this->backgroundColor != 0x41) || |
|||
self::mapFillType($this->_style->getFill()->getFillType()))?1:0; |
|||
$atr_prot = self::mapLocked($this->_style->getProtection()->getLocked()) |
|||
| self::mapHidden($this->_style->getProtection()->getHidden()); |
|||
|
|||
// Zero the default border colour if the border has not been set. |
|||
if (self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) == 0) { |
|||
$this->bottomBorderColor = 0; |
|||
} |
|||
if (self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) == 0) { |
|||
$this->topBorderColor = 0; |
|||
} |
|||
if (self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) == 0) { |
|||
$this->rightBorderColor = 0; |
|||
} |
|||
if (self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()) == 0) { |
|||
$this->leftBorderColor = 0; |
|||
} |
|||
if (self::mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) == 0) { |
|||
$this->_diag_color = 0; |
|||
} |
|||
|
|||
$record = 0x00E0; // Record identifier |
|||
$length = 0x0014; // Number of bytes to follow |
|||
|
|||
$ifnt = $this->fontIndex; // Index to FONT record |
|||
$ifmt = $this->numberFormatIndex; // Index to FORMAT record |
|||
|
|||
$align = $this->mapHAlign($this->_style->getAlignment()->getHorizontal()); // Alignment |
|||
$align |= (int) $this->_style->getAlignment()->getWrapText() << 3; |
|||
$align |= self::mapVAlign($this->_style->getAlignment()->getVertical()) << 4; |
|||
$align |= $this->textJustLast << 7; |
|||
|
|||
$used_attrib = $atr_num << 2; |
|||
$used_attrib |= $atr_fnt << 3; |
|||
$used_attrib |= $atr_alc << 4; |
|||
$used_attrib |= $atr_bdr << 5; |
|||
$used_attrib |= $atr_pat << 6; |
|||
$used_attrib |= $atr_prot << 7; |
|||
|
|||
$icv = $this->foregroundColor; // fg and bg pattern colors |
|||
$icv |= $this->backgroundColor << 7; |
|||
|
|||
$border1 = self::mapBorderStyle($this->_style->getBorders()->getLeft()->getBorderStyle()); // Border line style and color |
|||
$border1 |= self::mapBorderStyle($this->_style->getBorders()->getRight()->getBorderStyle()) << 4; |
|||
$border1 |= self::mapBorderStyle($this->_style->getBorders()->getTop()->getBorderStyle()) << 8; |
|||
$border1 |= self::mapBorderStyle($this->_style->getBorders()->getBottom()->getBorderStyle()) << 12; |
|||
$border1 |= $this->leftBorderColor << 16; |
|||
$border1 |= $this->rightBorderColor << 23; |
|||
|
|||
$diagonalDirection = $this->_style->getBorders()->getDiagonalDirection(); |
|||
$diag_tl_to_rb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH |
|||
|| $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_DOWN; |
|||
$diag_tr_to_lb = $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_BOTH |
|||
|| $diagonalDirection == PHPExcel_Style_Borders::DIAGONAL_UP; |
|||
$border1 |= $diag_tl_to_rb << 30; |
|||
$border1 |= $diag_tr_to_lb << 31; |
|||
|
|||
$border2 = $this->topBorderColor; // Border color |
|||
$border2 |= $this->bottomBorderColor << 7; |
|||
$border2 |= $this->_diag_color << 14; |
|||
$border2 |= self::mapBorderStyle($this->_style->getBorders()->getDiagonal()->getBorderStyle()) << 21; |
|||
$border2 |= self::mapFillType($this->_style->getFill()->getFillType()) << 26; |
|||
|
|||
$header = pack("vv", $record, $length); |
|||
|
|||
//BIFF8 options: identation, shrinkToFit and text direction |
|||
$biff8_options = $this->_style->getAlignment()->getIndent(); |
|||
$biff8_options |= (int) $this->_style->getAlignment()->getShrinkToFit() << 4; |
|||
|
|||
$data = pack("vvvC", $ifnt, $ifmt, $style, $align); |
|||
$data .= pack("CCC", self::mapTextRotation($this->_style->getAlignment()->getTextRotation()), $biff8_options, $used_attrib); |
|||
$data .= pack("VVv", $border1, $border2, $icv); |
|||
|
|||
return($header . $data); |
|||
} |
|||
|
|||
/** |
|||
* Is this a style XF ? |
|||
* |
|||
* @param boolean $value |
|||
*/ |
|||
public function setIsStyleXf($value) |
|||
{ |
|||
$this->isStyleXf = $value; |
|||
} |
|||
|
|||
/** |
|||
* Sets the cell's bottom border color |
|||
* |
|||
* @access public |
|||
* @param int $colorIndex Color index |
|||
*/ |
|||
public function setBottomColor($colorIndex) |
|||
{ |
|||
$this->bottomBorderColor = $colorIndex; |
|||
} |
|||
|
|||
/** |
|||
* Sets the cell's top border color |
|||
* |
|||
* @access public |
|||
* @param int $colorIndex Color index |
|||
*/ |
|||
public function setTopColor($colorIndex) |
|||
{ |
|||
$this->topBorderColor = $colorIndex; |
|||
} |
|||
|
|||
/** |
|||
* Sets the cell's left border color |
|||
* |
|||
* @access public |
|||
* @param int $colorIndex Color index |
|||
*/ |
|||
public function setLeftColor($colorIndex) |
|||
{ |
|||
$this->leftBorderColor = $colorIndex; |
|||
} |
|||
|
|||
/** |
|||
* Sets the cell's right border color |
|||
* |
|||
* @access public |
|||
* @param int $colorIndex Color index |
|||
*/ |
|||
public function setRightColor($colorIndex) |
|||
{ |
|||
$this->rightBorderColor = $colorIndex; |
|||
} |
|||
|
|||
/** |
|||
* Sets the cell's diagonal border color |
|||
* |
|||
* @access public |
|||
* @param int $colorIndex Color index |
|||
*/ |
|||
public function setDiagColor($colorIndex) |
|||
{ |
|||
$this->_diag_color = $colorIndex; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Sets the cell's foreground color |
|||
* |
|||
* @access public |
|||
* @param int $colorIndex Color index |
|||
*/ |
|||
public function setFgColor($colorIndex) |
|||
{ |
|||
$this->foregroundColor = $colorIndex; |
|||
} |
|||
|
|||
/** |
|||
* Sets the cell's background color |
|||
* |
|||
* @access public |
|||
* @param int $colorIndex Color index |
|||
*/ |
|||
public function setBgColor($colorIndex) |
|||
{ |
|||
$this->backgroundColor = $colorIndex; |
|||
} |
|||
|
|||
/** |
|||
* Sets the index to the number format record |
|||
* It can be date, time, currency, etc... |
|||
* |
|||
* @access public |
|||
* @param integer $numberFormatIndex Index to format record |
|||
*/ |
|||
public function setNumberFormatIndex($numberFormatIndex) |
|||
{ |
|||
$this->numberFormatIndex = $numberFormatIndex; |
|||
} |
|||
|
|||
/** |
|||
* Set the font index. |
|||
* |
|||
* @param int $value Font index, note that value 4 does not exist |
|||
*/ |
|||
public function setFontIndex($value) |
|||
{ |
|||
$this->fontIndex = $value; |
|||
} |
|||
|
|||
/** |
|||
* Map of BIFF2-BIFF8 codes for border styles |
|||
* @static array of int |
|||
* |
|||
*/ |
|||
private static $mapBorderStyles = array( |
|||
PHPExcel_Style_Border::BORDER_NONE => 0x00, |
|||
PHPExcel_Style_Border::BORDER_THIN => 0x01, |
|||
PHPExcel_Style_Border::BORDER_MEDIUM => 0x02, |
|||
PHPExcel_Style_Border::BORDER_DASHED => 0x03, |
|||
PHPExcel_Style_Border::BORDER_DOTTED => 0x04, |
|||
PHPExcel_Style_Border::BORDER_THICK => 0x05, |
|||
PHPExcel_Style_Border::BORDER_DOUBLE => 0x06, |
|||
PHPExcel_Style_Border::BORDER_HAIR => 0x07, |
|||
PHPExcel_Style_Border::BORDER_MEDIUMDASHED => 0x08, |
|||
PHPExcel_Style_Border::BORDER_DASHDOT => 0x09, |
|||
PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT => 0x0A, |
|||
PHPExcel_Style_Border::BORDER_DASHDOTDOT => 0x0B, |
|||
PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT => 0x0C, |
|||
PHPExcel_Style_Border::BORDER_SLANTDASHDOT => 0x0D, |
|||
); |
|||
|
|||
/** |
|||
* Map border style |
|||
* |
|||
* @param string $borderStyle |
|||
* @return int |
|||
*/ |
|||
private static function mapBorderStyle($borderStyle) |
|||
{ |
|||
if (isset(self::$mapBorderStyles[$borderStyle])) { |
|||
return self::$mapBorderStyles[$borderStyle]; |
|||
} |
|||
return 0x00; |
|||
} |
|||
|
|||
/** |
|||
* Map of BIFF2-BIFF8 codes for fill types |
|||
* @static array of int |
|||
* |
|||
*/ |
|||
private static $mapFillTypes = array( |
|||
PHPExcel_Style_Fill::FILL_NONE => 0x00, |
|||
PHPExcel_Style_Fill::FILL_SOLID => 0x01, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY => 0x02, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY => 0x03, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY => 0x04, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL => 0x06, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN => 0x07, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_DARKUP => 0x08, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID => 0x09, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS => 0x0A, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN => 0x0D, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP => 0x0E, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID => 0x0F, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_GRAY125 => 0x11, |
|||
PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625 => 0x12, |
|||
PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8 |
|||
PHPExcel_Style_Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8 |
|||
); |
|||
|
|||
/** |
|||
* Map fill type |
|||
* |
|||
* @param string $fillType |
|||
* @return int |
|||
*/ |
|||
private static function mapFillType($fillType) |
|||
{ |
|||
if (isset(self::$mapFillTypes[$fillType])) { |
|||
return self::$mapFillTypes[$fillType]; |
|||
} |
|||
return 0x00; |
|||
} |
|||
|
|||
/** |
|||
* Map of BIFF2-BIFF8 codes for horizontal alignment |
|||
* @static array of int |
|||
* |
|||
*/ |
|||
private static $mapHAlignments = array( |
|||
PHPExcel_Style_Alignment::HORIZONTAL_GENERAL => 0, |
|||
PHPExcel_Style_Alignment::HORIZONTAL_LEFT => 1, |
|||
PHPExcel_Style_Alignment::HORIZONTAL_CENTER => 2, |
|||
PHPExcel_Style_Alignment::HORIZONTAL_RIGHT => 3, |
|||
PHPExcel_Style_Alignment::HORIZONTAL_FILL => 4, |
|||
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY => 5, |
|||
PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6, |
|||
); |
|||
|
|||
/** |
|||
* Map to BIFF2-BIFF8 codes for horizontal alignment |
|||
* |
|||
* @param string $hAlign |
|||
* @return int |
|||
*/ |
|||
private function mapHAlign($hAlign) |
|||
{ |
|||
if (isset(self::$mapHAlignments[$hAlign])) { |
|||
return self::$mapHAlignments[$hAlign]; |
|||
} |
|||
return 0; |
|||
} |
|||
|
|||
/** |
|||
* Map of BIFF2-BIFF8 codes for vertical alignment |
|||
* @static array of int |
|||
* |
|||
*/ |
|||
private static $mapVAlignments = array( |
|||
PHPExcel_Style_Alignment::VERTICAL_TOP => 0, |
|||
PHPExcel_Style_Alignment::VERTICAL_CENTER => 1, |
|||
PHPExcel_Style_Alignment::VERTICAL_BOTTOM => 2, |
|||
PHPExcel_Style_Alignment::VERTICAL_JUSTIFY => 3, |
|||
); |
|||
|
|||
/** |
|||
* Map to BIFF2-BIFF8 codes for vertical alignment |
|||
* |
|||
* @param string $vAlign |
|||
* @return int |
|||
*/ |
|||
private static function mapVAlign($vAlign) |
|||
{ |
|||
if (isset(self::$mapVAlignments[$vAlign])) { |
|||
return self::$mapVAlignments[$vAlign]; |
|||
} |
|||
return 2; |
|||
} |
|||
|
|||
/** |
|||
* Map to BIFF8 codes for text rotation angle |
|||
* |
|||
* @param int $textRotation |
|||
* @return int |
|||
*/ |
|||
private static function mapTextRotation($textRotation) |
|||
{ |
|||
if ($textRotation >= 0) { |
|||
return $textRotation; |
|||
} elseif ($textRotation == -165) { |
|||
return 255; |
|||
} elseif ($textRotation < 0) { |
|||
return 90 - $textRotation; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Map locked |
|||
* |
|||
* @param string |
|||
* @return int |
|||
*/ |
|||
private static function mapLocked($locked) |
|||
{ |
|||
switch ($locked) { |
|||
case PHPExcel_Style_Protection::PROTECTION_INHERIT: |
|||
return 1; |
|||
case PHPExcel_Style_Protection::PROTECTION_PROTECTED: |
|||
return 1; |
|||
case PHPExcel_Style_Protection::PROTECTION_UNPROTECTED: |
|||
return 0; |
|||
default: |
|||
return 1; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Map hidden |
|||
* |
|||
* @param string |
|||
* @return int |
|||
*/ |
|||
private static function mapHidden($hidden) |
|||
{ |
|||
switch ($hidden) { |
|||
case PHPExcel_Style_Protection::PROTECTION_INHERIT: |
|||
return 0; |
|||
case PHPExcel_Style_Protection::PROTECTION_PROTECTED: |
|||
return 1; |
|||
case PHPExcel_Style_Protection::PROTECTION_UNPROTECTED: |
|||
return 0; |
|||
default: |
|||
return 0; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_Exception |
|||
* |
|||
* 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 |
|||
* @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_Exception extends PHPExcel_Exception |
|||
{ |
|||
/** |
|||
* Error handler callback |
|||
* |
|||
* @param mixed $code |
|||
* @param mixed $string |
|||
* @param mixed $file |
|||
* @param mixed $line |
|||
* @param mixed $context |
|||
*/ |
|||
public static function errorHandlerCallback($code, $string, $file, $line, $context) |
|||
{ |
|||
$e = new self($string, $code); |
|||
$e->line = $line; |
|||
$e->file = $file; |
|||
throw $e; |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,37 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_IWriter |
|||
* |
|||
* 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 |
|||
* @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## |
|||
*/ |
|||
interface PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* Save PHPExcel to file |
|||
* |
|||
* @param string $pFilename Name of the file to save |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function save($pFilename = null); |
|||
} |
|||
@ -0,0 +1,190 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument |
|||
* |
|||
* 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_OpenDocument |
|||
* @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_OpenDocument extends PHPExcel_Writer_Abstract implements PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* Private writer parts |
|||
* |
|||
* @var PHPExcel_Writer_OpenDocument_WriterPart[] |
|||
*/ |
|||
private $writerParts = array(); |
|||
|
|||
/** |
|||
* Private PHPExcel |
|||
* |
|||
* @var PHPExcel |
|||
*/ |
|||
private $spreadSheet; |
|||
|
|||
/** |
|||
* Create a new PHPExcel_Writer_OpenDocument |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
*/ |
|||
public function __construct(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
$this->setPHPExcel($pPHPExcel); |
|||
|
|||
$writerPartsArray = array( |
|||
'content' => 'PHPExcel_Writer_OpenDocument_Content', |
|||
'meta' => 'PHPExcel_Writer_OpenDocument_Meta', |
|||
'meta_inf' => 'PHPExcel_Writer_OpenDocument_MetaInf', |
|||
'mimetype' => 'PHPExcel_Writer_OpenDocument_Mimetype', |
|||
'settings' => 'PHPExcel_Writer_OpenDocument_Settings', |
|||
'styles' => 'PHPExcel_Writer_OpenDocument_Styles', |
|||
'thumbnails' => 'PHPExcel_Writer_OpenDocument_Thumbnails' |
|||
); |
|||
|
|||
foreach ($writerPartsArray as $writer => $class) { |
|||
$this->writerParts[$writer] = new $class($this); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Get writer part |
|||
* |
|||
* @param string $pPartName Writer part name |
|||
* @return PHPExcel_Writer_Excel2007_WriterPart |
|||
*/ |
|||
public function getWriterPart($pPartName = '') |
|||
{ |
|||
if ($pPartName != '' && isset($this->writerParts[strtolower($pPartName)])) { |
|||
return $this->writerParts[strtolower($pPartName)]; |
|||
} else { |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Save PHPExcel to file |
|||
* |
|||
* @param string $pFilename |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function save($pFilename = null) |
|||
{ |
|||
if (!$this->spreadSheet) { |
|||
throw new PHPExcel_Writer_Exception('PHPExcel object unassigned.'); |
|||
} |
|||
|
|||
// garbage collect |
|||
$this->spreadSheet->garbageCollect(); |
|||
|
|||
// If $pFilename is php://output or php://stdout, make it a temporary file... |
|||
$originalFilename = $pFilename; |
|||
if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { |
|||
$pFilename = @tempnam(PHPExcel_Shared_File::sys_get_temp_dir(), 'phpxltmp'); |
|||
if ($pFilename == '') { |
|||
$pFilename = $originalFilename; |
|||
} |
|||
} |
|||
|
|||
$objZip = $this->createZip($pFilename); |
|||
|
|||
$objZip->addFromString('META-INF/manifest.xml', $this->getWriterPart('meta_inf')->writeManifest()); |
|||
$objZip->addFromString('Thumbnails/thumbnail.png', $this->getWriterPart('thumbnails')->writeThumbnail()); |
|||
$objZip->addFromString('content.xml', $this->getWriterPart('content')->write()); |
|||
$objZip->addFromString('meta.xml', $this->getWriterPart('meta')->write()); |
|||
$objZip->addFromString('mimetype', $this->getWriterPart('mimetype')->write()); |
|||
$objZip->addFromString('settings.xml', $this->getWriterPart('settings')->write()); |
|||
$objZip->addFromString('styles.xml', $this->getWriterPart('styles')->write()); |
|||
|
|||
// Close file |
|||
if ($objZip->close() === false) { |
|||
throw new PHPExcel_Writer_Exception("Could not close zip file $pFilename."); |
|||
} |
|||
|
|||
// If a temporary file was used, copy it to the correct file stream |
|||
if ($originalFilename != $pFilename) { |
|||
if (copy($pFilename, $originalFilename) === false) { |
|||
throw new PHPExcel_Writer_Exception("Could not copy temporary zip file $pFilename to $originalFilename."); |
|||
} |
|||
@unlink($pFilename); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Create zip object |
|||
* |
|||
* @param string $pFilename |
|||
* @throws PHPExcel_Writer_Exception |
|||
* @return ZipArchive |
|||
*/ |
|||
private function createZip($pFilename) |
|||
{ |
|||
// Create new ZIP file and open it for writing |
|||
$zipClass = PHPExcel_Settings::getZipClass(); |
|||
$objZip = new $zipClass(); |
|||
|
|||
// Retrieve OVERWRITE and CREATE constants from the instantiated zip class |
|||
// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP |
|||
$ro = new ReflectionObject($objZip); |
|||
$zipOverWrite = $ro->getConstant('OVERWRITE'); |
|||
$zipCreate = $ro->getConstant('CREATE'); |
|||
|
|||
if (file_exists($pFilename)) { |
|||
unlink($pFilename); |
|||
} |
|||
// Try opening the ZIP file |
|||
if ($objZip->open($pFilename, $zipOverWrite) !== true) { |
|||
if ($objZip->open($pFilename, $zipCreate) !== true) { |
|||
throw new PHPExcel_Writer_Exception("Could not open $pFilename for writing."); |
|||
} |
|||
} |
|||
|
|||
return $objZip; |
|||
} |
|||
|
|||
/** |
|||
* Get PHPExcel object |
|||
* |
|||
* @return PHPExcel |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function getPHPExcel() |
|||
{ |
|||
if ($this->spreadSheet !== null) { |
|||
return $this->spreadSheet; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception('No PHPExcel assigned.'); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Set PHPExcel object |
|||
* |
|||
* @param PHPExcel $pPHPExcel PHPExcel object |
|||
* @throws PHPExcel_Writer_Exception |
|||
* @return PHPExcel_Writer_Excel2007 |
|||
*/ |
|||
public function setPHPExcel(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
$this->spreadSheet = $pPHPExcel; |
|||
return $this; |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
<?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_Writer_OpenDocument |
|||
* @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## |
|||
*/ |
|||
|
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument_Cell_Comment |
|||
* |
|||
* @category PHPExcel |
|||
* @package PHPExcel_Writer_OpenDocument |
|||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) |
|||
* @author Alexander Pervakov <frost-nzcr4@jagmort.com> |
|||
*/ |
|||
class PHPExcel_Writer_OpenDocument_Cell_Comment |
|||
{ |
|||
public static function write(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Cell $cell) |
|||
{ |
|||
$comments = $cell->getWorksheet()->getComments(); |
|||
if (!isset($comments[$cell->getCoordinate()])) { |
|||
return; |
|||
} |
|||
$comment = $comments[$cell->getCoordinate()]; |
|||
|
|||
$objWriter->startElement('office:annotation'); |
|||
//$objWriter->writeAttribute('draw:style-name', 'gr1'); |
|||
//$objWriter->writeAttribute('draw:text-style-name', 'P1'); |
|||
$objWriter->writeAttribute('svg:width', $comment->getWidth()); |
|||
$objWriter->writeAttribute('svg:height', $comment->getHeight()); |
|||
$objWriter->writeAttribute('svg:x', $comment->getMarginLeft()); |
|||
$objWriter->writeAttribute('svg:y', $comment->getMarginTop()); |
|||
//$objWriter->writeAttribute('draw:caption-point-x', $comment->getMarginLeft()); |
|||
//$objWriter->writeAttribute('draw:caption-point-y', $comment->getMarginTop()); |
|||
$objWriter->writeElement('dc:creator', $comment->getAuthor()); |
|||
// TODO: Not realized in PHPExcel_Comment yet. |
|||
//$objWriter->writeElement('dc:date', $comment->getDate()); |
|||
$objWriter->writeElement('text:p', $comment->getText()->getPlainText()); |
|||
//$objWriter->writeAttribute('draw:text-style-name', 'P1'); |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
@ -0,0 +1,272 @@ |
|||
<?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_Writer_OpenDocument |
|||
* @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## |
|||
*/ |
|||
|
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument_Content |
|||
* |
|||
* @category PHPExcel |
|||
* @package PHPExcel_Writer_OpenDocument |
|||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) |
|||
* @author Alexander Pervakov <frost-nzcr4@jagmort.com> |
|||
*/ |
|||
class PHPExcel_Writer_OpenDocument_Content extends PHPExcel_Writer_OpenDocument_WriterPart |
|||
{ |
|||
const NUMBER_COLS_REPEATED_MAX = 1024; |
|||
const NUMBER_ROWS_REPEATED_MAX = 1048576; |
|||
|
|||
/** |
|||
* Write content.xml to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function write(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
if (!$pPHPExcel) { |
|||
$pPHPExcel = $this->getParentWriter()->getPHPExcel(); /* @var $pPHPExcel PHPExcel */ |
|||
} |
|||
|
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8'); |
|||
|
|||
// Content |
|||
$objWriter->startElement('office:document-content'); |
|||
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
|||
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); |
|||
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); |
|||
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); |
|||
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); |
|||
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); |
|||
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
|||
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
|||
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); |
|||
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); |
|||
$objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); |
|||
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); |
|||
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); |
|||
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); |
|||
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); |
|||
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); |
|||
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); |
|||
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
|||
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); |
|||
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); |
|||
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); |
|||
$objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms'); |
|||
$objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); |
|||
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
|||
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); |
|||
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); |
|||
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); |
|||
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); |
|||
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); |
|||
$objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0'); |
|||
$objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0'); |
|||
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); |
|||
$objWriter->writeAttribute('office:version', '1.2'); |
|||
|
|||
$objWriter->writeElement('office:scripts'); |
|||
$objWriter->writeElement('office:font-face-decls'); |
|||
$objWriter->writeElement('office:automatic-styles'); |
|||
|
|||
$objWriter->startElement('office:body'); |
|||
$objWriter->startElement('office:spreadsheet'); |
|||
$objWriter->writeElement('table:calculation-settings'); |
|||
$this->writeSheets($objWriter); |
|||
$objWriter->writeElement('table:named-expressions'); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
|
|||
/** |
|||
* Write sheets |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter |
|||
*/ |
|||
private function writeSheets(PHPExcel_Shared_XMLWriter $objWriter) |
|||
{ |
|||
$pPHPExcel = $this->getParentWriter()->getPHPExcel(); /* @var $pPHPExcel PHPExcel */ |
|||
|
|||
$sheet_count = $pPHPExcel->getSheetCount(); |
|||
for ($i = 0; $i < $sheet_count; $i++) { |
|||
//$this->getWriterPart('Worksheet')->writeWorksheet()); |
|||
$objWriter->startElement('table:table'); |
|||
$objWriter->writeAttribute('table:name', $pPHPExcel->getSheet($i)->getTitle()); |
|||
$objWriter->writeElement('office:forms'); |
|||
$objWriter->startElement('table:table-column'); |
|||
$objWriter->writeAttribute('table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX); |
|||
$objWriter->endElement(); |
|||
$this->writeRows($objWriter, $pPHPExcel->getSheet($i)); |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write rows of the specified sheet |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter |
|||
* @param PHPExcel_Worksheet $sheet |
|||
*/ |
|||
private function writeRows(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet $sheet) |
|||
{ |
|||
$number_rows_repeated = self::NUMBER_ROWS_REPEATED_MAX; |
|||
$span_row = 0; |
|||
$rows = $sheet->getRowIterator(); |
|||
while ($rows->valid()) { |
|||
$number_rows_repeated--; |
|||
$row = $rows->current(); |
|||
if ($row->getCellIterator()->valid()) { |
|||
if ($span_row) { |
|||
$objWriter->startElement('table:table-row'); |
|||
if ($span_row > 1) { |
|||
$objWriter->writeAttribute('table:number-rows-repeated', $span_row); |
|||
} |
|||
$objWriter->startElement('table:table-cell'); |
|||
$objWriter->writeAttribute('table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
$span_row = 0; |
|||
} |
|||
$objWriter->startElement('table:table-row'); |
|||
$this->writeCells($objWriter, $row); |
|||
$objWriter->endElement(); |
|||
} else { |
|||
$span_row++; |
|||
} |
|||
$rows->next(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write cells of the specified row |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter |
|||
* @param PHPExcel_Worksheet_Row $row |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
private function writeCells(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet_Row $row) |
|||
{ |
|||
$number_cols_repeated = self::NUMBER_COLS_REPEATED_MAX; |
|||
$prev_column = -1; |
|||
$cells = $row->getCellIterator(); |
|||
while ($cells->valid()) { |
|||
$cell = $cells->current(); |
|||
$column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1; |
|||
|
|||
$this->writeCellSpan($objWriter, $column, $prev_column); |
|||
$objWriter->startElement('table:table-cell'); |
|||
|
|||
switch ($cell->getDataType()) { |
|||
case PHPExcel_Cell_DataType::TYPE_BOOL: |
|||
$objWriter->writeAttribute('office:value-type', 'boolean'); |
|||
$objWriter->writeAttribute('office:value', $cell->getValue()); |
|||
$objWriter->writeElement('text:p', $cell->getValue()); |
|||
break; |
|||
|
|||
case PHPExcel_Cell_DataType::TYPE_ERROR: |
|||
throw new PHPExcel_Writer_Exception('Writing of error not implemented yet.'); |
|||
break; |
|||
|
|||
case PHPExcel_Cell_DataType::TYPE_FORMULA: |
|||
try { |
|||
$formula_value = $cell->getCalculatedValue(); |
|||
} catch (Exception $e) { |
|||
$formula_value = $cell->getValue(); |
|||
} |
|||
$objWriter->writeAttribute('table:formula', 'of:' . $cell->getValue()); |
|||
if (is_numeric($formula_value)) { |
|||
$objWriter->writeAttribute('office:value-type', 'float'); |
|||
} else { |
|||
$objWriter->writeAttribute('office:value-type', 'string'); |
|||
} |
|||
$objWriter->writeAttribute('office:value', $formula_value); |
|||
$objWriter->writeElement('text:p', $formula_value); |
|||
break; |
|||
|
|||
case PHPExcel_Cell_DataType::TYPE_INLINE: |
|||
throw new PHPExcel_Writer_Exception('Writing of inline not implemented yet.'); |
|||
break; |
|||
|
|||
case PHPExcel_Cell_DataType::TYPE_NUMERIC: |
|||
$objWriter->writeAttribute('office:value-type', 'float'); |
|||
$objWriter->writeAttribute('office:value', $cell->getValue()); |
|||
$objWriter->writeElement('text:p', $cell->getValue()); |
|||
break; |
|||
|
|||
case PHPExcel_Cell_DataType::TYPE_STRING: |
|||
$objWriter->writeAttribute('office:value-type', 'string'); |
|||
$objWriter->writeElement('text:p', $cell->getValue()); |
|||
break; |
|||
} |
|||
PHPExcel_Writer_OpenDocument_Cell_Comment::write($objWriter, $cell); |
|||
$objWriter->endElement(); |
|||
$prev_column = $column; |
|||
$cells->next(); |
|||
} |
|||
$number_cols_repeated = $number_cols_repeated - $prev_column - 1; |
|||
if ($number_cols_repeated > 0) { |
|||
if ($number_cols_repeated > 1) { |
|||
$objWriter->startElement('table:table-cell'); |
|||
$objWriter->writeAttribute('table:number-columns-repeated', $number_cols_repeated); |
|||
$objWriter->endElement(); |
|||
} else { |
|||
$objWriter->writeElement('table:table-cell'); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Write span |
|||
* |
|||
* @param PHPExcel_Shared_XMLWriter $objWriter |
|||
* @param integer $curColumn |
|||
* @param integer $prevColumn |
|||
*/ |
|||
private function writeCellSpan(PHPExcel_Shared_XMLWriter $objWriter, $curColumn, $prevColumn) |
|||
{ |
|||
$diff = $curColumn - $prevColumn - 1; |
|||
if (1 === $diff) { |
|||
$objWriter->writeElement('table:table-cell'); |
|||
} elseif ($diff > 1) { |
|||
$objWriter->startElement('table:table-cell'); |
|||
$objWriter->writeAttribute('table:number-columns-repeated', $diff); |
|||
$objWriter->endElement(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,95 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument_Meta |
|||
* |
|||
* 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_OpenDocument |
|||
* @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_OpenDocument_Meta extends PHPExcel_Writer_OpenDocument_WriterPart |
|||
{ |
|||
/** |
|||
* Write meta.xml to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function write(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
if (!$pPHPExcel) { |
|||
$pPHPExcel = $this->getParentWriter()->getPHPExcel(); |
|||
} |
|||
|
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8'); |
|||
|
|||
// Meta |
|||
$objWriter->startElement('office:document-meta'); |
|||
|
|||
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
|||
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
|||
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
|||
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); |
|||
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
|||
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); |
|||
$objWriter->writeAttribute('office:version', '1.2'); |
|||
|
|||
$objWriter->startElement('office:meta'); |
|||
|
|||
$objWriter->writeElement('meta:initial-creator', $pPHPExcel->getProperties()->getCreator()); |
|||
$objWriter->writeElement('dc:creator', $pPHPExcel->getProperties()->getCreator()); |
|||
$objWriter->writeElement('meta:creation-date', date(DATE_W3C, $pPHPExcel->getProperties()->getCreated())); |
|||
$objWriter->writeElement('dc:date', date(DATE_W3C, $pPHPExcel->getProperties()->getCreated())); |
|||
$objWriter->writeElement('dc:title', $pPHPExcel->getProperties()->getTitle()); |
|||
$objWriter->writeElement('dc:description', $pPHPExcel->getProperties()->getDescription()); |
|||
$objWriter->writeElement('dc:subject', $pPHPExcel->getProperties()->getSubject()); |
|||
$keywords = explode(' ', $pPHPExcel->getProperties()->getKeywords()); |
|||
foreach ($keywords as $keyword) { |
|||
$objWriter->writeElement('meta:keyword', $keyword); |
|||
} |
|||
|
|||
//<meta:document-statistic meta:table-count="XXX" meta:cell-count="XXX" meta:object-count="XXX"/> |
|||
$objWriter->startElement('meta:user-defined'); |
|||
$objWriter->writeAttribute('meta:name', 'Company'); |
|||
$objWriter->writeRaw($pPHPExcel->getProperties()->getCompany()); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->startElement('meta:user-defined'); |
|||
$objWriter->writeAttribute('meta:name', 'category'); |
|||
$objWriter->writeRaw($pPHPExcel->getProperties()->getCategory()); |
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument_MetaInf |
|||
* |
|||
* 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_OpenDocument |
|||
* @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_OpenDocument_MetaInf extends PHPExcel_Writer_OpenDocument_WriterPart |
|||
{ |
|||
/** |
|||
* Write META-INF/manifest.xml to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeManifest(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
if (!$pPHPExcel) { |
|||
$pPHPExcel = $this->getParentWriter()->getPHPExcel(); |
|||
} |
|||
|
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8'); |
|||
|
|||
// Manifest |
|||
$objWriter->startElement('manifest:manifest'); |
|||
$objWriter->writeAttribute('xmlns:manifest', 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'); |
|||
$objWriter->writeAttribute('manifest:version', '1.2'); |
|||
|
|||
$objWriter->startElement('manifest:file-entry'); |
|||
$objWriter->writeAttribute('manifest:full-path', '/'); |
|||
$objWriter->writeAttribute('manifest:version', '1.2'); |
|||
$objWriter->writeAttribute('manifest:media-type', 'application/vnd.oasis.opendocument.spreadsheet'); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('manifest:file-entry'); |
|||
$objWriter->writeAttribute('manifest:full-path', 'meta.xml'); |
|||
$objWriter->writeAttribute('manifest:media-type', 'text/xml'); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('manifest:file-entry'); |
|||
$objWriter->writeAttribute('manifest:full-path', 'settings.xml'); |
|||
$objWriter->writeAttribute('manifest:media-type', 'text/xml'); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('manifest:file-entry'); |
|||
$objWriter->writeAttribute('manifest:full-path', 'content.xml'); |
|||
$objWriter->writeAttribute('manifest:media-type', 'text/xml'); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('manifest:file-entry'); |
|||
$objWriter->writeAttribute('manifest:full-path', 'Thumbnails/thumbnail.png'); |
|||
$objWriter->writeAttribute('manifest:media-type', 'image/png'); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('manifest:file-entry'); |
|||
$objWriter->writeAttribute('manifest:full-path', 'styles.xml'); |
|||
$objWriter->writeAttribute('manifest:media-type', 'text/xml'); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel |
|||
* |
|||
* PHPExcel_Writer_OpenDocument_Mimetype |
|||
* |
|||
* 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_OpenDocument |
|||
* @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_OpenDocument_Mimetype extends PHPExcel_Writer_OpenDocument_WriterPart |
|||
{ |
|||
/** |
|||
* Write mimetype to plain text format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function write(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
return 'application/vnd.oasis.opendocument.spreadsheet'; |
|||
} |
|||
} |
|||
@ -0,0 +1,76 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument_Settings |
|||
* |
|||
* 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_OpenDocument |
|||
* @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_OpenDocument_Settings extends PHPExcel_Writer_OpenDocument_WriterPart |
|||
{ |
|||
/** |
|||
* Write settings.xml to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function write(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
if (!$pPHPExcel) { |
|||
$pPHPExcel = $this->getParentWriter()->getPHPExcel(); |
|||
} |
|||
|
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8'); |
|||
|
|||
// Settings |
|||
$objWriter->startElement('office:document-settings'); |
|||
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
|||
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
|||
$objWriter->writeAttribute('xmlns:config', 'urn:oasis:names:tc:opendocument:xmlns:config:1.0'); |
|||
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
|||
$objWriter->writeAttribute('office:version', '1.2'); |
|||
|
|||
$objWriter->startElement('office:settings'); |
|||
$objWriter->startElement('config:config-item-set'); |
|||
$objWriter->writeAttribute('config:name', 'ooo:view-settings'); |
|||
$objWriter->startElement('config:config-item-map-indexed'); |
|||
$objWriter->writeAttribute('config:name', 'Views'); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
$objWriter->startElement('config:config-item-set'); |
|||
$objWriter->writeAttribute('config:name', 'ooo:configuration-settings'); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
} |
|||
@ -0,0 +1,92 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument_Styles |
|||
* |
|||
* 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_OpenDocument |
|||
* @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_OpenDocument_Styles extends PHPExcel_Writer_OpenDocument_WriterPart |
|||
{ |
|||
/** |
|||
* Write styles.xml to XML format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function write(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
if (!$pPHPExcel) { |
|||
$pPHPExcel = $this->getParentWriter()->getPHPExcel(); |
|||
} |
|||
|
|||
$objWriter = null; |
|||
if ($this->getParentWriter()->getUseDiskCaching()) { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory()); |
|||
} else { |
|||
$objWriter = new PHPExcel_Shared_XMLWriter(PHPExcel_Shared_XMLWriter::STORAGE_MEMORY); |
|||
} |
|||
|
|||
// XML header |
|||
$objWriter->startDocument('1.0', 'UTF-8'); |
|||
|
|||
// Content |
|||
$objWriter->startElement('office:document-styles'); |
|||
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
|||
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); |
|||
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); |
|||
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); |
|||
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); |
|||
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); |
|||
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
|||
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
|||
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); |
|||
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); |
|||
$objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); |
|||
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); |
|||
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); |
|||
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); |
|||
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); |
|||
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); |
|||
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); |
|||
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
|||
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); |
|||
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); |
|||
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); |
|||
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); |
|||
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); |
|||
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml'); |
|||
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#'); |
|||
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table'); |
|||
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/'); |
|||
$objWriter->writeAttribute('office:version', '1.2'); |
|||
|
|||
$objWriter->writeElement('office:font-face-decls'); |
|||
$objWriter->writeElement('office:styles'); |
|||
$objWriter->writeElement('office:automatic-styles'); |
|||
$objWriter->writeElement('office:master-styles'); |
|||
$objWriter->endElement(); |
|||
|
|||
return $objWriter->getData(); |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument_Thumbnails |
|||
* |
|||
* 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_OpenDocument |
|||
* @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_OpenDocument_Thumbnails extends PHPExcel_Writer_OpenDocument_WriterPart |
|||
{ |
|||
/** |
|||
* Write Thumbnails/thumbnail.png to PNG format |
|||
* |
|||
* @param PHPExcel $pPHPExcel |
|||
* @return string XML Output |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function writeThumbnail(PHPExcel $pPHPExcel = null) |
|||
{ |
|||
return ''; |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_OpenDocument_WriterPart |
|||
* |
|||
* 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_OpenDocument |
|||
* @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## |
|||
*/ |
|||
abstract class PHPExcel_Writer_OpenDocument_WriterPart extends PHPExcel_Writer_Excel2007_WriterPart |
|||
{ |
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_PDF |
|||
* |
|||
* 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_PDF |
|||
* @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_PDF implements PHPExcel_Writer_IWriter |
|||
{ |
|||
|
|||
/** |
|||
* The wrapper for the requested PDF rendering engine |
|||
* |
|||
* @var PHPExcel_Writer_PDF_Core |
|||
*/ |
|||
private $renderer = null; |
|||
|
|||
/** |
|||
* Instantiate a new renderer of the configured type within this container class |
|||
* |
|||
* @param PHPExcel $phpExcel PHPExcel object |
|||
* @throws PHPExcel_Writer_Exception when PDF library is not configured |
|||
*/ |
|||
public function __construct(PHPExcel $phpExcel) |
|||
{ |
|||
$pdfLibraryName = PHPExcel_Settings::getPdfRendererName(); |
|||
if (is_null($pdfLibraryName)) { |
|||
throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined."); |
|||
} |
|||
|
|||
$pdfLibraryPath = PHPExcel_Settings::getPdfRendererPath(); |
|||
if (is_null($pdfLibraryName)) { |
|||
throw new PHPExcel_Writer_Exception("PDF Rendering library path has not been defined."); |
|||
} |
|||
$includePath = str_replace('\\', '/', get_include_path()); |
|||
$rendererPath = str_replace('\\', '/', $pdfLibraryPath); |
|||
if (strpos($rendererPath, $includePath) === false) { |
|||
set_include_path(get_include_path() . PATH_SEPARATOR . $pdfLibraryPath); |
|||
} |
|||
|
|||
$rendererName = 'PHPExcel_Writer_PDF_' . $pdfLibraryName; |
|||
$this->renderer = new $rendererName($phpExcel); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Magic method to handle direct calls to the configured PDF renderer wrapper class. |
|||
* |
|||
* @param string $name Renderer library method name |
|||
* @param mixed[] $arguments Array of arguments to pass to the renderer method |
|||
* @return mixed Returned data from the PDF renderer wrapper method |
|||
*/ |
|||
public function __call($name, $arguments) |
|||
{ |
|||
if ($this->renderer === null) { |
|||
throw new PHPExcel_Writer_Exception("PDF Rendering library has not been defined."); |
|||
} |
|||
|
|||
return call_user_func_array(array($this->renderer, $name), $arguments); |
|||
} |
|||
|
|||
/** |
|||
* {@inheritdoc} |
|||
*/ |
|||
public function save($pFilename = null) |
|||
{ |
|||
$this->renderer->save($pFilename); |
|||
} |
|||
} |
|||
@ -0,0 +1,355 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* PHPExcel_Writer_PDF_Core |
|||
* |
|||
* 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_PDF |
|||
* @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## |
|||
*/ |
|||
abstract class PHPExcel_Writer_PDF_Core extends PHPExcel_Writer_HTML |
|||
{ |
|||
/** |
|||
* Temporary storage directory |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $tempDir = ''; |
|||
|
|||
/** |
|||
* Font |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $font = 'freesans'; |
|||
|
|||
/** |
|||
* Orientation (Over-ride) |
|||
* |
|||
* @var string |
|||
*/ |
|||
protected $orientation; |
|||
|
|||
/** |
|||
* Paper size (Over-ride) |
|||
* |
|||
* @var int |
|||
*/ |
|||
protected $paperSize; |
|||
|
|||
|
|||
/** |
|||
* Temporary storage for Save Array Return type |
|||
* |
|||
* @var string |
|||
*/ |
|||
private $saveArrayReturnType; |
|||
|
|||
/** |
|||
* Paper Sizes xRef List |
|||
* |
|||
* @var array |
|||
*/ |
|||
protected static $paperSizes = array( |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER |
|||
=> 'LETTER', // (8.5 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_SMALL |
|||
=> 'LETTER', // (8.5 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_TABLOID |
|||
=> array(792.00, 1224.00), // (11 in. by 17 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEDGER |
|||
=> array(1224.00, 792.00), // (17 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL |
|||
=> 'LEGAL', // (8.5 in. by 14 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STATEMENT |
|||
=> array(396.00, 612.00), // (5.5 in. by 8.5 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_EXECUTIVE |
|||
=> 'EXECUTIVE', // (7.25 in. by 10.5 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3 |
|||
=> 'A3', // (297 mm by 420 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4 |
|||
=> 'A4', // (210 mm by 297 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_SMALL |
|||
=> 'A4', // (210 mm by 297 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5 |
|||
=> 'A5', // (148 mm by 210 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B4 |
|||
=> 'B4', // (250 mm by 353 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B5 |
|||
=> 'B5', // (176 mm by 250 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_FOLIO |
|||
=> 'FOLIO', // (8.5 in. by 13 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_QUARTO |
|||
=> array(609.45, 779.53), // (215 mm by 275 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_1 |
|||
=> array(720.00, 1008.00), // (10 in. by 14 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_2 |
|||
=> array(792.00, 1224.00), // (11 in. by 17 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NOTE |
|||
=> 'LETTER', // (8.5 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO9_ENVELOPE |
|||
=> array(279.00, 639.00), // (3.875 in. by 8.875 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO10_ENVELOPE |
|||
=> array(297.00, 684.00), // (4.125 in. by 9.5 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO11_ENVELOPE |
|||
=> array(324.00, 747.00), // (4.5 in. by 10.375 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO12_ENVELOPE |
|||
=> array(342.00, 792.00), // (4.75 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_NO14_ENVELOPE |
|||
=> array(360.00, 828.00), // (5 in. by 11.5 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C |
|||
=> array(1224.00, 1584.00), // (17 in. by 22 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_D |
|||
=> array(1584.00, 2448.00), // (22 in. by 34 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_E |
|||
=> array(2448.00, 3168.00), // (34 in. by 44 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_DL_ENVELOPE |
|||
=> array(311.81, 623.62), // (110 mm by 220 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C5_ENVELOPE |
|||
=> 'C5', // (162 mm by 229 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C3_ENVELOPE |
|||
=> 'C3', // (324 mm by 458 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C4_ENVELOPE |
|||
=> 'C4', // (229 mm by 324 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C6_ENVELOPE |
|||
=> 'C6', // (114 mm by 162 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_C65_ENVELOPE |
|||
=> array(323.15, 649.13), // (114 mm by 229 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B4_ENVELOPE |
|||
=> 'B4', // (250 mm by 353 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B5_ENVELOPE |
|||
=> 'B5', // (176 mm by 250 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_B6_ENVELOPE |
|||
=> array(498.90, 354.33), // (176 mm by 125 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ITALY_ENVELOPE |
|||
=> array(311.81, 651.97), // (110 mm by 230 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_MONARCH_ENVELOPE |
|||
=> array(279.00, 540.00), // (3.875 in. by 7.5 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_6_3_4_ENVELOPE |
|||
=> array(261.00, 468.00), // (3.625 in. by 6.5 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_US_STANDARD_FANFOLD |
|||
=> array(1071.00, 792.00), // (14.875 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_GERMAN_STANDARD_FANFOLD |
|||
=> array(612.00, 864.00), // (8.5 in. by 12 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_GERMAN_LEGAL_FANFOLD |
|||
=> 'FOLIO', // (8.5 in. by 13 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ISO_B4 |
|||
=> 'B4', // (250 mm by 353 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_JAPANESE_DOUBLE_POSTCARD |
|||
=> array(566.93, 419.53), // (200 mm by 148 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_1 |
|||
=> array(648.00, 792.00), // (9 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_2 |
|||
=> array(720.00, 792.00), // (10 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_STANDARD_PAPER_3 |
|||
=> array(1080.00, 792.00), // (15 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_INVITE_ENVELOPE |
|||
=> array(623.62, 623.62), // (220 mm by 220 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_EXTRA_PAPER |
|||
=> array(667.80, 864.00), // (9.275 in. by 12 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LEGAL_EXTRA_PAPER |
|||
=> array(667.80, 1080.00), // (9.275 in. by 15 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_TABLOID_EXTRA_PAPER |
|||
=> array(841.68, 1296.00), // (11.69 in. by 18 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_EXTRA_PAPER |
|||
=> array(668.98, 912.76), // (236 mm by 322 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_TRANSVERSE_PAPER |
|||
=> array(595.80, 792.00), // (8.275 in. by 11 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_TRANSVERSE_PAPER |
|||
=> 'A4', // (210 mm by 297 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_EXTRA_TRANSVERSE_PAPER |
|||
=> array(667.80, 864.00), // (9.275 in. by 12 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_SUPERA_SUPERA_A4_PAPER |
|||
=> array(643.46, 1009.13), // (227 mm by 356 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_SUPERB_SUPERB_A3_PAPER |
|||
=> array(864.57, 1380.47), // (305 mm by 487 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER_PLUS_PAPER |
|||
=> array(612.00, 913.68), // (8.5 in. by 12.69 in.) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4_PLUS_PAPER |
|||
=> array(595.28, 935.43), // (210 mm by 330 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5_TRANSVERSE_PAPER |
|||
=> 'A5', // (148 mm by 210 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_JIS_B5_TRANSVERSE_PAPER |
|||
=> array(515.91, 728.50), // (182 mm by 257 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_EXTRA_PAPER |
|||
=> array(912.76, 1261.42), // (322 mm by 445 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A5_EXTRA_PAPER |
|||
=> array(493.23, 666.14), // (174 mm by 235 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_ISO_B5_EXTRA_PAPER |
|||
=> array(569.76, 782.36), // (201 mm by 276 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A2_PAPER |
|||
=> 'A2', // (420 mm by 594 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_TRANSVERSE_PAPER |
|||
=> 'A3', // (297 mm by 420 mm) |
|||
PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3_EXTRA_TRANSVERSE_PAPER |
|||
=> array(912.76, 1261.42) // (322 mm by 445 mm) |
|||
); |
|||
|
|||
/** |
|||
* Create a new PHPExcel_Writer_PDF |
|||
* |
|||
* @param PHPExcel $phpExcel PHPExcel object |
|||
*/ |
|||
public function __construct(PHPExcel $phpExcel) |
|||
{ |
|||
parent::__construct($phpExcel); |
|||
$this->setUseInlineCss(true); |
|||
$this->tempDir = PHPExcel_Shared_File::sys_get_temp_dir(); |
|||
} |
|||
|
|||
/** |
|||
* Get Font |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getFont() |
|||
{ |
|||
return $this->font; |
|||
} |
|||
|
|||
/** |
|||
* Set font. Examples: |
|||
* 'arialunicid0-chinese-simplified' |
|||
* 'arialunicid0-chinese-traditional' |
|||
* 'arialunicid0-korean' |
|||
* 'arialunicid0-japanese' |
|||
* |
|||
* @param string $fontName |
|||
*/ |
|||
public function setFont($fontName) |
|||
{ |
|||
$this->font = $fontName; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Paper Size |
|||
* |
|||
* @return int |
|||
*/ |
|||
public function getPaperSize() |
|||
{ |
|||
return $this->paperSize; |
|||
} |
|||
|
|||
/** |
|||
* Set Paper Size |
|||
* |
|||
* @param string $pValue Paper size |
|||
* @return PHPExcel_Writer_PDF |
|||
*/ |
|||
public function setPaperSize($pValue = PHPExcel_Worksheet_PageSetup::PAPERSIZE_LETTER) |
|||
{ |
|||
$this->paperSize = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get Orientation |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getOrientation() |
|||
{ |
|||
return $this->orientation; |
|||
} |
|||
|
|||
/** |
|||
* Set Orientation |
|||
* |
|||
* @param string $pValue Page orientation |
|||
* @return PHPExcel_Writer_PDF |
|||
*/ |
|||
public function setOrientation($pValue = PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) |
|||
{ |
|||
$this->orientation = $pValue; |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Get temporary storage directory |
|||
* |
|||
* @return string |
|||
*/ |
|||
public function getTempDir() |
|||
{ |
|||
return $this->tempDir; |
|||
} |
|||
|
|||
/** |
|||
* Set temporary storage directory |
|||
* |
|||
* @param string $pValue Temporary storage directory |
|||
* @throws PHPExcel_Writer_Exception when directory does not exist |
|||
* @return PHPExcel_Writer_PDF |
|||
*/ |
|||
public function setTempDir($pValue = '') |
|||
{ |
|||
if (is_dir($pValue)) { |
|||
$this->tempDir = $pValue; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception("Directory does not exist: $pValue"); |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
/** |
|||
* Save PHPExcel to PDF file, pre-save |
|||
* |
|||
* @param string $pFilename Name of the file to save as |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
protected function prepareForSave($pFilename = null) |
|||
{ |
|||
// garbage collect |
|||
$this->phpExcel->garbageCollect(); |
|||
|
|||
$this->saveArrayReturnType = PHPExcel_Calculation::getArrayReturnType(); |
|||
PHPExcel_Calculation::setArrayReturnType(PHPExcel_Calculation::RETURN_ARRAY_AS_VALUE); |
|||
|
|||
// Open file |
|||
$fileHandle = fopen($pFilename, 'w'); |
|||
if ($fileHandle === false) { |
|||
throw new PHPExcel_Writer_Exception("Could not open file $pFilename for writing."); |
|||
} |
|||
|
|||
// Set PDF |
|||
$this->isPdf = true; |
|||
// Build CSS |
|||
$this->buildCSS(true); |
|||
|
|||
return $fileHandle; |
|||
} |
|||
|
|||
/** |
|||
* Save PHPExcel to PDF file, post-save |
|||
* |
|||
* @param resource $fileHandle |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
protected function restoreStateAfterSave($fileHandle) |
|||
{ |
|||
// Close file |
|||
fclose($fileHandle); |
|||
|
|||
PHPExcel_Calculation::setArrayReturnType($this->saveArrayReturnType); |
|||
} |
|||
} |
|||
@ -0,0 +1,108 @@ |
|||
<?php |
|||
|
|||
/** Require DomPDF library */ |
|||
$pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/dompdf_config.inc.php'; |
|||
if (file_exists($pdfRendererClassFile)) { |
|||
require_once $pdfRendererClassFile; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library'); |
|||
} |
|||
|
|||
/** |
|||
* PHPExcel_Writer_PDF_DomPDF |
|||
* |
|||
* 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_PDF |
|||
* @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_PDF_DomPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* Create a new PHPExcel_Writer_PDF |
|||
* |
|||
* @param PHPExcel $phpExcel PHPExcel object |
|||
*/ |
|||
public function __construct(PHPExcel $phpExcel) |
|||
{ |
|||
parent::__construct($phpExcel); |
|||
} |
|||
|
|||
/** |
|||
* Save PHPExcel to file |
|||
* |
|||
* @param string $pFilename Name of the file to save as |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function save($pFilename = null) |
|||
{ |
|||
$fileHandle = parent::prepareForSave($pFilename); |
|||
|
|||
// Default PDF paper size |
|||
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) |
|||
|
|||
// Check for paper size and page orientation |
|||
if (is_null($this->getSheetIndex())) { |
|||
$orientation = ($this->phpExcel->getSheet(0)->getPageSetup()->getOrientation() |
|||
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
|||
$printPaperSize = $this->phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); |
|||
$printMargins = $this->phpExcel->getSheet(0)->getPageMargins(); |
|||
} else { |
|||
$orientation = ($this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() |
|||
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
|||
$printPaperSize = $this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); |
|||
$printMargins = $this->phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); |
|||
} |
|||
|
|||
$orientation = ($orientation == 'L') ? 'landscape' : 'portrait'; |
|||
|
|||
// Override Page Orientation |
|||
if (!is_null($this->getOrientation())) { |
|||
$orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) |
|||
? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT |
|||
: $this->getOrientation(); |
|||
} |
|||
// Override Paper Size |
|||
if (!is_null($this->getPaperSize())) { |
|||
$printPaperSize = $this->getPaperSize(); |
|||
} |
|||
|
|||
if (isset(self::$paperSizes[$printPaperSize])) { |
|||
$paperSize = self::$paperSizes[$printPaperSize]; |
|||
} |
|||
|
|||
|
|||
// Create PDF |
|||
$pdf = new DOMPDF(); |
|||
$pdf->set_paper(strtolower($paperSize), $orientation); |
|||
|
|||
$pdf->load_html( |
|||
$this->generateHTMLHeader(false) . |
|||
$this->generateSheetData() . |
|||
$this->generateHTMLFooter() |
|||
); |
|||
$pdf->render(); |
|||
|
|||
// Write to file |
|||
fwrite($fileHandle, $pdf->output()); |
|||
|
|||
parent::restoreStateAfterSave($fileHandle); |
|||
} |
|||
} |
|||
@ -0,0 +1,118 @@ |
|||
<?php |
|||
|
|||
/** Require mPDF library */ |
|||
$pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/mpdf.php'; |
|||
if (file_exists($pdfRendererClassFile)) { |
|||
require_once $pdfRendererClassFile; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library'); |
|||
} |
|||
|
|||
/** |
|||
* PHPExcel_Writer_PDF_mPDF |
|||
* |
|||
* 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_PDF |
|||
* @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_PDF_mPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* Create a new PHPExcel_Writer_PDF |
|||
* |
|||
* @param PHPExcel $phpExcel PHPExcel object |
|||
*/ |
|||
public function __construct(PHPExcel $phpExcel) |
|||
{ |
|||
parent::__construct($phpExcel); |
|||
} |
|||
|
|||
/** |
|||
* Save PHPExcel to file |
|||
* |
|||
* @param string $pFilename Name of the file to save as |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function save($pFilename = null) |
|||
{ |
|||
$fileHandle = parent::prepareForSave($pFilename); |
|||
|
|||
// Default PDF paper size |
|||
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) |
|||
|
|||
// Check for paper size and page orientation |
|||
if (is_null($this->getSheetIndex())) { |
|||
$orientation = ($this->phpExcel->getSheet(0)->getPageSetup()->getOrientation() |
|||
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
|||
$printPaperSize = $this->phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); |
|||
$printMargins = $this->phpExcel->getSheet(0)->getPageMargins(); |
|||
} else { |
|||
$orientation = ($this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() |
|||
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
|||
$printPaperSize = $this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); |
|||
$printMargins = $this->phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); |
|||
} |
|||
$this->setOrientation($orientation); |
|||
|
|||
// Override Page Orientation |
|||
if (!is_null($this->getOrientation())) { |
|||
$orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_DEFAULT) |
|||
? PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT |
|||
: $this->getOrientation(); |
|||
} |
|||
$orientation = strtoupper($orientation); |
|||
|
|||
// Override Paper Size |
|||
if (!is_null($this->getPaperSize())) { |
|||
$printPaperSize = $this->getPaperSize(); |
|||
} |
|||
|
|||
if (isset(self::$paperSizes[$printPaperSize])) { |
|||
$paperSize = self::$paperSizes[$printPaperSize]; |
|||
} |
|||
|
|||
|
|||
// Create PDF |
|||
$pdf = new mpdf(); |
|||
$ortmp = $orientation; |
|||
$pdf->_setPageSize(strtoupper($paperSize), $ortmp); |
|||
$pdf->DefOrientation = $orientation; |
|||
$pdf->AddPage($orientation); |
|||
|
|||
// Document info |
|||
$pdf->SetTitle($this->phpExcel->getProperties()->getTitle()); |
|||
$pdf->SetAuthor($this->phpExcel->getProperties()->getCreator()); |
|||
$pdf->SetSubject($this->phpExcel->getProperties()->getSubject()); |
|||
$pdf->SetKeywords($this->phpExcel->getProperties()->getKeywords()); |
|||
$pdf->SetCreator($this->phpExcel->getProperties()->getCreator()); |
|||
|
|||
$pdf->WriteHTML( |
|||
$this->generateHTMLHeader(false) . |
|||
$this->generateSheetData() . |
|||
$this->generateHTMLFooter() |
|||
); |
|||
|
|||
// Write to file |
|||
fwrite($fileHandle, $pdf->Output('', 'S')); |
|||
|
|||
parent::restoreStateAfterSave($fileHandle); |
|||
} |
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
<?php |
|||
|
|||
/** Require tcPDF library */ |
|||
$pdfRendererClassFile = PHPExcel_Settings::getPdfRendererPath() . '/tcpdf.php'; |
|||
if (file_exists($pdfRendererClassFile)) { |
|||
$k_path_url = PHPExcel_Settings::getPdfRendererPath(); |
|||
require_once $pdfRendererClassFile; |
|||
} else { |
|||
throw new PHPExcel_Writer_Exception('Unable to load PDF Rendering library'); |
|||
} |
|||
|
|||
/** |
|||
* PHPExcel_Writer_PDF_tcPDF |
|||
* |
|||
* 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_PDF |
|||
* @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_PDF_tcPDF extends PHPExcel_Writer_PDF_Core implements PHPExcel_Writer_IWriter |
|||
{ |
|||
/** |
|||
* Create a new PHPExcel_Writer_PDF |
|||
* |
|||
* @param PHPExcel $phpExcel PHPExcel object |
|||
*/ |
|||
public function __construct(PHPExcel $phpExcel) |
|||
{ |
|||
parent::__construct($phpExcel); |
|||
} |
|||
|
|||
/** |
|||
* Save PHPExcel to file |
|||
* |
|||
* @param string $pFilename Name of the file to save as |
|||
* @throws PHPExcel_Writer_Exception |
|||
*/ |
|||
public function save($pFilename = null) |
|||
{ |
|||
$fileHandle = parent::prepareForSave($pFilename); |
|||
|
|||
// Default PDF paper size |
|||
$paperSize = 'LETTER'; // Letter (8.5 in. by 11 in.) |
|||
|
|||
// Check for paper size and page orientation |
|||
if (is_null($this->getSheetIndex())) { |
|||
$orientation = ($this->phpExcel->getSheet(0)->getPageSetup()->getOrientation() |
|||
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
|||
$printPaperSize = $this->phpExcel->getSheet(0)->getPageSetup()->getPaperSize(); |
|||
$printMargins = $this->phpExcel->getSheet(0)->getPageMargins(); |
|||
} else { |
|||
$orientation = ($this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getOrientation() |
|||
== PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ? 'L' : 'P'; |
|||
$printPaperSize = $this->phpExcel->getSheet($this->getSheetIndex())->getPageSetup()->getPaperSize(); |
|||
$printMargins = $this->phpExcel->getSheet($this->getSheetIndex())->getPageMargins(); |
|||
} |
|||
|
|||
// Override Page Orientation |
|||
if (!is_null($this->getOrientation())) { |
|||
$orientation = ($this->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) |
|||
? 'L' |
|||
: 'P'; |
|||
} |
|||
// Override Paper Size |
|||
if (!is_null($this->getPaperSize())) { |
|||
$printPaperSize = $this->getPaperSize(); |
|||
} |
|||
|
|||
if (isset(self::$paperSizes[$printPaperSize])) { |
|||
$paperSize = self::$paperSizes[$printPaperSize]; |
|||
} |
|||
|
|||
|
|||
// Create PDF |
|||
$pdf = new TCPDF($orientation, 'pt', $paperSize); |
|||
$pdf->setFontSubsetting(false); |
|||
// Set margins, converting inches to points (using 72 dpi) |
|||
$pdf->SetMargins($printMargins->getLeft() * 72, $printMargins->getTop() * 72, $printMargins->getRight() * 72); |
|||
$pdf->SetAutoPageBreak(true, $printMargins->getBottom() * 72); |
|||
|
|||
$pdf->setPrintHeader(false); |
|||
$pdf->setPrintFooter(false); |
|||
|
|||
$pdf->AddPage(); |
|||
|
|||
// Set the appropriate font |
|||
$pdf->SetFont($this->getFont()); |
|||
$pdf->writeHTML( |
|||
$this->generateHTMLHeader(false) . |
|||
$this->generateSheetData() . |
|||
$this->generateHTMLFooter() |
|||
); |
|||
|
|||
// Document info |
|||
$pdf->SetTitle($this->phpExcel->getProperties()->getTitle()); |
|||
$pdf->SetAuthor($this->phpExcel->getProperties()->getCreator()); |
|||
$pdf->SetSubject($this->phpExcel->getProperties()->getSubject()); |
|||
$pdf->SetKeywords($this->phpExcel->getProperties()->getKeywords()); |
|||
$pdf->SetCreator($this->phpExcel->getProperties()->getCreator()); |
|||
|
|||
// Write to file |
|||
fwrite($fileHandle, $pdf->output($pFilename, 'S')); |
|||
|
|||
parent::restoreStateAfterSave($fileHandle); |
|||
} |
|||
} |
|||
@ -0,0 +1,371 @@ |
|||
<?php |
|||
//------------------------ |
|||
// 七牛上传和token生成 |
|||
//------------------------- |
|||
|
|||
class Qiniu |
|||
{ |
|||
/** |
|||
* 默认上传配置 |
|||
*/ |
|||
private $config = [ |
|||
'mimes' => [], // 允许上传的文件 mime 类型 |
|||
'max_size' => 0, // 上传的文件大小限制 (0-不做限制) |
|||
'exts' => [], // 允许上传的文件后缀 |
|||
'url' => "http://upload.qiniu.com/", // 上传的地址 |
|||
'param' => [], // 参数 |
|||
]; |
|||
|
|||
private $error = ''; //上传错误信息 |
|||
//单例 |
|||
private static $instance; |
|||
|
|||
public static function instance($config = []) |
|||
{ |
|||
if (self::$instance === null) { |
|||
self::$instance = new static($config); |
|||
} |
|||
return self::$instance; |
|||
} |
|||
|
|||
/** |
|||
* 构造方法,用于构造上传实例 |
|||
* @param array $config 配置 |
|||
*/ |
|||
public function __construct($config = []) |
|||
{ |
|||
$this->config($config); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 设置 |
|||
* @param array $config |
|||
* @return $this |
|||
*/ |
|||
public function config($config = []) |
|||
{ |
|||
/* 获取配置 */ |
|||
if(config('upload_validate.size')) $conf['max_size']=config('upload_validate.size'); |
|||
if(config('upload_validate.ext')) $conf['exts']=config('upload_validate.ext'); |
|||
$this->config = array_merge($this->config, $conf); |
|||
$this->config = array_merge($this->config, $config); |
|||
|
|||
/* 调整配置,把字符串配置参数转换为数组 */ |
|||
if (!empty($this->config['mimes'])) { |
|||
if (is_string($this->config['mimes'])) { |
|||
$this->config['mimes'] = explode(',', $this->config['mimes']); |
|||
} |
|||
$this->config['mimes'] = array_map('strtolower', $this->config['mimes']); |
|||
} |
|||
if (!empty($this->config['exts'])) { |
|||
if (is_string($this->config['mimes'])) { |
|||
$this->config['exts'] = explode(',', $this->config['mimes']); |
|||
} |
|||
$this->config['exts'] = array_map('strtolower', $this->config['mimes']); |
|||
} |
|||
return $this; |
|||
} |
|||
|
|||
private static $instance_manager; //\Qiniu\Storage\UploadManager的单例 |
|||
|
|||
/** |
|||
* 单例化\Qiniu\Storage\UploadManager |
|||
* @return \Qiniu\Storage\UploadManager |
|||
*/ |
|||
public static function manager() |
|||
{ |
|||
if (self::$instance_manager === null) { |
|||
self::$instance_manager = new \Qiniu\Storage\UploadManager(); |
|||
} |
|||
return self::$instance_manager; |
|||
} |
|||
|
|||
/** |
|||
* 生成token |
|||
* @param int $expires |
|||
* @param null $bucket |
|||
* @param null $key |
|||
* @param null $policy |
|||
* @param bool $strictPolicy |
|||
* @return string |
|||
*/ |
|||
public static function token($expires = 3600, $bucket = null, $key = null, $policy = null, $strictPolicy = true) |
|||
{ |
|||
if (empty($bucket)) $bucket = config("storage.bucket"); |
|||
// 初始化签权对象 |
|||
$auth = new \Qiniu\Auth(config("storage.accesskey"), config("storage.secretkey")); |
|||
$token = $auth->uploadToken($bucket, $key, $expires, $policy, $strictPolicy); |
|||
return $token; |
|||
} |
|||
|
|||
/** |
|||
* 上传单个文件,文件直传 |
|||
* @param $file_path |
|||
* @param string $prefix 文件名前缀,可以模拟目录 |
|||
* @param null $name |
|||
* @param string $ext 后缀 |
|||
* @param null $token |
|||
* @param null $params |
|||
* @param string $mime |
|||
* @param bool $checkCrc |
|||
* @return bool |
|||
*/ |
|||
public function uploadOne($file_path, $prefix = "", $name = null,$ext="", $token = null, $params = null, $mime = 'application/octet-stream', $checkCrc = false) |
|||
{ |
|||
if(empty($name)){ |
|||
if(empty($ext)) $ext=pathinfo($file_path, PATHINFO_EXTENSION); |
|||
}else{ |
|||
if(empty($ext)) $ext=pathinfo($name, PATHINFO_EXTENSION); |
|||
} |
|||
//$ext不为空,且未指定$prefix时,根据$ext判断 |
|||
if($ext && empty($prefix)){ |
|||
if(in_array(strtolower($ext),array('jpg', 'gif', 'png', 'jpeg','bmp'))){ |
|||
$prefix='image/'; |
|||
}elseif(in_array(strtolower($ext),array('mp4', 'avi', 'wmv','rm','rmvb','mkv'))){ |
|||
$prefix='video/'; |
|||
}else{ |
|||
$prefix='file/'; |
|||
} |
|||
if(!empty($name)) $name=$prefix.$name; |
|||
} |
|||
if (empty($name)) $name = $prefix . base_convert(time() * 1000, 10, 36) . "_" . base_convert(microtime(), 10, 36) . uniqid() .($ext?'.'.$ext:''); |
|||
if (empty($token)) $token = self::token(); |
|||
if (empty($mime)) $mime = 'application/octet-stream'; |
|||
$this->error = null; |
|||
|
|||
list($ret, $error) = self::manager()->putFile($token, $name, $file_path, $params, $mime, $checkCrc); |
|||
|
|||
if ($error !== null) { |
|||
$this->error = $error->message(); |
|||
return false; |
|||
} else { |
|||
return $ret; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 上传文件,包含$_FILES的上传 |
|||
* 返回数据包含上传信息部分如果是字符串表示错误信息,如果是数组表示成功 |
|||
* @param string $prefix |
|||
* @param null $params |
|||
* @param bool $checkCrc |
|||
* @return array|bool |
|||
*/ |
|||
public function upload($prefix = "", $params = null, $checkCrc = false) |
|||
{ |
|||
if (!isset($_FILES) || empty($_FILES)) { |
|||
$this->error = '没有上传的文件!'; |
|||
return false; |
|||
} |
|||
|
|||
// 逐个检测并上传文件 |
|||
$info = []; //文件上传信息数组 |
|||
foreach ($_FILES as $key => $files) { |
|||
foreach ($this->reArrayFiles($files) as $file) { |
|||
//文件上传检测 |
|||
if (!$this->check($file)) { |
|||
$info[$key][] = $this->error; |
|||
continue; |
|||
} |
|||
//文件名生成 |
|||
if (isset($file['name'])) { |
|||
$name = $prefix . base_convert(time() * 1000, 10, 36) . "_" . base_convert(microtime(), 10, 36) . uniqid() . "." . pathinfo($file['name'], PATHINFO_EXTENSION); |
|||
} else { |
|||
$name = $prefix . base_convert(time() * 1000, 10, 36) . "_" . base_convert(microtime(), 10, 36) . uniqid(); |
|||
} |
|||
|
|||
//文件上传 |
|||
if ($ret = $this->uploadOne($file['tmp_name'], $prefix, $name,"", null, $params, isset($file['type']) ? $file['type'] : null, $checkCrc)) { |
|||
$info[$key][] = array_merge($ret, $file); |
|||
} else { |
|||
$info[$key][] = $this->error; |
|||
} |
|||
} |
|||
} |
|||
|
|||
//简化返回数据格式 |
|||
return count($_FILES) == 1 ? end($info) : $info; |
|||
} |
|||
/** |
|||
* 抓取远程url资源 |
|||
* @param string $url 远程资源url |
|||
* @param string $prefix |
|||
* @param string $name 保存文件名 |
|||
* @param string $ext |
|||
* @param string $bucket 空间 |
|||
* @return array |
|||
*/ |
|||
public function uploadcatch($url,$prefix="",$name="",$ext="",$bucket="") |
|||
{ |
|||
if(empty($ext)) $ext=pathinfo($url, PATHINFO_EXTENSION); |
|||
//$ext不为空,且未指定$prefix时,根据$ext判断 |
|||
if($ext && empty($prefix)){ |
|||
if(in_array(strtolower($ext),array('jpg', 'gif', 'png', 'jpeg','bmp'))){ |
|||
$prefix='image/'; |
|||
}elseif(in_array(strtolower($ext),array('mp4', 'avi', 'wmv','rm','rmvb','mkv'))){ |
|||
$prefix='video/'; |
|||
}else{ |
|||
$prefix='file/'; |
|||
} |
|||
} |
|||
if (empty($name)) $name = $prefix . base_convert(time() * 1000, 10, 36) . "_" . base_convert(microtime(), 10, 36) . uniqid().($ext?'.'.$ext:''); |
|||
if (empty($bucket)) $bucket =config('storage.bucket'); |
|||
$auth = new \Qiniu\Auth(config("storage.accesskey"), config("storage.secretkey")); |
|||
$bucketMgr=new \Qiniu\Storage\BucketManager($auth); |
|||
$info=$bucketMgr->fetch($url,$bucket,$name); |
|||
return $info; |
|||
} |
|||
/** |
|||
* 列表文件 |
|||
* @param string |
|||
* @param string |
|||
* @param string |
|||
* @param int |
|||
* @return array |
|||
*/ |
|||
public function listfile($prefix='',$bucket='', $marker='', $limit=1000) |
|||
{ |
|||
if (empty($bucket)) $bucket =config('storage.bucket'); |
|||
$auth = new \Qiniu\Auth(config("storage.accesskey"), config("storage.secretkey")); |
|||
$bucketMgr=new \Qiniu\Storage\BucketManager($auth); |
|||
list($iterms, $marker, $err) = $bucketMgr->listFiles($bucket, $prefix, $marker, $limit); |
|||
if ($err !== null) { |
|||
return $err; |
|||
}else{ |
|||
return $iterms; |
|||
} |
|||
} |
|||
/** |
|||
* 对文件信息进行处理 |
|||
* @param $file_post |
|||
* @return array |
|||
*/ |
|||
private function reArrayFiles($file_post) |
|||
{ |
|||
$file_ary = []; |
|||
if (is_array($file_post['tmp_name'])) { |
|||
$file_count = count($file_post['tmp_name']); |
|||
$file_keys = array_keys($file_post); |
|||
for ($i = 0; $i < $file_count; $i++) { |
|||
foreach ($file_keys as $key) { |
|||
$file_ary[$i][$key] = $file_post[$key][$i]; |
|||
} |
|||
} |
|||
} else { |
|||
$file_ary[] = $file_post; |
|||
} |
|||
return $file_ary; |
|||
} |
|||
|
|||
/** |
|||
* 获取最后一次上传错误信息 |
|||
* @return string 错误信息 |
|||
*/ |
|||
public function getError() |
|||
{ |
|||
return $this->error; |
|||
} |
|||
|
|||
/** |
|||
* 检查上传的文件 |
|||
* @param array $file 文件信息 |
|||
* @return boolean |
|||
*/ |
|||
private function check($file) |
|||
{ |
|||
if (!isset($file['tmp_name']) || !file_exists($file['tmp_name'])) { |
|||
$this->error = '上传的文件不存在'; |
|||
return false; |
|||
} |
|||
|
|||
// 文件上传失败,捕获错误代码 |
|||
if (isset($file['error']) && $file['error']) { |
|||
$this->error($file['error']); |
|||
return false; |
|||
} |
|||
|
|||
// 检查文件大小 |
|||
if (isset($file['size']) && !$this->checkSize($file['size'])) { |
|||
$this->error = '上传文件大小不符!'; |
|||
return false; |
|||
} |
|||
|
|||
// 检查文件Mime类型 |
|||
if (isset($file['type']) && $file['type']) { |
|||
if (!$this->checkMime($file['type'])) { |
|||
$this->error = '上传文件MIME类型不允许!'; |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
// 检查文件后缀 |
|||
if (isset($file['ext']) && !$this->checkExt($file['ext'])) { |
|||
$this->error = '上传文件后缀不允许'; |
|||
return false; |
|||
} |
|||
|
|||
// 通过检测 |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* 获取错误代码信息 |
|||
* @param string $errorNo 错误号 |
|||
*/ |
|||
private function error($errorNo) |
|||
{ |
|||
switch ($errorNo) { |
|||
case 1: |
|||
$this->error = '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值!'; |
|||
break; |
|||
case 2: |
|||
$this->error = '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值!'; |
|||
break; |
|||
case 3: |
|||
$this->error = '文件只有部分被上传!'; |
|||
break; |
|||
case 4: |
|||
$this->error = '没有文件被上传!'; |
|||
break; |
|||
case 6: |
|||
$this->error = '找不到临时文件夹!'; |
|||
break; |
|||
case 7: |
|||
$this->error = '文件写入失败!'; |
|||
break; |
|||
default: |
|||
$this->error = '未知上传错误!'; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 检查文件大小是否合法 |
|||
* @param integer $size 数据 |
|||
* @return boolean |
|||
*/ |
|||
private function checkSize($size) |
|||
{ |
|||
return !($size > $this->config['max_size']) || (0 == $this->config['max_size']); |
|||
} |
|||
|
|||
/** |
|||
* 检查上传的文件MIME类型是否合法 |
|||
* @param string $mime 数据 |
|||
* @return boolean |
|||
*/ |
|||
private function checkMime($mime) |
|||
{ |
|||
return empty($this->config['mimes']) ? true : in_array(strtolower($mime), $this->config['mimes']); |
|||
} |
|||
|
|||
/** |
|||
* 检查上传的文件后缀是否合法 |
|||
* @param string $ext 后缀 |
|||
* @return boolean |
|||
*/ |
|||
private function checkExt($ext) |
|||
{ |
|||
return empty($this->config['exts']) ? true : in_array(strtolower($ext), $this->config['exts']); |
|||
} |
|||
} |
|||
@ -0,0 +1,124 @@ |
|||
<?php |
|||
//------------------------ |
|||
// 读取类文件 |
|||
//------------------------- |
|||
|
|||
class ReadClass |
|||
{ |
|||
private static $errormsg; |
|||
|
|||
/** |
|||
* 根据类名获取public方法 |
|||
* @param string $class 类名 |
|||
* @param bool $parents 是否获取父类方法,默认false |
|||
* @return array|bool |
|||
*/ |
|||
public static function method($class, $parents = false) |
|||
{ |
|||
if (!class_exists($class)) { |
|||
self::$errormsg = $class . "类不存在"; |
|||
return false; |
|||
} |
|||
|
|||
$reflection = new \ReflectionClass($class); |
|||
$class_name = $reflection->name; |
|||
$staticProperties = $reflection->getStaticProperties(); |
|||
// 黑名单方法 |
|||
$blacklist = isset($staticProperties['blacklist']) ? $staticProperties['blacklist'] : []; |
|||
$ret = []; |
|||
//遍历public方法 |
|||
foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
|||
if ($parents || (!$parents && $method->class == $class_name)) { |
|||
if (substr($method->name, 0, 2) != '__' && !in_array(strtolower($method->name), $blacklist)) { |
|||
//根据phpDoc获取方法说明 |
|||
$title = ''; |
|||
$docComment = $method->getDocComment(); |
|||
if ($docComment !== false) { |
|||
$docCommentArr = explode("\n", $docComment); |
|||
$comment = trim($docCommentArr[1]); |
|||
$title = trim(substr($comment, strpos($comment, '*') + 1)); |
|||
} |
|||
$ret[] = ['name' => $method->name, 'title' => $title]; |
|||
} |
|||
} |
|||
} |
|||
return $ret; |
|||
} |
|||
|
|||
/** |
|||
* 读取某个路径的类和方法 |
|||
* @param string $path |
|||
* @param bool $parents |
|||
* @return array|bool |
|||
*/ |
|||
public static function readFile($path, $parents = false) |
|||
{ |
|||
if (!file_exists($path)) { |
|||
self::$errormsg = $path . "文件不存在"; |
|||
return false; |
|||
} |
|||
$class = str_replace([realpath(APP_PATH), ".php", DS], [config("app_namespace"), "", "\\"], realpath($path)); |
|||
$method = self::method($class, $parents); |
|||
if ($method) { |
|||
$class_name = explode("\\", $class); |
|||
return ["class" => $class, "class_name" => end($class_name), "method" => $method]; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 读取某个文件夹里所有的类与方法 |
|||
* @param $dir |
|||
* @param array $filter |
|||
* @param bool $parents |
|||
* @return array|bool |
|||
*/ |
|||
public static function readDir($dir, $filter = [], $parents = false) |
|||
{ |
|||
if (!is_dir($dir)) { |
|||
self::$errormsg = $dir . "路径不存在"; |
|||
return false; |
|||
} |
|||
$file_list = self::listDir($dir, true); |
|||
|
|||
$ret = []; |
|||
foreach ($file_list as $file) { |
|||
$method = self::readFile($file, $parents); |
|||
if ($method && !in_array($method['class_name'], $filter)) { |
|||
$ret[$method['class_name']] = $method; |
|||
} |
|||
} |
|||
return $ret; |
|||
} |
|||
|
|||
/** |
|||
* 列出某个目录下的文件 |
|||
* @param string $dir 目录 |
|||
* @param bool $recursion 是否递归 |
|||
* @return array |
|||
*/ |
|||
public static function listDir($dir, $recursion = true) |
|||
{ |
|||
$dirInfo = []; |
|||
if (is_dir($dir)) { |
|||
foreach (glob($dir . DS . '*') as $v) { |
|||
if ($recursion && is_dir($v)) { |
|||
$dirInfo = array_merge($dirInfo, self::listDir($v)); |
|||
} else { |
|||
$dirInfo[] = $v; |
|||
} |
|||
|
|||
} |
|||
} |
|||
return $dirInfo; |
|||
} |
|||
|
|||
/** |
|||
* 读取错误信息 |
|||
* @return mixed |
|||
*/ |
|||
public static function getError() |
|||
{ |
|||
return self::$errormsg; |
|||
} |
|||
} |
|||
@ -0,0 +1,78 @@ |
|||
<?php |
|||
|
|||
class Route |
|||
{ |
|||
|
|||
public function route_rule() |
|||
{ |
|||
$routes = $this->get_route(); |
|||
if (is_array($routes)) { |
|||
foreach ($routes as $key => $route) { |
|||
\think\Route::rule($route[0], $route[1], $route[2], $route[3], $route[4]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private function get_route() |
|||
{ |
|||
$routes = \think\Cache::get('routes'); |
|||
if(empty($routes) && config('url_route_on')){ |
|||
switch (config('url_route_mode')) { |
|||
// 标准模式 |
|||
case null: |
|||
case '1': |
|||
$rules = [ |
|||
]; |
|||
foreach ($rules as $key => $rule) { |
|||
$routes[] = [$key, $rule, 'post|get', [], []]; |
|||
} |
|||
\think\Cache::set('routes', $routes); |
|||
break; |
|||
// 高级模式 |
|||
case '2': |
|||
// 内容模块 |
|||
$rules = [ |
|||
]; |
|||
if(file_exists(ROOT_PATH.'data/install.lock')){ |
|||
$data=\think\Db::name("route")->where("status=1")->order("listorder asc")->column('full_url','url'); |
|||
$data=array_merge($rules,$data); |
|||
foreach ($data as $key => $rule) { |
|||
$routes[] = [$key, $rule, 'post|get', [], []]; |
|||
} |
|||
} |
|||
\think\Cache::set('routes', $routes); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
return $routes; |
|||
} |
|||
|
|||
private function category_route($categorys, $pid = 0, $path = [], &$res) |
|||
{ |
|||
foreach ($categorys as $key => $category) { |
|||
if ($category['pid'] == $pid) { |
|||
$tpath = array_merge($path, [$category['name']]); |
|||
$this->category_route($categorys, $category['id'], $tpath, $res); |
|||
if ($tpath) { |
|||
$res[] = [implode('/', $tpath) . '$', 'index/content/index?id=' . $category['id'], 'get|post', [], []]; |
|||
$res[] = [implode('/', $tpath) . '/:id$', 'index/content/detail?category_id=' . $category['id'], 'get|post', [], []]; |
|||
$res[] = [implode('/', $tpath) . '/:filename$', 'index/content/detail?category_id=' . $category['id'], 'get|post', [], []]; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
private function single_route($single, &$routes) |
|||
{ |
|||
if ($single) { |
|||
foreach ($single as $id => $path) { |
|||
if ($path) { |
|||
$routes[] = [substr($path, 1), 'index/single/index?id=' . $id, 'get|post', [], []]; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,424 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* 通用的树型类,可以生成任何树型结构 |
|||
* author:phpcms |
|||
* edit:rainfer |
|||
*/ |
|||
class Tree |
|||
{ |
|||
|
|||
/** |
|||
* 生成树型结构所需要的2维数组 |
|||
* @var array |
|||
*/ |
|||
public $arr = array(); |
|||
|
|||
/** |
|||
* 生成树型结构所需修饰符号,可以换成图片 |
|||
* @var array |
|||
*/ |
|||
private $icon = array('│', '├', '└'); |
|||
private $nbsp = ' '; |
|||
private $str=''; |
|||
private $ret = ''; |
|||
private $config=array( |
|||
'id'=>'id', |
|||
'parentid'=>'parentid', |
|||
'name'=>'name', |
|||
'child'=>'child', |
|||
); |
|||
|
|||
/** |
|||
* 构造函数,初始化类 |
|||
* @param array 2维数组,例如: |
|||
* array( |
|||
* 1 => array('id'=>'1','parentid'=>0,'name'=>'一级栏目一'), |
|||
* 2 => array('id'=>'2','parentid'=>0,'name'=>'一级栏目二'), |
|||
* 3 => array('id'=>'3','parentid'=>1,'name'=>'二级栏目一'), |
|||
* 4 => array('id'=>'4','parentid'=>1,'name'=>'二级栏目二'), |
|||
* 5 => array('id'=>'5','parentid'=>2,'name'=>'二级栏目三'), |
|||
* 6 => array('id'=>'6','parentid'=>3,'name'=>'三级栏目一'), |
|||
* 7 => array('id'=>'7','parentid'=>3,'name'=>'三级栏目二') |
|||
* ) |
|||
* @param array $config 配置数组字段名称 |
|||
* @return boolean |
|||
*/ |
|||
public function init($arr=array(),$config=array()) |
|||
{ |
|||
$this->arr = $arr; |
|||
$this->ret = ''; |
|||
$this->str=''; |
|||
if($config) $this->config=array_merge($this->config,$config); |
|||
return is_array($arr); |
|||
} |
|||
/** |
|||
* 递归重组节点信息为多维数组 |
|||
* @param array |
|||
* @param int |
|||
* @param string |
|||
* @param string |
|||
* @param string |
|||
* @return array |
|||
*/ |
|||
public function get_arraylist(&$node, $pid = 0) |
|||
{ |
|||
$arr = array(); |
|||
foreach ($node as $v) { |
|||
if ($v [$this->config['parentid']] == $pid) { |
|||
$v [$this->config['child']] = $this->get_arraylist($node, $v [$this->config['id']]); |
|||
$arr [] = $v; |
|||
} |
|||
} |
|||
return $arr; |
|||
} |
|||
/** |
|||
* 得到父级数组的同级数组 |
|||
* @param int $myid 菜单id |
|||
* @return array|mixed |
|||
*/ |
|||
public function get_parent($myid) |
|||
{ |
|||
$newarr = array(); |
|||
if (!isset($this->arr[$myid])) return false; |
|||
$pid = $this->arr[$myid][$this->config['parentid']];//父级id |
|||
$pid = $this->arr[$pid][$this->config['parentid']];//祖级id |
|||
if (is_array($this->arr)) { |
|||
foreach ($this->arr as $id => $a) { |
|||
if ($a[$this->config['parentid']] == $pid) |
|||
$newarr[$id] = $a; |
|||
} |
|||
} |
|||
return $newarr; |
|||
} |
|||
|
|||
/** |
|||
* 得到子级数组的同级数组 |
|||
* @param int $myid |
|||
* @return array|mixed |
|||
*/ |
|||
public function get_child($myid) |
|||
{ |
|||
$newarr = array(); |
|||
if (is_array($this->arr)) { |
|||
foreach ($this->arr as $id => $a) { |
|||
if ($a[$this->config['parentid']] == $myid) |
|||
$newarr[$id] = $a; |
|||
} |
|||
} |
|||
return $newarr ? $newarr : false; |
|||
} |
|||
/** |
|||
* 获取所有子节点 |
|||
* @param array $lists 数据集 |
|||
* @param int $pid 父级id |
|||
* @param bool $only_id 是否只取id |
|||
* @param bool $self 是否包含自身 |
|||
* @return array |
|||
*/ |
|||
public function get_childs($lists=[],$pid=0,$only_id=false,$self=false) |
|||
{ |
|||
$result = []; |
|||
if (is_array($lists)) { |
|||
foreach ($lists as $id => $a) { |
|||
if ($a[$this->config['parentid']] == $pid) { |
|||
$result[] = $only_id?$a[$this->config['id']]:$a; |
|||
unset($lists[$id]); |
|||
$result = array_merge($result, $this->get_childs($lists,$a[$this->config['id']],$only_id,$self)); |
|||
}elseif($self && $a[$this->config['id']] == $pid){ |
|||
$result[] = $only_id?$a[$this->config['id']]:$a; |
|||
} |
|||
} |
|||
} |
|||
return $result; |
|||
} |
|||
/** |
|||
* 得到当前位置数组 |
|||
* @param int 位置 |
|||
* @param array |
|||
* @return array|mixed |
|||
*/ |
|||
public function get_pos($index, &$newarr) |
|||
{ |
|||
$a = array(); |
|||
if (!isset($this->arr[$index])) return false; |
|||
$newarr[] = $this->arr[$index]; |
|||
$pid = $this->arr[$index][$this->config['parentid']]; |
|||
if (isset($this->arr[$pid])) { |
|||
$this->get_pos($pid, $newarr); |
|||
} |
|||
//一直到顶级的数组 |
|||
if (is_array($newarr)) { |
|||
krsort($newarr);//降序排序 |
|||
foreach ($newarr as $v) { |
|||
$a[$v[$this->config['id']]] = $v; |
|||
} |
|||
} |
|||
return $a; |
|||
} |
|||
|
|||
/** |
|||
* 得到树型结构 |
|||
* @param int $myid,表示获得这个ID下的所有子级 |
|||
* @param string $str 生成树型结构的基本代码,例如:"<option value=\$id \$selected>\$spacer\$name</option>" |
|||
* @param int $sid 被选中的ID, 比如在做树形下拉框的时候需要用到 |
|||
* @param string $adds |
|||
* @param string $str_group |
|||
* @return string |
|||
*/ |
|||
public function get_tree($myid, $str, $sid = 0, $adds = '', $str_group = '') |
|||
{ |
|||
$number = 1; |
|||
//一级栏目 |
|||
$child = $this->get_child($myid);//得到子级同级数组 |
|||
if (is_array($child)) { |
|||
$total = count($child);//子级数组个数 |
|||
foreach ($child as $id => $value) { |
|||
$j = $k = ''; |
|||
if ($number == $total) { |
|||
$j .= $this->icon[2];//最后1个,前置符号为“└” |
|||
} else { |
|||
$j .= $this->icon[1];//否则,前置符号为“├” |
|||
$k = $adds ? $this->icon[0] : '';//额外前置符号 |
|||
} |
|||
$spacer = $adds ? $adds . $j : ''; |
|||
$selected = $id == $sid ? 'selected' : ''; |
|||
@extract($value); |
|||
$parentid == 0 && $str_group ? eval("\$nstr = \"$str_group\";") : eval("\$nstr = \"$str\";");//顶级 |
|||
$this->ret .= $nstr; |
|||
$nbsp = $this->nbsp; |
|||
$this->get_tree($id, $str, $sid, $adds . $k . $nbsp, $str_group);//递归子级数组 |
|||
$number++; |
|||
} |
|||
} |
|||
return $this->ret; |
|||
} |
|||
|
|||
/** |
|||
* 得到树型结构数组 |
|||
* @param int $myid,表示获得这个ID下的所有子级 |
|||
* @return array |
|||
*/ |
|||
public function get_tree_array($myid=0) |
|||
{ |
|||
$retarray = array(); |
|||
//一级栏目数组 |
|||
$child = $this->get_child($myid); |
|||
if (is_array($child)) { |
|||
foreach ($child as $id => $value) { |
|||
$retarray[$value[$this->config['id']]] = $value; |
|||
$retarray[$value[$this->config['id']]][$this->config['child']] = $this->get_tree_array($id); |
|||
} |
|||
} |
|||
return $retarray; |
|||
} |
|||
|
|||
/** |
|||
* 同get_tree,但允许多选 |
|||
* @param int $myid,表示获得这个ID下的所有子级 |
|||
* @param string $str 生成树型结构的基本代码,例如:"<option value=\$id \$selected>\$spacer\$name</option>" |
|||
* @param int $sid 被选中的ID, 比如在做树形下拉框的时候需要用到 |
|||
* @param string $adds |
|||
* @return string |
|||
*/ |
|||
public function get_tree_multi($myid, $str, $sid = 0, $adds = '') |
|||
{ |
|||
$number = 1; |
|||
$child = $this->get_child($myid); |
|||
if (is_array($child)) { |
|||
$total = count($child); |
|||
foreach ($child as $id => $a) { |
|||
$j = $k = ''; |
|||
if ($number == $total) { |
|||
$j .= $this->icon[2]; |
|||
} else { |
|||
$j .= $this->icon[1]; |
|||
$k = $adds ? $this->icon[0] : ''; |
|||
} |
|||
$spacer = $adds ? $adds . $j : ''; |
|||
$selected = $this->have($sid, $id) ? 'selected' : ''; |
|||
@extract($a); |
|||
eval("\$nstr = \"$str\";"); |
|||
$this->ret .= $nstr; |
|||
$this->get_tree_multi($id, $str, $sid, $adds . $k . $this->nbsp); |
|||
$number++; |
|||
} |
|||
} |
|||
return $this->ret; |
|||
} |
|||
|
|||
/** |
|||
* @param int $myid 要查询的ID |
|||
* @param string $str 第一种HTML代码方式 |
|||
* @param string $str2 第二种HTML代码方式 |
|||
* @param int $sid 默认选中 |
|||
* @param string $adds 前缀 |
|||
* @return string $adds 前缀 |
|||
*/ |
|||
public function get_tree_category($myid, $str, $str2, $sid = 0, $adds = '') |
|||
{ |
|||
$number = 1; |
|||
$child = $this->get_child($myid); |
|||
if (is_array($child)) { |
|||
$total = count($child); |
|||
foreach ($child as $id => $a) { |
|||
$j = $k = ''; |
|||
if ($number == $total) { |
|||
$j .= $this->icon[2]; |
|||
} else { |
|||
$j .= $this->icon[1]; |
|||
$k = $adds ? $this->icon[0] : ''; |
|||
} |
|||
$spacer = $adds ? $adds . $j : ''; |
|||
$selected = $this->have($sid, $id) ? 'selected' : ''; |
|||
@extract($a); |
|||
if (empty($html_disabled)) { |
|||
eval("\$nstr = \"$str\";"); |
|||
} else { |
|||
eval("\$nstr = \"$str2\";"); |
|||
} |
|||
$this->ret .= $nstr; |
|||
$this->get_tree_category($id, $str, $str2, $sid, $adds . $k . $this->nbsp); |
|||
$number++; |
|||
} |
|||
} |
|||
return $this->ret; |
|||
} |
|||
|
|||
/** |
|||
* 同上一类方法,jquery treeview 风格,可伸缩样式(需要treeview插件支持) |
|||
* @param int $myid 表示获得这个ID下的所有子级 |
|||
* @param string $effected_id 需要生成treeview目录数的id |
|||
* @param string $str 末级样式 |
|||
* @param string $str2 目录级别样式 |
|||
* @param int $showlevel 直接显示层级数,其余为异步显示,0为全部限制 |
|||
* @param string $style 目录样式 默认 filetree 可增加其他样式如'filetree treeview-famfamfam' |
|||
* @param int $currentlevel 计算当前层级,递归使用 适用改函数时不需要用该参数 |
|||
* @param boolean $recursion 递归使用 外部调用时为FALSE |
|||
* @return string |
|||
*/ |
|||
public function get_treeview($myid, $effected_id='example', $str="<span class='file'>\$name</span>", $str2="<span class='folder'>\$name</span>", $showlevel = 0, $style='filetree ', $currentlevel = 1, $recursion=FALSE) |
|||
{ |
|||
|
|||
$child = $this->get_child($myid); |
|||
if (!defined('EFFECTED_INIT')) { |
|||
$effected = ' id="' . $effected_id . '"'; |
|||
define('EFFECTED_INIT', 1); |
|||
} else { |
|||
$effected = ''; |
|||
} |
|||
$placeholder = '<ul><li><span class="placeholder"></span></li></ul>'; |
|||
if (!$recursion) |
|||
$this->str .='<ul' . $effected . ' class="' . $style . '">'; |
|||
if (is_array($child)) { |
|||
foreach ($child as $id => $a) { |
|||
@extract($a); |
|||
if ($showlevel > 0 && $showlevel == $currentlevel && $this->get_child($id)) |
|||
$folder = 'hasChildren'; //如设置显示层级模式@2011.07.01 |
|||
$floder_status = isset($folder) ? ' class="' . $folder . '"' : ''; |
|||
$this->str .= $recursion ? '<ul><li' . $floder_status . ' id=\'' . $id . '\'>' : '<li' . $floder_status . ' id=\'' . $id . '\'>'; |
|||
$recursion = FALSE; |
|||
//判断是否为终极栏目 |
|||
if ($child == 1) { |
|||
eval("\$nstr = \"$str2\";"); |
|||
$this->str .= $nstr; |
|||
if ($showlevel == 0 || ($showlevel > 0 && $showlevel > $currentlevel)) { |
|||
$this->get_treeview($id, $effected_id, $str, $str2, $showlevel, $style, $currentlevel + 1, TRUE); |
|||
} elseif ($showlevel > 0 && $showlevel == $currentlevel) { |
|||
$this->str .= $placeholder; |
|||
} |
|||
} else { |
|||
eval("\$nstr = \"$str\";"); |
|||
$this->str .= $nstr; |
|||
} |
|||
$this->str .=$recursion ? '</li></ul>' : '</li>'; |
|||
} |
|||
} |
|||
if (!$recursion) |
|||
$this->str .='</ul>'; |
|||
return $this->str; |
|||
} |
|||
|
|||
/** |
|||
* 生成树形菜单 |
|||
* @param int $myid 表示获得这个ID下的所有子级 |
|||
* @param string $top_ul_id 顶级菜单ul的id |
|||
* @param string $childtpl 子菜单模板 |
|||
* @param string $parenttpl 父菜单模板 |
|||
* @param int $showlevel 直接显示层级数,其余为异步显示,0为全部限制 |
|||
* @param string $ul_class 子菜单ul样式 |
|||
* @param string $li_class 子菜单li样式 |
|||
* @param string $top_ul_class 顶级菜单ul的样式 |
|||
* @param int $currentlevel 计算当前层级,递归使用 适用改函数时不需要用该参数 |
|||
* @param boolean $recursion 递归使用 外部调用时为FALSE,内部为true |
|||
* @param string $dropdown 有子元素时li的class |
|||
* @return string |
|||
*/ |
|||
|
|||
public function get_treeview_menu($myid,$top_ul_id='', $childtpl="<a href='\$href' class='sf-with-ul'>\$menu_name</a>", $parenttpl="<a href='#' target=\'\$menu_target\' class='sf-with-ul'>\$menu_name<span class='sf-sub-indicator'><i class='fa fa-angle-down'></i></span></a>", $showlevel = 0, $ul_class="" ,$li_class="" , $top_ul_class='filetree ', $currentlevel = 1, $recursion=FALSE, $dropdown='hasChild') |
|||
{ |
|||
//取出子菜单数组 |
|||
$child = $this->get_child($myid); |
|||
if (!defined('EFFECTED_INIT')) { |
|||
$effected = ' id="' . $top_ul_id . '"'; |
|||
define('EFFECTED_INIT', 1); |
|||
} else { |
|||
$effected = ''; |
|||
} |
|||
$placeholder = '<ul><li><span class="placeholder"></span></li></ul>'; |
|||
if (!$recursion){ |
|||
$this->str .='<ul' . $effected . ' class="' . $top_ul_class . ' lev_'.$showlevel.'">';//顶级菜单ul |
|||
} |
|||
$temp_recursion = false; |
|||
if (is_array($child)) { |
|||
foreach ($child as $id => $a) { |
|||
@extract($a); |
|||
if ($showlevel > 0 && is_array($this->get_child($a[$this->config['id']]))){ |
|||
$class_str = " class='$dropdown $li_class'"; |
|||
}else{ |
|||
$class_str = " class='$li_class'"; |
|||
} |
|||
$this->str .= $recursion ? "<ul class='".$ul_class." chi_".$currentlevel."'><li $class_str id= 'menu-item-$id'>" : "<li $class_str id= 'menu-item-$id'>"; |
|||
if ($recursion) $temp_recursion = $recursion; |
|||
$recursion = FALSE; |
|||
|
|||
if(strpos($href,'http')!==false&&session('user_token')){ |
|||
$href=$href.'?token='.session('user_token'); |
|||
} |
|||
|
|||
//判断是否含有子菜单 |
|||
if ($this->get_child($a[$this->config['id']])) { |
|||
eval("\$nstr = \"$parenttpl\";"); |
|||
$nstr=html_entity_decode($nstr); |
|||
$this->str .= $nstr; |
|||
if ($showlevel == 0 || ($showlevel > 0 && $showlevel > $currentlevel)) { |
|||
$this->get_treeview_menu($a[$this->config['id']], $top_ul_id, $childtpl, $parenttpl, $showlevel, $ul_class ,$li_class ,$top_ul_class, $currentlevel + 1, TRUE,$dropdown); |
|||
} elseif ($showlevel > 0 && $showlevel == $currentlevel) { |
|||
$this->str .= $placeholder; |
|||
} |
|||
} else { |
|||
eval("\$nstr = \"$childtpl\";"); |
|||
$nstr=html_entity_decode($nstr); |
|||
$this->str .= $nstr; |
|||
} |
|||
$this->str .=$recursion ? '</li></ul>' : '</li>'; |
|||
} |
|||
if ($temp_recursion) { |
|||
// for ($i = 0; $i<4; $i++) { |
|||
// $this->str .= '<li style="height:0px;min-height:0px;"></li>'; |
|||
// } |
|||
} |
|||
} |
|||
if (!$recursion) $this->str .='</ul>'; |
|||
return $this->str; |
|||
} |
|||
/** |
|||
* 某list是否有某item |
|||
* @param string $list |
|||
* @param string $item |
|||
* @return int|boolean */ |
|||
private function have($list, $item) |
|||
{ |
|||
return(strpos(',,' . $list . ',', ',' . $item . ',')); |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,170 @@ |
|||
<?php |
|||
date_default_timezone_set('PRC'); |
|||
define("YM_SMS_ADDR", "www.btom.cn:8080");/*接口地址,请联系销售获取*/ |
|||
define("YM_SMS_SEND_URI", "/inter/sendSingleSMS");/*发送单条短信接口*/ |
|||
define("YM_SMS_GETMO_URI", "/inter/getMo");/*获取上行接口*/ |
|||
define("EN_GZIP", true);/* 是否开启GZIP */ |
|||
class MagicCrypt { |
|||
private $iv = "0102030405060708";//密钥偏移量IV,可自定义 |
|||
private $encryptKey = ""; |
|||
private $appid=''; |
|||
private $type=1; |
|||
public function __construct($type='1'){ |
|||
$this->type=$type; |
|||
if(!isset($type)||$type==1){ |
|||
$this->encryptKey=config('ymsms.password'); |
|||
$this->appid=config('ymsms.cdkey'); |
|||
}else{ |
|||
$this->encryptKey=config('ymsms2.password'); |
|||
$this->appid=config('ymsms2.cdkey'); |
|||
} |
|||
} |
|||
//加密 |
|||
public function encrypt($encryptStr) { |
|||
if(version_compare(PHP_VERSION,'7.0.0','ge')){ |
|||
$encryptObj = new MagicCrypt($this->type); |
|||
return $encryptObj->encryptPhp7($encryptStr);//加密结果 |
|||
} |
|||
$localIV = $this->iv; |
|||
$encryptKey = $this->encryptKey; |
|||
if (true == EN_GZIP) $encryptStr = gzencode($encryptStr); |
|||
//Open module |
|||
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, $localIV); |
|||
mcrypt_generic_init($module, $encryptKey, $localIV); |
|||
//Padding |
|||
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); |
|||
$pad = $block - (strlen($encryptStr) % $block); //Compute how many characters need to pad |
|||
$encryptStr .= str_repeat(chr($pad), $pad); // After pad, the str length must be equal to block or its integer multiples |
|||
//encrypt |
|||
$encrypted = mcrypt_generic($module, $encryptStr); |
|||
//Close |
|||
mcrypt_generic_deinit($module); |
|||
mcrypt_module_close($module); |
|||
return $encrypted; |
|||
} |
|||
|
|||
//PHP7使用这个加密 |
|||
public function encryptPhp7($encryptStr){ |
|||
$localIV = $this->iv; |
|||
$encryptKey = $this->encryptKey; |
|||
if (true == EN_GZIP) $encryptStr = gzencode($encryptStr); |
|||
|
|||
$ivlen = openssl_cipher_iv_length("AES-128-ECB"); |
|||
$localIV=openssl_random_pseudo_bytes($ivlen); |
|||
|
|||
return openssl_encrypt($encryptStr, 'AES-128-ECB',$encryptKey,OPENSSL_RAW_DATA,$localIV); |
|||
} |
|||
//解密 |
|||
public function decrypt($encryptStr) { |
|||
if(version_compare(PHP_VERSION,'7.0.0','ge')){ |
|||
$encryptObj = new MagicCrypt($this->type); |
|||
return $encryptObj->decryptPhp7($encryptStr);//加密结果 |
|||
} |
|||
$localIV = $this->iv; |
|||
$encryptKey = $this->encryptKey; |
|||
//Open module |
|||
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, $localIV); |
|||
mcrypt_generic_init($module, $encryptKey, $localIV); |
|||
$encryptedData = mdecrypt_generic($module, $encryptStr); |
|||
if (true == EN_GZIP) $encryptedData = gzdecode($encryptedData); |
|||
return $encryptedData; |
|||
} |
|||
//PHP7使用这个解密 |
|||
public function decryptPhp7($encryptStr){ |
|||
$localIV = $this->iv; |
|||
$encryptKey = $this->encryptKey; |
|||
$ivlen = openssl_cipher_iv_length("AES-128-ECB"); |
|||
$localIV=openssl_random_pseudo_bytes($ivlen); |
|||
$encryptedData = openssl_decrypt($encryptStr,'AES-128-ECB',$encryptKey,OPENSSL_RAW_DATA,$localIV); |
|||
if (true == EN_GZIP) $encryptedData = gzdecode($encryptedData); |
|||
return $encryptedData; |
|||
} |
|||
} |
|||
class Ymsms{ |
|||
private $encryptKey = ""; |
|||
private $appid=''; |
|||
private $type=''; |
|||
public function __construct($type=1){ |
|||
$this->type=$type; |
|||
|
|||
if($type==1){ |
|||
$this->encryptKey=config('ymsms.password'); |
|||
$this->appid=config('ymsms.cdkey'); |
|||
}else{ |
|||
$this->encryptKey=config('ymsms2.password'); |
|||
$this->appid=config('ymsms2.cdkey'); |
|||
} |
|||
} |
|||
function http_request($url, $data = null){ |
|||
$curl = curl_init(); |
|||
curl_setopt($curl, CURLOPT_URL, $url); |
|||
curl_setopt($curl, CURLOPT_HEADER, true); |
|||
$header[] = "appId: ".$this->appid; |
|||
if(true == EN_GZIP)$header[] = "gzip: on"; |
|||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); |
|||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); |
|||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); |
|||
curl_setopt($curl, CURLOPT_HEADER, true); |
|||
if (!empty($data)){ |
|||
curl_setopt($curl, CURLOPT_POST, 1); |
|||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
|||
} |
|||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); |
|||
$res = curl_exec($curl); |
|||
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); |
|||
curl_close($curl); |
|||
$header = substr($res, 0, $headerSize); |
|||
$outobj =array(); |
|||
$lines = explode("\r\n",$header); |
|||
foreach($lines as $line){ |
|||
$items = explode(": ",$line); |
|||
if(isset($items[0])&&!empty($items[0])&&isset($items[1])&&!empty($items[1])){ |
|||
$key=$items[0]; |
|||
$outobj[$key]=$items[1]; |
|||
} |
|||
} |
|||
$outobj=(Object)$outobj; |
|||
$outobj->ciphertext = substr($res, $headerSize); |
|||
return $outobj; |
|||
} |
|||
function getMillisecond() { |
|||
list($t1, $t2) = explode(' ', microtime()); |
|||
return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000); |
|||
} |
|||
function SendSimpleSMS($mobile, $content, $timerTime = "", $customSmsId = "",$extendedCode = "", $validPeriodtime= 120){ |
|||
$item = new stdClass(); |
|||
$item->mobile = $mobile; |
|||
$item->content = $content; |
|||
/* 选填内容 */ |
|||
if("" != $timerTime)$item->timerTime = $timerTime; |
|||
if("" != $customSmsId)$item->customSmsId = $customSmsId; |
|||
if("" != $extendedCode)$item->extendedCode = $extendedCode; |
|||
$item->requestTime = $this->getMillisecond(); |
|||
$item->requestValidPeriod = $validPeriodtime; |
|||
$json_data = json_encode($item, JSON_UNESCAPED_UNICODE); |
|||
|
|||
$encryptObj = new MagicCrypt($this->type); |
|||
$senddata = $encryptObj->encrypt($json_data);//加密结果 |
|||
$url = YM_SMS_ADDR.YM_SMS_SEND_URI; |
|||
$resobj = $this->http_request($url, $senddata); |
|||
$resobj->plaintext = $resobj->ciphertext?$encryptObj->decrypt($resobj->ciphertext):''; |
|||
return $resobj; |
|||
} |
|||
function getMo($number =0,$validPeriodtime= 120){ |
|||
$item = new stdClass(); |
|||
/* 选填内容 */ |
|||
if(0 != $number) $item->number = $number; |
|||
|
|||
$item->requestTime = $this->getMillisecond(); |
|||
$item->requestValidPeriod = $validPeriodtime; |
|||
$json_data = json_encode($item, JSON_UNESCAPED_UNICODE); |
|||
$encryptObj = new MagicCrypt($this->type); |
|||
$senddata = $encryptObj->encrypt($json_data);//加密结果 |
|||
$url = YM_SMS_ADDR.YM_SMS_GETMO_URI; |
|||
$resobj = $this->http_request($url, $senddata); |
|||
$resobj->plaintext =$resobj->ciphertext?$encryptObj->decrypt($resobj->ciphertext):''; |
|||
return $resobj; |
|||
} |
|||
} |
|||
?> |
|||
|
|||
@ -0,0 +1,262 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | YFCMF [ WE CAN DO IT MORE SIMPLE ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: rainfer <81818832@qq.com> |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace thinksdk; |
|||
|
|||
abstract class ThinkOauth |
|||
{ |
|||
/** |
|||
* 第三方配置属性 |
|||
* @var type String |
|||
*/ |
|||
protected $config = ''; |
|||
/** |
|||
* 获取到的第三方Access Token |
|||
* @var type Array |
|||
*/ |
|||
protected $accessToken = null; |
|||
/** |
|||
* 请求授权页面展现形式 |
|||
* @var type String |
|||
*/ |
|||
protected $display = 'default'; |
|||
/** |
|||
* 授权后获取到的TOKEN信息 |
|||
* @var array |
|||
*/ |
|||
protected $token = null; |
|||
/** |
|||
* oauth版本 |
|||
* @var string |
|||
*/ |
|||
protected $Version = '2.0'; |
|||
|
|||
/** |
|||
* 申请应用时分配的app_key |
|||
* @var string |
|||
*/ |
|||
protected $AppKey = ''; |
|||
|
|||
/** |
|||
* 申请应用时分配的 app_secret |
|||
* @var string |
|||
*/ |
|||
protected $AppSecret = ''; |
|||
protected $Display = ''; |
|||
|
|||
/** |
|||
* 授权类型 response_type 目前只能为code |
|||
* @var string |
|||
*/ |
|||
protected $ResponseType = 'code'; |
|||
|
|||
/** |
|||
* grant_type 目前只能为 authorization_code |
|||
* @var string |
|||
*/ |
|||
protected $GrantType = 'authorization_code'; |
|||
|
|||
/** |
|||
* 回调页面URL 可以通过配置文件配置 |
|||
* @var string |
|||
*/ |
|||
protected $Callback = ''; |
|||
|
|||
/** |
|||
* 获取request_code的额外参数 URL查询字符串格式 |
|||
* @var string |
|||
*/ |
|||
protected $Authorize = ''; |
|||
private $Type = ''; |
|||
protected $timestamp = ''; |
|||
|
|||
private function __construct($token = null) |
|||
{ |
|||
//设置SDK类型 |
|||
$class = get_class($this); |
|||
$this->Type = strtoupper(substr($class, 0, strlen($class) - 3)); |
|||
//获取应用配置 |
|||
$config = config("think_sdk_{$this->Type}"); |
|||
if (empty($config['app_key']) || empty($config['app_secret']) || empty($config['display'])) { |
|||
exception('你尚未配置应用或未开启'); |
|||
} else { |
|||
$_config = array('response_type' =>$this->ResponseType,'grant_type'=>$this->GrantType); |
|||
$this->config = array_merge($config, $_config); |
|||
$this->timestamp = time(); |
|||
// $this->Token = $token; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 设置授权页面样式,PC或者Mobile |
|||
* @param type $display |
|||
*/ |
|||
public function setDisplay($display) |
|||
{ |
|||
if (in_array($display, array('default', 'mobile'))) { |
|||
$this->display = $display; |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 取得Oauth实例 |
|||
* @static |
|||
* @return mixed 返回Oauth |
|||
*/ |
|||
public static function getInstance($type, $token = null) |
|||
{ |
|||
$name = ucfirst(strtolower($type)) . 'SDK'; |
|||
require_once "sdk/{$name}.php"; |
|||
if (class_exists($name)) { |
|||
return new $name($token); |
|||
} else { |
|||
exception(lang('_CLASS_NOT_EXIST_') . ':' . $name); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 合并默认参数和额外参数 |
|||
* @param array $params 默认参数 |
|||
* @param array/string $param 额外参数 |
|||
* @return array: |
|||
*/ |
|||
protected function param($params, $param) |
|||
{ |
|||
if (is_string($param)) { |
|||
parse_str($param, $param); |
|||
} |
|||
return array_merge($params, $param); |
|||
} |
|||
/** |
|||
* 默认的AccessToken请求参数 |
|||
* @return type |
|||
*/ |
|||
protected function _params() |
|||
{ |
|||
$params = array( |
|||
'client_id' => $this->config['app_key'], |
|||
'client_secret' => $this->config['app_secret'], |
|||
'grant_type' => $this->GrantType, |
|||
'code' => $_GET['code'], |
|||
'redirect_uri' => $this->config['callback'], |
|||
); |
|||
return $params; |
|||
} |
|||
/** |
|||
* 获取指定API请求的URL |
|||
* @param string $api API名称 |
|||
* @param string $fix api后缀 |
|||
* @return string 请求的完整URL |
|||
*/ |
|||
protected function url($api, $fix = '') |
|||
{ |
|||
return $this->ApiBase . $api . $fix; |
|||
} |
|||
/** |
|||
* 获取access_token |
|||
*/ |
|||
public function getAccessToken($ignore_stat = false) |
|||
{ |
|||
if ($ignore_stat === false && isset($_COOKIE['A_S']) && $_GET['state'] != $_COOKIE['A_S']) { |
|||
throw new Exception('传递的STATE参数不匹配!'); |
|||
} else { |
|||
$this->initConfig(); |
|||
$params = $this->_params(); |
|||
$data = $this->http($this->GetAccessTokenURL, $params, 'POST'); |
|||
$this->token = $this->parseToken($data); |
|||
setcookie('A_S', $this->timestamp, $this->timestamp - 600, '/'); |
|||
return $this->token; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 初始化一些特殊配置 |
|||
*/ |
|||
protected function initConfig() |
|||
{ |
|||
/*用与后续扩展*/ |
|||
$callback = array( |
|||
'default' => $this->config['callback'], |
|||
'mobile' => $this->config['callback'], |
|||
); |
|||
$this->config['callback'] = $callback[$this->display]; |
|||
} |
|||
|
|||
/** |
|||
* 发送HTTP请求方法,目前只支持CURL发送请求 |
|||
* @param string $url 请求URL |
|||
* @param array $params 请求参数 |
|||
* @param string $method 请求方法GET/POST |
|||
* @return array $data 响应数据 |
|||
*/ |
|||
protected function http($url, $params, $method = 'GET', $header = array(), $multi = false) |
|||
{ |
|||
$opts = array( |
|||
CURLOPT_TIMEOUT => 30, |
|||
CURLOPT_RETURNTRANSFER => 1, |
|||
CURLOPT_SSL_VERIFYPEER => false, |
|||
CURLOPT_SSL_VERIFYHOST => false, |
|||
CURLOPT_HTTPHEADER => $header |
|||
); |
|||
|
|||
/* 根据请求类型设置特定参数 */ |
|||
switch (strtoupper($method)) { |
|||
case 'GET': |
|||
$opts[CURLOPT_URL] = $url . '?' . http_build_query($params); |
|||
break; |
|||
case 'POST': |
|||
//判断是否传输文件 |
|||
$params = $multi ? $params : http_build_query($params); |
|||
$opts[CURLOPT_URL] = $url; |
|||
$opts[CURLOPT_POST] = 1; |
|||
$opts[CURLOPT_POSTFIELDS] = $params; |
|||
break; |
|||
default: |
|||
exception('不支持的请求方式!'); |
|||
} |
|||
|
|||
/* 初始化并执行curl请求 */ |
|||
$ch = curl_init(); |
|||
curl_setopt_array($ch, $opts); |
|||
$data = curl_exec($ch); |
|||
$error = curl_error($ch); |
|||
curl_close($ch); |
|||
if ($error) |
|||
exception('请求发生错误:' . $error); |
|||
return $data; |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* 抽象方法 |
|||
* 得到请求code的地址 |
|||
*/ |
|||
abstract public function getRequestCodeURL(); |
|||
/** |
|||
* 抽象方法 |
|||
* 组装接口调用参数 并调用接口 |
|||
*/ |
|||
abstract protected function call($api, $param = '', $method = 'GET'); |
|||
/** |
|||
* 抽象方法 |
|||
* 解析access_token方法请求后的返回值 |
|||
*/ |
|||
abstract protected function parseToken($result); |
|||
/** |
|||
* 抽象方法 |
|||
* 获取当前授权用户的SNS标识 |
|||
*/ |
|||
abstract public function openid(); |
|||
abstract public function userinfo(); |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,129 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | YFCMF [ WE CAN DO IT MORE SIMPLE ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: rainfer <81818832@qq.com> |
|||
// +---------------------------------------------------------------------- |
|||
use thinksdk\ThinkOauth; |
|||
|
|||
class FacebookSDK extends ThinkOauth |
|||
{ |
|||
/** |
|||
* 获取requestCode的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetRequestCodeURL = 'https://www.facebook.com/dialog/oauth'; |
|||
|
|||
/** |
|||
* 获取access_token的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetAccessTokenURL = 'https://graph.facebook.com/oauth/access_token'; |
|||
|
|||
|
|||
/** |
|||
* API根路径 |
|||
* @var string |
|||
*/ |
|||
protected $ApiBase = 'https://graph.facebook.com/v2.3/'; |
|||
/** |
|||
* 获取scope的额外参数,可在配置中修改 URL查询字符串格式 |
|||
* @var string |
|||
*/ |
|||
protected $scope = 'email'; |
|||
|
|||
|
|||
/** |
|||
* 请求Authorize访问地址 |
|||
*/ |
|||
public function getRequestCodeURL() |
|||
{ |
|||
setcookie('A_S', $this->timestamp, $this->timestamp + 600, '/'); |
|||
$this->initConfig(); |
|||
//Oauth 标准参数 |
|||
$params = array( |
|||
'response_type' => $this->config['response_type'], |
|||
'client_id' => $this->config['app_key'], |
|||
'redirect_uri' => $this->config['callback'], |
|||
'state' => $this->timestamp, |
|||
'scope' => $this->scope, |
|||
); |
|||
return $this->GetRequestCodeURL . '?' . http_build_query($params); |
|||
} |
|||
|
|||
/** |
|||
* 组装接口调用参数 并调用接口 |
|||
* @param string $api 微博API |
|||
* @param string $param 调用API的额外参数 |
|||
* @param string $method HTTP请求方法 默认为GET |
|||
* @return json |
|||
*/ |
|||
public function call($api, $param = '', $method = 'GET', $multi = false) |
|||
{ |
|||
$params = array('access_token'=>$this->token['access_token'],); |
|||
$header = array(); |
|||
$data = $this->http($this->url($api), $this->param($params, $param), $method, $header); |
|||
return json_decode($data, true); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析access_token方法请求后的返回值 |
|||
* @param string $result 获取access_token的方法的返回值 |
|||
*/ |
|||
protected function parseToken($result) |
|||
{ |
|||
parse_str($result, $data); |
|||
if ($data['access_token'] && $data['expires']) { |
|||
$data['expires_in'] = $data['expires']; |
|||
$this->token = $data; |
|||
$data['openid'] = $this->openid(); |
|||
return $data; |
|||
} else { |
|||
throw new Exception("获取Facebook ACCESS_TOKEN 出错:{$result}"); |
|||
} |
|||
} |
|||
/** |
|||
* 获取当前授权应用的openid |
|||
* @return string |
|||
*/ |
|||
public function openid() |
|||
{ |
|||
$data = $this->token; |
|||
if (isset($data['openid'])) { |
|||
return $data['openid']; |
|||
} elseif ($data['access_token']) { |
|||
$data = $this->http($this->url('me'), array('access_token' => $data['access_token'])); |
|||
$data = json_decode ($data,true); |
|||
//var_dump($data);exit; |
|||
if ($data['id']) { |
|||
return $data['id']; |
|||
} else { |
|||
throw new Exception("获取用户openid出错:{$data['error_description']}"); |
|||
} |
|||
} else { |
|||
throw new Exception('没有获取到openid!'); |
|||
} |
|||
} |
|||
/** |
|||
* 获取授权用户的用户信息 |
|||
*/ |
|||
public function userinfo() |
|||
{ |
|||
$rsp = $this->call('me'); |
|||
if (!$rsp) { |
|||
throw new Exception('接口访问失败!' . $rsp['msg']); |
|||
} else { |
|||
$userinfo = array( |
|||
'openid' => $this->openid(), |
|||
'name' => $rsp['name'], |
|||
'head' => "http://graph.facebook.com/".$rsp['id']."/picture?type=normal" |
|||
); |
|||
return $userinfo; |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,132 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | YFCMF [ WE CAN DO IT MORE SIMPLE ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: rainfer <81818832@qq.com> |
|||
// +---------------------------------------------------------------------- |
|||
use thinksdk\ThinkOauth; |
|||
|
|||
class QqSDK extends ThinkOauth |
|||
{ |
|||
/** |
|||
* 获取requestCode的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetRequestCodeURL = 'https://graph.qq.com/oauth2.0/authorize'; |
|||
|
|||
/** |
|||
* 获取access_token的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetAccessTokenURL = 'https://graph.qq.com/oauth2.0/token'; |
|||
|
|||
|
|||
/** |
|||
* API根路径 |
|||
* @var string |
|||
*/ |
|||
protected $ApiBase = 'https://graph.qq.com/'; |
|||
/** |
|||
* 获取scope的额外参数,可在配置中修改 URL查询字符串格式 |
|||
* @var string |
|||
*/ |
|||
protected $scope = 'get_user_info,add_share'; |
|||
|
|||
/** |
|||
* 请求Authorize访问地址 |
|||
*/ |
|||
public function getRequestCodeURL() |
|||
{ |
|||
setcookie('A_S', $this->timestamp, $this->timestamp + 600, '/'); |
|||
$this->initConfig(); |
|||
//Oauth 标准参数 |
|||
$params = array( |
|||
'response_type' => $this->config['response_type'], |
|||
'client_id' => $this->config['app_key'], |
|||
'redirect_uri' => $this->config['callback'], |
|||
'state' => $this->timestamp, |
|||
'scope' => $this->scope, |
|||
'display' => $this->display |
|||
); |
|||
return $this->GetRequestCodeURL . '?' . http_build_query($params); |
|||
} |
|||
|
|||
/** |
|||
* 组装接口调用参数 并调用接口 |
|||
* @param string $api 微博API |
|||
* @param string $param 调用API的额外参数 |
|||
* @param string $method HTTP请求方法 默认为GET |
|||
* @return json |
|||
*/ |
|||
public function call($api, $param = '', $method = 'GET', $multi = false) |
|||
{ |
|||
/* 腾讯QQ调用公共参数 */ |
|||
$params = array( |
|||
'oauth_consumer_key' => $this->config['app_key'], |
|||
'access_token' => $this->token['access_token'], |
|||
'openid' => $this->openid(), |
|||
'format' => 'json' |
|||
); |
|||
$data = $this->http($this->url($api), $this->param($params, $param), $method); |
|||
return json_decode($data, true); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析access_token方法请求后的返回值 |
|||
* @param string $result 获取access_token的方法的返回值 |
|||
*/ |
|||
protected function parseToken($result) |
|||
{ |
|||
parse_str($result, $data); |
|||
if ($data['access_token'] && $data['expires_in']) { |
|||
$this->token = $data; |
|||
$data['openid'] = $this->openid(); |
|||
return $data; |
|||
} else { |
|||
throw new Exception("获取腾讯QQ ACCESS_TOKEN 出错:{$result}"); |
|||
} |
|||
} |
|||
/** |
|||
* 获取当前授权应用的openid |
|||
* @return string |
|||
*/ |
|||
public function openid() |
|||
{ |
|||
$data = $this->token; |
|||
if (isset($data['openid'])) { |
|||
return $data['openid']; |
|||
} elseif ($data['access_token']) { |
|||
$data = $this->http($this->url('oauth2.0/me'), array('access_token' => $data['access_token'])); |
|||
$data = json_decode(trim(substr($data, 9), " );\n"), true); |
|||
if (isset($data['openid'])) { |
|||
return $data['openid']; |
|||
} else { |
|||
throw new Exception("获取用户openid出错:{$data['error_description']}"); |
|||
} |
|||
} else { |
|||
throw new Exception('没有获取到openid!'); |
|||
} |
|||
} |
|||
/** |
|||
* 获取授权用户的用户信息 |
|||
*/ |
|||
public function userinfo() |
|||
{ |
|||
$rsp = $this->call('user/get_user_info'); |
|||
if (!$rsp || $rsp['ret'] != 0) { |
|||
throw new Exception('接口访问失败!' . $rsp['msg']); |
|||
} else { |
|||
$userinfo = array( |
|||
'openid' => $this->openid(), |
|||
'name' => $rsp['nickname'], |
|||
'head' => $rsp['figureurl'] |
|||
); |
|||
return $userinfo; |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,118 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | YFCMF [ WE CAN DO IT MORE SIMPLE ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: rainfer <81818832@qq.com> |
|||
// +---------------------------------------------------------------------- |
|||
use thinksdk\ThinkOauth; |
|||
|
|||
class SinaSDK extends ThinkOauth |
|||
{ |
|||
/** |
|||
* 获取requestCode的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetRequestCodeURL = 'https://api.weibo.com/oauth2/authorize'; |
|||
|
|||
/** |
|||
* 获取access_token的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetAccessTokenURL = 'https://api.weibo.com/oauth2/access_token'; |
|||
|
|||
/** |
|||
* 获取scope的额外参数,可在配置中修改 URL查询字符串格式 |
|||
* @var string |
|||
*/ |
|||
protected $scope = ''; |
|||
|
|||
/** |
|||
* API根路径 |
|||
* @var string |
|||
*/ |
|||
protected $ApiBase = 'https://api.weibo.com/2/'; |
|||
|
|||
|
|||
/** |
|||
* 请求Authorize访问地址 |
|||
*/ |
|||
public function getRequestCodeURL() |
|||
{ |
|||
setcookie('A_S', $this->timestamp, $this->timestamp + 600, '/'); |
|||
$this->initConfig(); |
|||
//Oauth 标准参数 |
|||
$params = array( |
|||
'client_id' => $this->config['app_key'], |
|||
'redirect_uri' => $this->config['callback'], |
|||
'response_type' => $this->ResponseType, |
|||
); |
|||
return $this->GetRequestCodeURL . '?' . http_build_query($params); |
|||
} |
|||
|
|||
/** |
|||
* 组装接口调用参数 并调用接口 |
|||
* @param string $api 微博API |
|||
* @param string $param 调用API的额外参数 |
|||
* @param string $method HTTP请求方法 默认为GET |
|||
* @return json |
|||
*/ |
|||
public function call($api, $param = '', $method = 'GET', $multi = false) |
|||
{ |
|||
/* 新浪微博调用公共参数 */ |
|||
$params = array( |
|||
'access_token' => $this->token['access_token'], |
|||
'uid' => $this->openid(), |
|||
); |
|||
$vars = $this->param($params, $param); |
|||
$data = $this->http($this->url($api, '.json'), $vars, $method, array(), $multi); |
|||
return json_decode($data, true); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析access_token方法请求后的返回值 |
|||
* @param string $result 获取access_token的方法的返回值 |
|||
*/ |
|||
protected function parseToken($result) |
|||
{ |
|||
$data = json_decode($result, true); |
|||
if ($data['access_token'] && $data['expires_in'] && $data['remind_in'] && $data['uid']) { |
|||
$data['openid'] = $data['uid']; |
|||
unset($data['uid']); |
|||
return $data; |
|||
} else |
|||
throw new Exception("获取新浪微博ACCESS_TOKEN出错:{$data['error']}"); |
|||
} |
|||
|
|||
/** |
|||
* 获取当前授权应用的openid |
|||
* @return string |
|||
*/ |
|||
public function openid() |
|||
{ |
|||
$data = $this->token; |
|||
if (isset($data['openid'])) |
|||
return $data['openid']; |
|||
else |
|||
throw new Exception('没有获取到新浪微博用户ID!'); |
|||
} |
|||
|
|||
public function userinfo() |
|||
{ |
|||
$rsp = $this->call('users/show'); |
|||
if (!$rsp) { |
|||
throw new Exception('接口访问失败!' . $rsp['msg']); |
|||
} else { |
|||
$userinfo = array( |
|||
'openid' => $this->openid(), |
|||
'name' => $rsp['screen_name'], |
|||
'head' => $rsp['avatar_hd'] |
|||
); |
|||
return $userinfo; |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,123 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | YFCMF [ WE CAN DO IT MORE SIMPLE ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: rainfer <81818832@qq.com> |
|||
// +---------------------------------------------------------------------- |
|||
use thinksdk\ThinkOauth; |
|||
|
|||
class WechatSDK extends ThinkOauth |
|||
{ |
|||
/** |
|||
* 获取requestCode的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetRequestCodeURL = 'https://open.weixin.qq.com/connect/oauth2/authorize'; |
|||
|
|||
/** |
|||
* 获取access_token的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetAccessTokenURL = 'https://api.weixin.qq.com/sns/oauth2/access_token'; |
|||
|
|||
|
|||
/** |
|||
* API根路径 |
|||
* @var string |
|||
*/ |
|||
protected $ApiBase = 'https://api.weixin.qq.com/sns/'; |
|||
/** |
|||
* 获取scope的额外参数,可在配置中修改 URL查询字符串格式 |
|||
* @var string |
|||
*/ |
|||
protected $scope = 'snsapi_login'; |
|||
|
|||
/** |
|||
* 请求Authorize访问地址 |
|||
*/ |
|||
public function getRequestCodeURL() |
|||
{ |
|||
setcookie('A_S', $this->timestamp, $this->timestamp + 600, '/'); |
|||
$this->initConfig(); |
|||
//Oauth 标准参数 |
|||
$params = array( |
|||
'appid' => $this->config['app_key'], |
|||
'redirect_uri' => $this->config['callback'], |
|||
'response_type' => $this->config['response_type'], |
|||
'scope' => $this->scope, |
|||
'state' => $this->timestamp, |
|||
); |
|||
|
|||
return $this->GetRequestCodeURL . '?' . http_build_query($params); |
|||
} |
|||
|
|||
/** |
|||
* 组装接口调用参数 并调用接口 |
|||
* @param string $api 微博API |
|||
* @param string $param 调用API的额外参数 |
|||
* @param string $method HTTP请求方法 默认为GET |
|||
* @return json |
|||
*/ |
|||
public function call($api, $param = '', $method = 'GET', $multi = false) |
|||
{ |
|||
/* 腾讯QQ调用公共参数 */ |
|||
$params = array( |
|||
'access_token' => $this->token['access_token'], |
|||
'openid' => $this->openid(), |
|||
'lang' => 'zh_CN' |
|||
); |
|||
$data = $this->http($this->url($api), $this->param($params, $param), $method); |
|||
return json_decode($data, true); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析access_token方法请求后的返回值 |
|||
* @param string $result 获取access_token的方法的返回值 |
|||
*/ |
|||
protected function parseToken($result) |
|||
{ |
|||
parse_str($result, $data); |
|||
if ($data['access_token'] && $data['expires_in'] && $data['openid']) { |
|||
$this->token = $data; |
|||
$data['openid'] = $this->openid(); |
|||
return $data; |
|||
} else { |
|||
throw new Exception("获取微信 ACCESS_TOKEN 出错:{$result}"); |
|||
} |
|||
} |
|||
/** |
|||
* 获取当前授权应用的openid |
|||
* @return string |
|||
*/ |
|||
public function openid() |
|||
{ |
|||
$data = $this->token; |
|||
if (isset($data['openid'])) |
|||
return $data['openid']; |
|||
else |
|||
throw new Exception('没有获取到微信用户ID!'); |
|||
} |
|||
/** |
|||
* 获取授权用户的用户信息 |
|||
*/ |
|||
public function userinfo() |
|||
{ |
|||
$rsp = $this->call('userinfo'); |
|||
if (!$rsp || (isset($rsp['errcode']) && $rsp['errcode'] != 0)) { |
|||
throw new Exception('接口访问失败!' . $rsp['msg']); |
|||
} else { |
|||
$userinfo = array( |
|||
'openid' => $this->openid(), |
|||
'name' => $rsp['nickname'], |
|||
'unionid' => isset($this->token['unionid']) ? $this->token['unionid'] : '', |
|||
'head' => $rsp['figureurl'] |
|||
); |
|||
return $userinfo; |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,137 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | YFCMF [ WE CAN DO IT MORE SIMPLE ] |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: rainfer <81818832@qq.com> |
|||
// +---------------------------------------------------------------------- |
|||
use thinksdk\ThinkOauth; |
|||
|
|||
class WeixinSDK extends ThinkOauth |
|||
{ |
|||
/** |
|||
* 获取requestCode的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetRequestCodeURL = 'https://open.weixin.qq.com/connect/qrconnect'; |
|||
|
|||
/** |
|||
* 获取access_token的api接口 |
|||
* @var string |
|||
*/ |
|||
protected $GetAccessTokenURL = 'https://api.weixin.qq.com/sns/oauth2/access_token'; |
|||
|
|||
|
|||
/** |
|||
* API根路径 |
|||
* @var string |
|||
*/ |
|||
protected $ApiBase = 'https://api.weixin.qq.com/sns/'; |
|||
/** |
|||
* 获取scope的额外参数,可在配置中修改 URL查询字符串格式 |
|||
* @var string |
|||
*/ |
|||
protected $scope = 'snsapi_login'; |
|||
|
|||
/** |
|||
* 请求Authorize访问地址 |
|||
*/ |
|||
public function getRequestCodeURL() |
|||
{ |
|||
setcookie('A_S', $this->timestamp, $this->timestamp + 600, '/'); |
|||
$this->initConfig(); |
|||
//Oauth 标准参数 |
|||
$params = array( |
|||
'appid' => $this->config['app_key'], |
|||
'redirect_uri' => $this->config['callback'], |
|||
'response_type' => $this->GrantType, |
|||
'scope' => $this->scope, |
|||
'state' => $this->timestamp, |
|||
); |
|||
return $this->GetRequestCodeURL . '?' . http_build_query($params); |
|||
} |
|||
|
|||
/** |
|||
* 组装接口调用参数 并调用接口 |
|||
* @param string $api 微博API |
|||
* @param string $param 调用API的额外参数 |
|||
* @param string $method HTTP请求方法 默认为GET |
|||
* @return json |
|||
*/ |
|||
public function call($api, $param = '', $method = 'GET', $multi = false) |
|||
{ |
|||
/* 腾讯QQ调用公共参数 */ |
|||
$params = array( |
|||
'access_token' => $this->token['access_token'], |
|||
'openid' => $this->openid(), |
|||
'lang' => 'zh_CN' |
|||
); |
|||
$data = $this->http($this->url($api), $this->param($params, $param), $method); |
|||
return json_decode($data, true); |
|||
} |
|||
|
|||
/** |
|||
* 默认的AccessToken请求参数 |
|||
* @return type |
|||
*/ |
|||
protected function _params() |
|||
{ |
|||
$params = array( |
|||
'appid' => $this->config['app_key'], |
|||
'secret' => $this->config['app_secret'], |
|||
'grant_type' => $this->GrantType, |
|||
'code' => $_GET['code'], |
|||
); |
|||
return $params; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 解析access_token方法请求后的返回值 |
|||
* @param string $result 获取access_token的方法的返回值 |
|||
*/ |
|||
protected function parseToken($result) |
|||
{ |
|||
$data = json_decode ($result,true); |
|||
if ($data['access_token'] && $data['expires_in'] && $data['openid']) { |
|||
$this->token = $data; |
|||
$data['openid'] = $this->openid(); |
|||
return $data; |
|||
} else { |
|||
throw new Exception("获取Weixin ACCESS_TOKEN 出错:{$result}"); |
|||
} |
|||
} |
|||
/** |
|||
* 获取当前授权应用的openid |
|||
* @return string |
|||
*/ |
|||
public function openid() |
|||
{ |
|||
$data = $this->token; |
|||
if (isset($data['openid'])) |
|||
return $data['openid']; |
|||
else |
|||
throw new Exception('没有获取到微信用户ID!'); |
|||
} |
|||
/** |
|||
* 获取授权用户的用户信息 |
|||
*/ |
|||
public function userinfo() |
|||
{ |
|||
$rsp = $this->call('userinfo'); |
|||
if (!$rsp || (isset($rsp['errcode']) && $rsp['errcode'] != 0)) { |
|||
throw new Exception('接口访问失败!' . $rsp['msg']); |
|||
} else { |
|||
$userinfo = array( |
|||
'openid' => $this->openid(), |
|||
'name' => $rsp['nickname'], |
|||
'unionid' => isset($this->token['unionid']) ? $this->token['unionid'] : '', |
|||
'head' => $rsp['headimgurl'] |
|||
); |
|||
return $userinfo; |
|||
} |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,120 @@ |
|||
<?php |
|||
namespace weixin; |
|||
class Jssdk { |
|||
private $appId; |
|||
private $appSecret; |
|||
|
|||
public function __construct($appId, $appSecret) { |
|||
$this->appId = $appId; |
|||
$this->appSecret = $appSecret; |
|||
} |
|||
|
|||
public function getSignPackage($jump='',$nonce='') { |
|||
$jsapiTicket = $this->getJsApiTicket(); |
|||
|
|||
// 注意 URL 一定要动态获取,不能 hardcode. |
|||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; |
|||
if(empty($jump))$url ="$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
|||
else $url=urldecode(urldecode(htmlspecialchars_decode($jump))); |
|||
$timestamp = time(); |
|||
$nonceStr = $nonce?$nonce:$this->createNonceStr(); |
|||
|
|||
// 这里参数的顺序要按照 key 值 ASCII 码升序排序 |
|||
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; |
|||
|
|||
$signature = sha1($string); |
|||
|
|||
$signPackage = array( |
|||
"appId" => $this->appId, |
|||
"nonceStr" => $nonceStr, |
|||
"timestamp" => $timestamp, |
|||
"url" => $url, |
|||
"signature" => $signature, |
|||
"rawString" => $string, |
|||
"jump"=>$url |
|||
); |
|||
return $signPackage; |
|||
} |
|||
|
|||
private function createNonceStr($length = 16) { |
|||
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
|||
$str = ""; |
|||
for ($i = 0; $i < $length; $i++) { |
|||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); |
|||
} |
|||
return $str; |
|||
} |
|||
|
|||
private function getJsApiTicket() { |
|||
// jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例 |
|||
$data = json_decode($this->get_php_file("./extend/weixin/jsapi_ticket.php")); |
|||
$ticket=''; |
|||
try { |
|||
if ($data->expire_time < time()) { |
|||
$accessToken = $this->getAccessToken(); |
|||
// 如果是企业号用以下 URL 获取 ticket |
|||
// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; |
|||
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken"; |
|||
$res = json_decode($this->httpGet($url)); |
|||
$ticket =isset($res->ticket)?$res->ticket:''; |
|||
if ($ticket) { |
|||
$data->expire_time = time() + 7000; |
|||
$data->jsapi_ticket = $ticket; |
|||
$this->set_php_file("./extend/weixin/jsapi_ticket.php", json_encode($data)); |
|||
} |
|||
} else { |
|||
$ticket = $data->jsapi_ticket; |
|||
} |
|||
} catch (\Exception $e) { } |
|||
return $ticket; |
|||
} |
|||
|
|||
private function getAccessToken() { |
|||
// access_token 应该全局存储与更新,以下代码以写入到文件中做示例 |
|||
$data = json_decode($this->get_php_file("./extend/weixin/access_token.php")); |
|||
$access_token=''; |
|||
try { |
|||
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret"; |
|||
if ($data->expire_time < time()) { |
|||
// 如果是企业号用以下URL获取access_token |
|||
// $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret"; |
|||
$res = json_decode($this->httpGet($url)); |
|||
$access_token =isset($res->access_token)?$res->access_token:''; |
|||
if ($access_token) { |
|||
$data->expire_time = time() + 7000; |
|||
$data->access_token = $access_token; |
|||
$this->set_php_file("./extend/weixin/access_token.php", json_encode($data)); |
|||
} |
|||
} else { |
|||
$access_token = $data->access_token; |
|||
} |
|||
} catch (\Exception $e) {} |
|||
return $access_token; |
|||
} |
|||
|
|||
private function httpGet($url) { |
|||
$curl = curl_init(); |
|||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|||
curl_setopt($curl, CURLOPT_TIMEOUT, 500); |
|||
// 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。 |
|||
// 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。 |
|||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,2); |
|||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,2); |
|||
curl_setopt($curl, CURLOPT_URL, $url); |
|||
|
|||
$res = curl_exec($curl); |
|||
curl_close($curl); |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
private function get_php_file($filename) { |
|||
return trim(substr(file_get_contents($filename), 15)); |
|||
} |
|||
private function set_php_file($filename, $content) { |
|||
$fp = fopen($filename, "w"); |
|||
fwrite($fp, "<?php exit();?>" . $content); |
|||
fclose($fp); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,100 @@ |
|||
<?php |
|||
namespace weixin; |
|||
class Jssdk { |
|||
private $appId; |
|||
private $appSecret; |
|||
|
|||
public function __construct($appId, $appSecret) { |
|||
$this->appId = $appId; |
|||
$this->appSecret = $appSecret; |
|||
} |
|||
|
|||
public function getSignPackage($jump='',$nonce='') { |
|||
$jsapiTicket = $this->getJsApiTicket(); |
|||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; |
|||
if(empty($jump))$url =$protocol."$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; |
|||
else $url=urldecode(urldecode(htmlspecialchars_decode($jump))); |
|||
$timestamp = time(); |
|||
$nonceStr = $nonce?$nonce:$this->createNonceStr(); |
|||
|
|||
// 这里参数的顺序要按照 key 值 ASCII 码升序排序 |
|||
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; |
|||
|
|||
$signature = sha1($string); |
|||
|
|||
$signPackage = array( |
|||
"appId" => $this->appId, |
|||
"nonceStr" => $nonceStr, |
|||
"timestamp" => $timestamp, |
|||
"url" => $url, |
|||
"signature" => $signature, |
|||
"rawString" => $string, |
|||
"jump"=>$url |
|||
); |
|||
return $signPackage; |
|||
} |
|||
|
|||
private function createNonceStr($length = 16) { |
|||
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
|||
$str = ""; |
|||
for ($i = 0; $i < $length; $i++) { |
|||
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); |
|||
} |
|||
return $str; |
|||
} |
|||
|
|||
private function getJsApiTicket() { |
|||
// jsapi_ticket 应该全局存储与更新,以下代码以写入到文件中做示例 |
|||
$data = json_decode(file_get_contents("./extend/weixin/jsapi_ticket.json")); |
|||
|
|||
if ($data->expire_time < time()) { |
|||
$accessToken = $this->getAccessToken(); |
|||
$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken"; |
|||
$res = json_decode($this->httpGet($url)); |
|||
$ticket =isset($res->ticket)?$res->ticket:''; |
|||
if ($ticket) { |
|||
$data->expire_time = time() + 7000; |
|||
$data->jsapi_ticket = $ticket; |
|||
$fp = fopen("./extend/weixin/jsapi_ticket.json", "w"); |
|||
fwrite($fp, json_encode($data)); |
|||
fclose($fp); |
|||
} |
|||
} else { |
|||
$ticket = $data->jsapi_ticket; |
|||
} |
|||
|
|||
return $ticket; |
|||
} |
|||
|
|||
private function getAccessToken() { |
|||
// access_token 应该全局存储与更新,以下代码以写入到文件中做示例 |
|||
$data = json_decode(file_get_contents("./extend/weixin/access_token.json")); |
|||
if ($data->expire_time < time()) { |
|||
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret"; |
|||
$res = json_decode($this->httpGet($url)); |
|||
$access_token =isset($res->access_token)?$res->access_token:''; |
|||
if ($access_token) { |
|||
$data->expire_time = time() + 7000; |
|||
$data->access_token = $access_token; |
|||
$fp = fopen("./extend/weixin/access_token.json", "w"); |
|||
fwrite($fp, json_encode($data)); |
|||
fclose($fp); |
|||
} |
|||
} else { |
|||
$access_token = $data->access_token; |
|||
} |
|||
return $access_token; |
|||
} |
|||
|
|||
private function httpGet($url) { |
|||
$curl = curl_init(); |
|||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|||
curl_setopt($curl, CURLOPT_TIMEOUT, 500); |
|||
curl_setopt($curl, CURLOPT_URL, $url); |
|||
|
|||
$res = curl_exec($curl); |
|||
curl_close($curl); |
|||
|
|||
return $res; |
|||
} |
|||
} |
|||
@ -0,0 +1 @@ |
|||
{"expire_time":1605690431,"access_token":"39_5PnsknlIe6RJklfUdeEJFfgtqBayQnBoo29wMyQ70uhKgVpPktJiIhgqgd4_qXH6NwgEUeIlQItLo0-uyIRZUVXZg42dBxVvO_KrssOlS-DoSfnZ4p3pEneR3GKsJ2idLg7PFjUH0er8w2EfQOBfAHAJHU"} |
|||
@ -0,0 +1 @@ |
|||
<?php exit();?>{"access_token":"68_URdKBoEHk77uby3ehEHQDWB9SsXqWGCNX08XqaTYjXV2iiGhC576XhpBCAltSRXPFGM7xB8R4ZSU36gBlMxk9R2WEA2_B09Zyfu8spHWtBtpi1oSkgmgwPq5XcoVGRcAIAOZK","expire_time":1684388654} |
|||
@ -0,0 +1 @@ |
|||
{"expire_time":1605690431,"jsapi_ticket":"HoagFKDcsGMVCIY2vOjf9rtPp7UNrdJ9q2u4vmqwz-ScOZi6i5a-k_shlyzcqm3TCZr7o8xexMf0X27qpQFuKQ"} |
|||
@ -0,0 +1 @@ |
|||
<?php exit();?>{"jsapi_ticket":"HoagFKDcsGMVCIY2vOjf9rtPp7UNrdJ9q2u4vmqwz-TalrmNrKdQM-3b799aYM-tbFwUw4XHPuwwZCJwauv_Rw","expire_time":1684388654} |
|||
Loading…
Reference in new issue