Drop unused code and fix some PhpStorm warnings

This commit is contained in:
Adrien Crivelli 2017-10-08 01:21:32 +09:00
parent 4b4bac53aa
commit 1259549466
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
26 changed files with 35 additions and 913 deletions

View File

@ -15,6 +15,8 @@ if ($helper->isCli()) {
return; return;
} }
?> ?>
<html>
<head>
<title><?php echo $helper->getPageTitle(); ?></title> <title><?php echo $helper->getPageTitle(); ?></title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <meta http-equiv="X-UA-Compatible" content="IE=edge"/>

View File

@ -3800,7 +3800,7 @@ class Calculation
return $output; return $output;
} }
private function validateBinaryOperand($cellID, &$operand, &$stack) private function validateBinaryOperand(&$operand, &$stack)
{ {
if (is_array($operand)) { if (is_array($operand)) {
if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) { if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) {
@ -4002,10 +4002,10 @@ class Calculation
private function executeNumericBinaryOperation($cellID, $operand1, $operand2, $operation, $matrixFunction, &$stack) private function executeNumericBinaryOperation($cellID, $operand1, $operand2, $operation, $matrixFunction, &$stack)
{ {
// Validate the two operands // Validate the two operands
if (!$this->validateBinaryOperand($cellID, $operand1, $stack)) { if (!$this->validateBinaryOperand($operand1, $stack)) {
return false; return false;
} }
if (!$this->validateBinaryOperand($cellID, $operand2, $stack)) { if (!$this->validateBinaryOperand($operand2, $stack)) {
return false; return false;
} }

View File

@ -2,8 +2,6 @@
namespace PhpOffice\PhpSpreadsheet\Calculation; namespace PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
class ExceptionHandler class ExceptionHandler
{ {
/** /**
@ -11,7 +9,7 @@ class ExceptionHandler
*/ */
public function __construct() public function __construct()
{ {
set_error_handler([CalculationException::class, 'errorHandlerCallback'], E_ALL); set_error_handler([Exception::class, 'errorHandlerCallback'], E_ALL);
} }
/** /**

View File

@ -24,20 +24,6 @@ class Financial
return $testDate->format('d') == $testDate->format('t'); return $testDate->format('d') == $testDate->format('t');
} }
/**
* isFirstDayOfMonth.
*
* Returns a boolean TRUE/FALSE indicating if this date is the first date of the month
*
* @param DateTime $testDate The date for testing
*
* @return bool
*/
private static function isFirstDayOfMonth($testDate)
{
return $testDate->format('d') == 1;
}
private static function couponFirstPeriodDate($settlement, $maturity, $frequency, $next) private static function couponFirstPeriodDate($settlement, $maturity, $frequency, $next)
{ {
$months = 12 / $frequency; $months = 12 / $frequency;
@ -542,8 +528,6 @@ class Financial
// US (NASD) 30/360, Actual/360 or European 30/360 // US (NASD) 30/360, Actual/360 or European 30/360
return 360 / $frequency; return 360 / $frequency;
} }
return Functions::VALUE();
} }
/** /**

View File

@ -41,27 +41,6 @@ class Statistical
return true; return true;
} }
/**
* Beta function.
*
* @author Jaco van Kooten
*
* @param p require p>0
* @param q require q>0
* @param mixed $p
* @param mixed $q
*
* @return 0 if p<=0, q<=0 or p+q>2.55E305 to avoid errors and over/underflow
*/
private static function beta($p, $q)
{
if ($p <= 0.0 || $q <= 0.0 || ($p + $q) > self::LOG_GAMMA_X_MAX_VALUE) {
return 0.0;
}
return exp(self::logBeta($p, $q));
}
/** /**
* Incomplete beta function. * Incomplete beta function.
* *
@ -540,153 +519,6 @@ class Statistical
return Functions::NULL(); return Functions::NULL();
} }
private static function inverseNcdf2($prob)
{
// Approximation of inverse standard normal CDF developed by
// B. Moro, "The Full Monte," Risk 8(2), Feb 1995, 57-58.
$a1 = 2.50662823884;
$a2 = -18.61500062529;
$a3 = 41.39119773534;
$a4 = -25.44106049637;
$b1 = -8.4735109309;
$b2 = 23.08336743743;
$b3 = -21.06224101826;
$b4 = 3.13082909833;
$c1 = 0.337475482272615;
$c2 = 0.976169019091719;
$c3 = 0.160797971491821;
$c4 = 2.76438810333863E-02;
$c5 = 3.8405729373609E-03;
$c6 = 3.951896511919E-04;
$c7 = 3.21767881768E-05;
$c8 = 2.888167364E-07;
$c9 = 3.960315187E-07;
$y = $prob - 0.5;
if (abs($y) < 0.42) {
$z = ($y * $y);
$z = $y * ((($a4 * $z + $a3) * $z + $a2) * $z + $a1) / (((($b4 * $z + $b3) * $z + $b2) * $z + $b1) * $z + 1);
} else {
if ($y > 0) {
$z = log(-log(1 - $prob));
} else {
$z = log(-log($prob));
}
$z = $c1 + $z * ($c2 + $z * ($c3 + $z * ($c4 + $z * ($c5 + $z * ($c6 + $z * ($c7 + $z * ($c8 + $z * $c9)))))));
if ($y < 0) {
$z = -$z;
}
}
return $z;
}
// function inverseNcdf2()
private static function inverseNcdf3($p)
{
// ALGORITHM AS241 APPL. STATIST. (1988) VOL. 37, NO. 3.
// Produces the normal deviate Z corresponding to a given lower
// tail area of P; Z is accurate to about 1 part in 10**16.
//
// This is a PHP version of the original FORTRAN code that can
// be found at http://lib.stat.cmu.edu/apstat/
$split1 = 0.425;
$split2 = 5;
$const1 = 0.180625;
$const2 = 1.6;
// coefficients for p close to 0.5
$a0 = 3.3871328727963666080;
$a1 = 1.3314166789178437745E+2;
$a2 = 1.9715909503065514427E+3;
$a3 = 1.3731693765509461125E+4;
$a4 = 4.5921953931549871457E+4;
$a5 = 6.7265770927008700853E+4;
$a6 = 3.3430575583588128105E+4;
$a7 = 2.5090809287301226727E+3;
$b1 = 4.2313330701600911252E+1;
$b2 = 6.8718700749205790830E+2;
$b3 = 5.3941960214247511077E+3;
$b4 = 2.1213794301586595867E+4;
$b5 = 3.9307895800092710610E+4;
$b6 = 2.8729085735721942674E+4;
$b7 = 5.2264952788528545610E+3;
// coefficients for p not close to 0, 0.5 or 1.
$c0 = 1.42343711074968357734;
$c1 = 4.63033784615654529590;
$c2 = 5.76949722146069140550;
$c3 = 3.64784832476320460504;
$c4 = 1.27045825245236838258;
$c5 = 2.41780725177450611770E-1;
$c6 = 2.27238449892691845833E-2;
$c7 = 7.74545014278341407640E-4;
$d1 = 2.05319162663775882187;
$d2 = 1.67638483018380384940;
$d3 = 6.89767334985100004550E-1;
$d4 = 1.48103976427480074590E-1;
$d5 = 1.51986665636164571966E-2;
$d6 = 5.47593808499534494600E-4;
$d7 = 1.05075007164441684324E-9;
// coefficients for p near 0 or 1.
$e0 = 6.65790464350110377720;
$e1 = 5.46378491116411436990;
$e2 = 1.78482653991729133580;
$e3 = 2.96560571828504891230E-1;
$e4 = 2.65321895265761230930E-2;
$e5 = 1.24266094738807843860E-3;
$e6 = 2.71155556874348757815E-5;
$e7 = 2.01033439929228813265E-7;
$f1 = 5.99832206555887937690E-1;
$f2 = 1.36929880922735805310E-1;
$f3 = 1.48753612908506148525E-2;
$f4 = 7.86869131145613259100E-4;
$f5 = 1.84631831751005468180E-5;
$f6 = 1.42151175831644588870E-7;
$f7 = 2.04426310338993978564E-15;
$q = $p - 0.5;
// computation for p close to 0.5
if (abs($q) <= split1) {
$R = $const1 - $q * $q;
$z = $q * ((((((($a7 * $R + $a6) * $R + $a5) * $R + $a4) * $R + $a3) * $R + $a2) * $R + $a1) * $R + $a0) /
((((((($b7 * $R + $b6) * $R + $b5) * $R + $b4) * $R + $b3) * $R + $b2) * $R + $b1) * $R + 1);
} else {
if ($q < 0) {
$R = $p;
} else {
$R = 1 - $p;
}
$R = pow(-log($R), 2);
// computation for p not close to 0, 0.5 or 1.
if ($R <= $split2) {
$R = $R - $const2;
$z = ((((((($c7 * $R + $c6) * $R + $c5) * $R + $c4) * $R + $c3) * $R + $c2) * $R + $c1) * $R + $c0) /
((((((($d7 * $R + $d6) * $R + $d5) * $R + $d4) * $R + $d3) * $R + $d2) * $R + $d1) * $R + 1);
} else {
// computation for p near 0 or 1.
$R = $R - $split2;
$z = ((((((($e7 * $R + $e6) * $R + $e5) * $R + $e4) * $R + $e3) * $R + $e2) * $R + $e1) * $R + $e0) /
((((((($f7 * $R + $f6) * $R + $f5) * $R + $f4) * $R + $f3) * $R + $f2) * $R + $f1) * $R + 1);
}
if ($q < 0) {
$z = -$z;
}
}
return $z;
}
/** /**
* AVEDEV. * AVEDEV.
* *

View File

@ -6,21 +6,4 @@ use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
class Exception extends PhpSpreadsheetException class Exception extends PhpSpreadsheetException
{ {
/**
* 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;
}
} }

View File

@ -355,11 +355,11 @@ abstract class Properties
if (!is_array($elements)) { if (!is_array($elements)) {
return $reference[$elements]; return $reference[$elements];
} }
foreach ($elements as $keys) { foreach ($elements as $keys) {
$reference = &$reference[$keys]; $reference = &$reference[$keys];
} }
return $reference; return $reference;
return $this;
} }
} }

View File

@ -4,21 +4,4 @@ namespace PhpOffice\PhpSpreadsheet;
class Exception extends \Exception class 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;
}
} }

View File

@ -6,21 +6,4 @@ use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
class Exception extends PhpSpreadsheetException class Exception extends PhpSpreadsheetException
{ {
/**
* 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;
}
} }

View File

@ -20,13 +20,6 @@ use XMLReader;
class Gnumeric extends BaseReader implements IReader class Gnumeric extends BaseReader implements IReader
{ {
/**
* Formats.
*
* @var array
*/
private $styles = [];
/** /**
* Shared Expressions. * Shared Expressions.
* *

View File

@ -19,13 +19,6 @@ use ZipArchive;
class Ods extends BaseReader implements IReader class Ods extends BaseReader implements IReader
{ {
/**
* Formats.
*
* @var array
*/
private $styles = [];
/** /**
* Create a new Ods Reader instance. * Create a new Ods Reader instance.
*/ */
@ -213,7 +206,7 @@ class Ods extends BaseReader implements IReader
} }
} elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == XMLReader::ELEMENT) { } elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == XMLReader::ELEMENT) {
$mergeSize = $xml->getAttribute('table:number-columns-repeated'); $mergeSize = $xml->getAttribute('table:number-columns-repeated');
$currCells += $mergeSize; $currCells += (int) $mergeSize;
$xml->read(); $xml->read();
} }
} while ($xml->name != 'table:table-row'); } while ($xml->name != 'table:table-row');
@ -249,20 +242,6 @@ class Ods extends BaseReader implements IReader
return $this->loadIntoExisting($pFilename, $spreadsheet); return $this->loadIntoExisting($pFilename, $spreadsheet);
} }
private static function identifyFixedStyleValue($styleList, &$styleAttributeValue)
{
$styleAttributeValue = strtolower($styleAttributeValue);
foreach ($styleList as $style) {
if ($styleAttributeValue == strtolower($style)) {
$styleAttributeValue = $style;
return true;
}
}
return false;
}
/** /**
* Loads PhpSpreadsheet from file into PhpSpreadsheet instance. * Loads PhpSpreadsheet from file into PhpSpreadsheet instance.
* *

View File

@ -164,13 +164,6 @@ class Xls extends BaseReader implements IReader
*/ */
private $documentSummaryInformation; private $documentSummaryInformation;
/**
* User-Defined Properties stream data.
*
* @var string
*/
private $userDefinedProperties;
/** /**
* Workbook stream data. (Includes workbook globals substream as well as sheet substreams). * Workbook stream data. (Includes workbook globals substream as well as sheet substreams).
* *
@ -1043,7 +1036,6 @@ class Xls extends BaseReader implements IReader
$this->readNote(); $this->readNote();
break; break;
//case self::XLS_TYPE_IMDATA: $this->readImData(); break;
case self::XLS_TYPE_TXO: case self::XLS_TYPE_TXO:
$this->readTextObject(); $this->readTextObject();
@ -5187,80 +5179,6 @@ class Xls extends BaseReader implements IReader
} }
} }
/**
* Read IMDATA record.
*/
private function readImData()
{
$length = self::getUInt2d($this->data, $this->pos + 2);
// get spliced record data
$splicedRecordData = $this->getSplicedRecordData();
$recordData = $splicedRecordData['recordData'];
// UNDER CONSTRUCTION
// offset: 0; size: 2; image format
$cf = self::getUInt2d($recordData, 0);
// offset: 2; size: 2; environment from which the file was written
$env = self::getUInt2d($recordData, 2);
// offset: 4; size: 4; length of the image data
$lcb = self::getInt4d($recordData, 4);
// offset: 8; size: var; image data
$iData = substr($recordData, 8);
switch ($cf) {
case 0x09: // Windows bitmap format
// BITMAPCOREINFO
// 1. BITMAPCOREHEADER
// offset: 0; size: 4; bcSize, Specifies the number of bytes required by the structure
$bcSize = self::getInt4d($iData, 0);
// offset: 4; size: 2; bcWidth, specifies the width of the bitmap, in pixels
$bcWidth = self::getUInt2d($iData, 4);
// offset: 6; size: 2; bcHeight, specifies the height of the bitmap, in pixels.
$bcHeight = self::getUInt2d($iData, 6);
$ih = imagecreatetruecolor($bcWidth, $bcHeight);
// offset: 8; size: 2; bcPlanes, specifies the number of planes for the target device. This value must be 1
// offset: 10; size: 2; bcBitCount specifies the number of bits-per-pixel. This value must be 1, 4, 8, or 24
$bcBitCount = self::getUInt2d($iData, 10);
$rgbString = substr($iData, 12);
$rgbTriples = [];
while (strlen($rgbString) > 0) {
$rgbTriples[] = unpack('Cb/Cg/Cr', $rgbString);
$rgbString = substr($rgbString, 3);
}
$x = 0;
$y = 0;
foreach ($rgbTriples as $i => $rgbTriple) {
$color = imagecolorallocate($ih, $rgbTriple['r'], $rgbTriple['g'], $rgbTriple['b']);
imagesetpixel($ih, $x, $bcHeight - 1 - $y, $color);
$x = ($x + 1) % $bcWidth;
$y = $y + floor(($x + 1) / $bcWidth);
}
//imagepng($ih, 'image.png');
$drawing = new Drawing();
$drawing->setPath($filename);
$drawing->setWorksheet($this->phpSheet);
break;
case 0x02: // Windows metafile or Macintosh PICT format
case 0x0e: // native format
default:
break;
}
// getSplicedRecordData() takes care of moving current position in data stream
}
/** /**
* Read a free CONTINUE record. Free CONTINUE record may be a camouflaged MSODRAWING record * Read a free CONTINUE record. Free CONTINUE record may be a camouflaged MSODRAWING record
* When MSODRAWING data on a sheet exceeds 8224 bytes, CONTINUE records are used instead. Undocumented. * When MSODRAWING data on a sheet exceeds 8224 bytes, CONTINUE records are used instead. Undocumented.

View File

@ -247,7 +247,6 @@ class Xlsx extends BaseReader implements IReader
} }
return (bool) $c->v; return (bool) $c->v;
return $value;
} }
private static function castToError($c) private static function castToError($c)

View File

@ -18,13 +18,6 @@ class Theme
*/ */
private $colourSchemeName; private $colourSchemeName;
/**
* Colour Map indexed by position.
*
* @var array of string
*/
private $colourMapValues;
/** /**
* Colour Map. * Colour Map.
* *

View File

@ -236,7 +236,7 @@ class Xml extends BaseReader implements IReader
return $this->loadIntoExisting($pFilename, $spreadsheet); return $this->loadIntoExisting($pFilename, $spreadsheet);
} }
protected static function identifyFixedStyleValue($styleList, &$styleAttributeValue) private static function identifyFixedStyleValue($styleList, &$styleAttributeValue)
{ {
$styleAttributeValue = strtolower($styleAttributeValue); $styleAttributeValue = strtolower($styleAttributeValue);
foreach ($styleList as $style) { foreach ($styleList as $style) {

View File

@ -31,13 +31,6 @@ class EigenvalueDecomposition
*/ */
private $n; private $n;
/**
* Internal symmetry flag.
*
* @var int
*/
private $issymmetric;
/** /**
* Arrays for internal storage of eigenvalues. * Arrays for internal storage of eigenvalues.
* *

View File

@ -122,9 +122,8 @@ class PolynomialBestFit extends BestFit
* @param int $order Order of Polynomial for this regression * @param int $order Order of Polynomial for this regression
* @param float[] $yValues The set of Y-values for this regression * @param float[] $yValues The set of Y-values for this regression
* @param float[] $xValues The set of X-values for this regression * @param float[] $xValues The set of X-values for this regression
* @param bool $const
*/ */
private function polynomialRegression($order, $yValues, $xValues, $const) private function polynomialRegression($order, $yValues, $xValues)
{ {
// calculate sums // calculate sums
$x_sum = array_sum($xValues); $x_sum = array_sum($xValues);
@ -156,7 +155,7 @@ class PolynomialBestFit extends BestFit
$C = $matrixA->solve($matrixB); $C = $matrixA->solve($matrixB);
$coefficients = []; $coefficients = [];
for ($i = 0; $i < $C->m; ++$i) { for ($i = 0; $i < $C->getRowDimension(); ++$i) {
$r = $C->get($i, 0); $r = $C->get($i, 0);
if (abs($r) <= pow(10, -9)) { if (abs($r) <= pow(10, -9)) {
$r = 0; $r = 0;
@ -187,7 +186,7 @@ class PolynomialBestFit extends BestFit
if ($order < $this->valueCount) { if ($order < $this->valueCount) {
$this->bestFitType .= '_' . $order; $this->bestFitType .= '_' . $order;
$this->order = $order; $this->order = $order;
$this->polynomialRegression($order, $yValues, $xValues, $const); $this->polynomialRegression($order, $yValues, $xValues);
if (($this->getGoodnessOfFit() < 0.0) || ($this->getGoodnessOfFit() > 1.0)) { if (($this->getGoodnessOfFit() < 0.0) || ($this->getGoodnessOfFit() > 1.0)) {
$this->_error = true; $this->_error = true;
} }

View File

@ -37,13 +37,6 @@ class Border extends Supervisor implements IComparable
*/ */
protected $color; protected $color;
/**
* Parent property name.
*
* @var string
*/
protected $parentPropertyName;
/** /**
* Create a new Border. * Create a new Border.
* *
@ -68,22 +61,6 @@ class Border extends Supervisor implements IComparable
} }
} }
/**
* Bind parent. Only used for supervisor.
*
* @param Borders $parent
* @param string $parentPropertyName
*
* @return Border
*/
public function bindParent($parent, $parentPropertyName = null)
{
$this->parent = $parent;
$this->parentPropertyName = $parentPropertyName;
return $this;
}
/** /**
* Get the shared style component for the currently active cell in currently active sheet. * Get the shared style component for the currently active cell in currently active sheet.
* Only used for style supervisor. * Only used for style supervisor.

View File

@ -33,13 +33,6 @@ class Color extends Supervisor implements IComparable
*/ */
protected $argb; protected $argb;
/**
* Parent property name.
*
* @var string
*/
protected $parentPropertyName;
/** /**
* Create a new Color. * Create a new Color.
* *
@ -62,22 +55,6 @@ class Color extends Supervisor implements IComparable
} }
} }
/**
* Bind parent. Only used for supervisor.
*
* @param mixed $parent
* @param string $parentPropertyName
*
* @return Color
*/
public function bindParent($parent, $parentPropertyName = null)
{
$this->parent = $parent;
$this->parentPropertyName = $parentPropertyName;
return $this;
}
/** /**
* Get the shared style component for the currently active cell in currently active sheet. * Get the shared style component for the currently active cell in currently active sheet.
* Only used for style supervisor. * Only used for style supervisor.

View File

@ -523,15 +523,15 @@ class NumberFormat extends Supervisor implements IComparable
} }
} }
private static function complexNumberFormatMask($number, $mask, $level = 0) private static function complexNumberFormatMask($number, $mask)
{ {
$sign = ($number < 0.0); $sign = ($number < 0.0);
$number = abs($number); $number = abs($number);
if (strpos($mask, '.') !== false) { if (strpos($mask, '.') !== false) {
$numbers = explode('.', $number . '.0'); $numbers = explode('.', $number . '.0');
$masks = explode('.', $mask . '.0'); $masks = explode('.', $mask . '.0');
$result1 = self::complexNumberFormatMask($numbers[0], $masks[0], 1); $result1 = self::complexNumberFormatMask($numbers[0], $masks[0]);
$result2 = strrev(self::complexNumberFormatMask(strrev($numbers[1]), strrev($masks[1]), 1)); $result2 = strrev(self::complexNumberFormatMask(strrev($numbers[1]), strrev($masks[1])));
return (($sign) ? '-' : '') . $result1 . '.' . $result2; return (($sign) ? '-' : '') . $result1 . '.' . $result2;
} }

View File

@ -18,6 +18,13 @@ abstract class Supervisor
*/ */
protected $parent; protected $parent;
/**
* Parent property name.
*
* @var null|string
*/
protected $parentPropertyName;
/** /**
* Create a new Supervisor. * Create a new Supervisor.
* *
@ -35,13 +42,14 @@ abstract class Supervisor
* Bind parent. Only used for supervisor. * Bind parent. Only used for supervisor.
* *
* @param Style $parent * @param Style $parent
* @param null|mixed $parentPropertyName * @param null|string $parentPropertyName
* *
* @return Supervisor * @return Supervisor
*/ */
public function bindParent($parent, $parentPropertyName = null) public function bindParent($parent, $parentPropertyName = null)
{ {
$this->parent = $parent; $this->parent = $parent;
$this->parentPropertyName = $parentPropertyName;
return $this; return $this;
} }

View File

@ -6,21 +6,4 @@ use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
class Exception extends PhpSpreadsheetException class Exception extends PhpSpreadsheetException
{ {
/**
* 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;
}
} }

View File

@ -53,9 +53,9 @@ class DomPDF extends Core implements IWriter
// Create PDF // Create PDF
$pdf = new \Dompdf\Dompdf(); $pdf = new \Dompdf\Dompdf();
$pdf->set_paper(strtolower($paperSize), $orientation); $pdf->setPaper(strtolower($paperSize), $orientation);
$pdf->load_html( $pdf->loadHtml(
$this->generateHTMLHeader(false) . $this->generateHTMLHeader(false) .
$this->generateSheetData() . $this->generateSheetData() .
$this->generateHTMLFooter() $this->generateHTMLFooter()

View File

@ -734,50 +734,6 @@ class Parser
return pack('C', 0xFF); return pack('C', 0xFF);
} }
/**
* Convert the sheet name part of an external reference, for example "Sheet1" or
* "Sheet1:Sheet2", to a packed structure.
*
* @param string $ext_ref The name of the external reference
*
* @return string The reference index in packed() format
*/
private function packExtRef($ext_ref)
{
$ext_ref = preg_replace("/^'/", '', $ext_ref); // Remove leading ' if any.
$ext_ref = preg_replace("/'$/", '', $ext_ref); // Remove trailing ' if any.
// Check if there is a sheet range eg., Sheet1:Sheet2.
if (preg_match('/:/', $ext_ref)) {
list($sheet_name1, $sheet_name2) = explode(':', $ext_ref);
$sheet1 = $this->getSheetIndex($sheet_name1);
if ($sheet1 == -1) {
throw new WriterException("Unknown sheet name $sheet_name1 in formula");
}
$sheet2 = $this->getSheetIndex($sheet_name2);
if ($sheet2 == -1) {
throw new WriterException("Unknown sheet name $sheet_name2 in formula");
}
// Reverse max and min sheet numbers if necessary
if ($sheet1 > $sheet2) {
list($sheet1, $sheet2) = [$sheet2, $sheet1];
}
} else { // Single sheet name only.
$sheet1 = $this->getSheetIndex($ext_ref);
if ($sheet1 == -1) {
throw new WriterException("Unknown sheet name $ext_ref in formula");
}
$sheet2 = $sheet1;
}
// References are stored relative to 0xFFFF.
$offset = -1 - $sheet1;
return pack('vdvv', $offset, 0x00, $sheet1, $sheet2);
}
/** /**
* Look up the REF index that corresponds to an external sheet name * Look up the REF index that corresponds to an external sheet name
* (or range). If it doesn't exist yet add it to the workbook's references * (or range). If it doesn't exist yet add it to the workbook's references

View File

@ -527,114 +527,6 @@ class Workbook extends BIFFwriter
$this->writeStyle(); $this->writeStyle();
} }
/**
* Write the EXTERNCOUNT and EXTERNSHEET records. These are used as indexes for
* the NAME records.
*/
private function writeExternals()
{
$countSheets = $this->spreadsheet->getSheetCount();
// Create EXTERNCOUNT with number of worksheets
$this->writeExternalCount($countSheets);
// Create EXTERNSHEET for each worksheet
for ($i = 0; $i < $countSheets; ++$i) {
$this->writeExternalSheet($this->spreadsheet->getSheet($i)->getTitle());
}
}
/**
* Write the NAME record to define the print area and the repeat rows and cols.
*/
private function writeNames()
{
// total number of sheets
$total_worksheets = $this->spreadsheet->getSheetCount();
// Create the print area NAME records
for ($i = 0; $i < $total_worksheets; ++$i) {
$sheetSetup = $this->spreadsheet->getSheet($i)->getPageSetup();
// Write a Name record if the print area has been defined
if ($sheetSetup->isPrintAreaSet()) {
// Print area
$printArea = Cell::splitRange($sheetSetup->getPrintArea());
$printArea = $printArea[0];
$printArea[0] = Cell::coordinateFromString($printArea[0]);
$printArea[1] = Cell::coordinateFromString($printArea[1]);
$print_rowmin = $printArea[0][1] - 1;
$print_rowmax = $printArea[1][1] - 1;
$print_colmin = Cell::columnIndexFromString($printArea[0][0]) - 1;
$print_colmax = Cell::columnIndexFromString($printArea[1][0]) - 1;
$this->writeNameShort(
$i, // sheet index
0x06, // NAME type
$print_rowmin,
$print_rowmax,
$print_colmin,
$print_colmax
);
}
}
// Create the print title NAME records
for ($i = 0; $i < $total_worksheets; ++$i) {
$sheetSetup = $this->spreadsheet->getSheet($i)->getPageSetup();
// simultaneous repeatColumns repeatRows
if ($sheetSetup->isColumnsToRepeatAtLeftSet() && $sheetSetup->isRowsToRepeatAtTopSet()) {
$repeat = $sheetSetup->getColumnsToRepeatAtLeft();
$colmin = Cell::columnIndexFromString($repeat[0]) - 1;
$colmax = Cell::columnIndexFromString($repeat[1]) - 1;
$repeat = $sheetSetup->getRowsToRepeatAtTop();
$rowmin = $repeat[0] - 1;
$rowmax = $repeat[1] - 1;
$this->writeNameLong(
$i, // sheet index
0x07, // NAME type
$rowmin,
$rowmax,
$colmin,
$colmax
);
// (exclusive) either repeatColumns or repeatRows
} elseif ($sheetSetup->isColumnsToRepeatAtLeftSet() || $sheetSetup->isRowsToRepeatAtTopSet()) {
// Columns to repeat
if ($sheetSetup->isColumnsToRepeatAtLeftSet()) {
$repeat = $sheetSetup->getColumnsToRepeatAtLeft();
$colmin = Cell::columnIndexFromString($repeat[0]) - 1;
$colmax = Cell::columnIndexFromString($repeat[1]) - 1;
} else {
$colmin = 0;
$colmax = 255;
}
// Rows to repeat
if ($sheetSetup->isRowsToRepeatAtTopSet()) {
$repeat = $sheetSetup->getRowsToRepeatAtTop();
$rowmin = $repeat[0] - 1;
$rowmax = $repeat[1] - 1;
} else {
$rowmin = 0;
$rowmax = 65535;
}
$this->writeNameShort(
$i, // sheet index
0x07, // NAME type
$rowmin,
$rowmax,
$colmin,
$colmax
);
}
}
}
/** /**
* Writes all the DEFINEDNAME records (BIFF8). * Writes all the DEFINEDNAME records (BIFF8).
* So far this is only used for repeating rows/columns (print titles) and print areas. * So far this is only used for repeating rows/columns (print titles) and print areas.
@ -1035,195 +927,6 @@ class Workbook extends BIFFwriter
$this->append($header . $data); $this->append($header . $data);
} }
/**
* Write BIFF record EXTERNCOUNT to indicate the number of external sheet
* references in the workbook.
*
* Excel only stores references to external sheets that are used in NAME.
* The workbook NAME record is required to define the print area and the repeat
* rows and columns.
*
* A similar method is used in Worksheet.php for a slightly different purpose.
*
* @param int $cxals Number of external references
*/
private function writeExternalCount($cxals)
{
$record = 0x0016; // Record identifier
$length = 0x0002; // Number of bytes to follow
$header = pack('vv', $record, $length);
$data = pack('v', $cxals);
$this->append($header . $data);
}
/**
* Writes the Excel BIFF EXTERNSHEET record. These references are used by
* formulas. NAME record is required to define the print area and the repeat
* rows and columns.
*
* A similar method is used in Worksheet.php for a slightly different purpose.
*
* @param string $sheetname Worksheet name
*/
private function writeExternalSheet($sheetname)
{
$record = 0x0017; // Record identifier
$length = 0x02 + strlen($sheetname); // Number of bytes to follow
$cch = strlen($sheetname); // Length of sheet name
$rgch = 0x03; // Filename encoding
$header = pack('vv', $record, $length);
$data = pack('CC', $cch, $rgch);
$this->append($header . $data . $sheetname);
}
/**
* Store the NAME record in the short format that is used for storing the print
* area, repeat rows only and repeat columns only.
*
* @param int $index Sheet index
* @param int $type Built-in name type
* @param int $rowmin Start row
* @param int $rowmax End row
* @param int $colmin Start colum
* @param int $colmax End column
*/
private function writeNameShort($index, $type, $rowmin, $rowmax, $colmin, $colmax)
{
$record = 0x0018; // Record identifier
$length = 0x0024; // Number of bytes to follow
$grbit = 0x0020; // Option flags
$chKey = 0x00; // Keyboard shortcut
$cch = 0x01; // Length of text name
$cce = 0x0015; // Length of text definition
$ixals = $index + 1; // Sheet index
$itab = $ixals; // Equal to ixals
$cchCustMenu = 0x00; // Length of cust menu text
$cchDescription = 0x00; // Length of description text
$cchHelptopic = 0x00; // Length of help topic text
$cchStatustext = 0x00; // Length of status bar text
$rgch = $type; // Built-in name type
$unknown03 = 0x3b;
$unknown04 = 0xffff - $index;
$unknown05 = 0x0000;
$unknown06 = 0x0000;
$unknown07 = 0x1087;
$unknown08 = 0x8005;
$header = pack('vv', $record, $length);
$data = pack('v', $grbit);
$data .= pack('C', $chKey);
$data .= pack('C', $cch);
$data .= pack('v', $cce);
$data .= pack('v', $ixals);
$data .= pack('v', $itab);
$data .= pack('C', $cchCustMenu);
$data .= pack('C', $cchDescription);
$data .= pack('C', $cchHelptopic);
$data .= pack('C', $cchStatustext);
$data .= pack('C', $rgch);
$data .= pack('C', $unknown03);
$data .= pack('v', $unknown04);
$data .= pack('v', $unknown05);
$data .= pack('v', $unknown06);
$data .= pack('v', $unknown07);
$data .= pack('v', $unknown08);
$data .= pack('v', $index);
$data .= pack('v', $index);
$data .= pack('v', $rowmin);
$data .= pack('v', $rowmax);
$data .= pack('C', $colmin);
$data .= pack('C', $colmax);
$this->append($header . $data);
}
/**
* Store the NAME record in the long format that is used for storing the repeat
* rows and columns when both are specified. This shares a lot of code with
* writeNameShort() but we use a separate method to keep the code clean.
* Code abstraction for reuse can be carried too far, and I should know. ;-).
*
* @param int $index Sheet index
* @param int $type Built-in name type
* @param int $rowmin Start row
* @param int $rowmax End row
* @param int $colmin Start colum
* @param int $colmax End column
*/
private function writeNameLong($index, $type, $rowmin, $rowmax, $colmin, $colmax)
{
$record = 0x0018; // Record identifier
$length = 0x003d; // Number of bytes to follow
$grbit = 0x0020; // Option flags
$chKey = 0x00; // Keyboard shortcut
$cch = 0x01; // Length of text name
$cce = 0x002e; // Length of text definition
$ixals = $index + 1; // Sheet index
$itab = $ixals; // Equal to ixals
$cchCustMenu = 0x00; // Length of cust menu text
$cchDescription = 0x00; // Length of description text
$cchHelptopic = 0x00; // Length of help topic text
$cchStatustext = 0x00; // Length of status bar text
$rgch = $type; // Built-in name type
$unknown01 = 0x29;
$unknown02 = 0x002b;
$unknown03 = 0x3b;
$unknown04 = 0xffff - $index;
$unknown05 = 0x0000;
$unknown06 = 0x0000;
$unknown07 = 0x1087;
$unknown08 = 0x8008;
$header = pack('vv', $record, $length);
$data = pack('v', $grbit);
$data .= pack('C', $chKey);
$data .= pack('C', $cch);
$data .= pack('v', $cce);
$data .= pack('v', $ixals);
$data .= pack('v', $itab);
$data .= pack('C', $cchCustMenu);
$data .= pack('C', $cchDescription);
$data .= pack('C', $cchHelptopic);
$data .= pack('C', $cchStatustext);
$data .= pack('C', $rgch);
$data .= pack('C', $unknown01);
$data .= pack('v', $unknown02);
// Column definition
$data .= pack('C', $unknown03);
$data .= pack('v', $unknown04);
$data .= pack('v', $unknown05);
$data .= pack('v', $unknown06);
$data .= pack('v', $unknown07);
$data .= pack('v', $unknown08);
$data .= pack('v', $index);
$data .= pack('v', $index);
$data .= pack('v', 0x0000);
$data .= pack('v', 0x3fff);
$data .= pack('C', $colmin);
$data .= pack('C', $colmax);
// Row definition
$data .= pack('C', $unknown03);
$data .= pack('v', $unknown04);
$data .= pack('v', $unknown05);
$data .= pack('v', $unknown06);
$data .= pack('v', $unknown07);
$data .= pack('v', $unknown08);
$data .= pack('v', $index);
$data .= pack('v', $index);
$data .= pack('v', $rowmin);
$data .= pack('v', $rowmax);
$data .= pack('C', 0x00);
$data .= pack('C', 0xff);
// End of data
$data .= pack('C', 0x10);
$this->append($header . $data);
}
/** /**
* Stores the COUNTRY record for localization. * Stores the COUNTRY record for localization.
* *

View File

@ -682,43 +682,6 @@ class Worksheet extends BIFFwriter
$this->append($header . $data); $this->append($header . $data);
} }
/**
* Write a string to the specified row and column (zero indexed).
* NOTE: there is an Excel 5 defined limit of 255 characters.
* $format is optional.
* Returns 0 : normal termination
* -2 : row or column out of range
* -3 : long string truncated to 255 chars.
*
* @param int $row Zero indexed row
* @param int $col Zero indexed column
* @param string $str The string to write
* @param mixed $xfIndex The XF format index for the cell
*
* @return int
*/
private function writeLabel($row, $col, $str, $xfIndex)
{
$strlen = strlen($str);
$record = 0x0204; // Record identifier
$length = 0x0008 + $strlen; // Bytes to follow
$str_error = 0;
if ($strlen > $this->xlsStringMaxLength) { // LABEL must be < 255 chars
$str = substr($str, 0, $this->xlsStringMaxLength);
$length = 0x0008 + $this->xlsStringMaxLength;
$strlen = $this->xlsStringMaxLength;
$str_error = -3;
}
$header = pack('vv', $record, $length);
$data = pack('vvvv', $row, $col, $xfIndex, $strlen);
$this->append($header . $data . $str);
return $str_error;
}
/** /**
* Write a string to the specified row and column (zero indexed). * Write a string to the specified row and column (zero indexed).
* This is the BIFF8 version (no 255 chars limit). * This is the BIFF8 version (no 255 chars limit).
@ -752,37 +715,6 @@ class Worksheet extends BIFFwriter
$this->append($header . $data); $this->append($header . $data);
} }
/**
* Writes a note associated with the cell given by the row and column.
* NOTE records don't have a length limit.
*
* @param int $row Zero indexed row
* @param int $col Zero indexed column
* @param string $note The note to write
*/
private function writeNote($row, $col, $note)
{
$note_length = strlen($note);
$record = 0x001C; // Record identifier
$max_length = 2048; // Maximun length for a NOTE record
// Length for this record is no more than 2048 + 6
$length = 0x0006 + min($note_length, 2048);
$header = pack('vv', $record, $length);
$data = pack('vvv', $row, $col, $note_length);
$this->append($header . $data . substr($note, 0, 2048));
for ($i = $max_length; $i < $note_length; $i += $max_length) {
$chunk = substr($note, $i, $max_length);
$length = 0x0006 + strlen($chunk);
$header = pack('vv', $record, $length);
$data = pack('vvv', -1, 0, strlen($chunk));
$this->append($header . $data . $chunk);
}
return 0;
}
/** /**
* Write a blank cell to the specified row and column (zero indexed). * Write a blank cell to the specified row and column (zero indexed).
* A blank cell is used to specify formatting without adding a string * A blank cell is used to specify formatting without adding a string
@ -1647,59 +1579,6 @@ class Worksheet extends BIFFwriter
} }
} }
/**
* Write BIFF record EXTERNCOUNT to indicate the number of external sheet
* references in a worksheet.
*
* Excel only stores references to external sheets that are used in formulas.
* For simplicity we store references to all the sheets in the workbook
* regardless of whether they are used or not. This reduces the overall
* complexity and eliminates the need for a two way dialogue between the formula
* parser the worksheet objects.
*
* @param int $count The number of external sheet references in this worksheet
*/
private function writeExterncount($count)
{
$record = 0x0016; // Record identifier
$length = 0x0002; // Number of bytes to follow
$header = pack('vv', $record, $length);
$data = pack('v', $count);
$this->append($header . $data);
}
/**
* Writes the Excel BIFF EXTERNSHEET record. These references are used by
* formulas. A formula references a sheet name via an index. Since we store a
* reference to all of the external worksheets the EXTERNSHEET index is the same
* as the worksheet index.
*
* @param string $sheetname The name of a external worksheet
*/
private function writeExternsheet($sheetname)
{
$record = 0x0017; // Record identifier
// References to the current sheet are encoded differently to references to
// external sheets.
//
if ($this->phpSheet->getTitle() == $sheetname) {
$sheetname = '';
$length = 0x02; // The following 2 bytes
$cch = 1; // The following byte
$rgch = 0x02; // Self reference
} else {
$length = 0x02 + strlen($sheetname);
$cch = strlen($sheetname);
$rgch = 0x03; // Reference to a sheet in the current workbook
}
$header = pack('vv', $record, $length);
$data = pack('CC', $cch, $rgch);
$this->append($header . $data . $sheetname);
}
/** /**
* Writes the Excel BIFF PANE record. * Writes the Excel BIFF PANE record.
* The panes can either be frozen or thawed (unfrozen). * The panes can either be frozen or thawed (unfrozen).