From 1259549466efa9d9cd38976d4dfc50c6dd1b6f62 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Sun, 8 Oct 2017 01:21:32 +0900 Subject: [PATCH] Drop unused code and fix some PhpStorm warnings --- samples/Header.php | 20 +- src/PhpSpreadsheet/Calculation.php | 6 +- .../Calculation/ExceptionHandler.php | 4 +- src/PhpSpreadsheet/Calculation/Financial.php | 16 - .../Calculation/Statistical.php | 168 ---------- src/PhpSpreadsheet/Chart/Exception.php | 17 - src/PhpSpreadsheet/Chart/Properties.php | 2 +- src/PhpSpreadsheet/Exception.php | 17 - src/PhpSpreadsheet/Reader/Exception.php | 17 - src/PhpSpreadsheet/Reader/Gnumeric.php | 7 - src/PhpSpreadsheet/Reader/Ods.php | 23 +- src/PhpSpreadsheet/Reader/Xls.php | 82 ----- src/PhpSpreadsheet/Reader/Xlsx.php | 1 - src/PhpSpreadsheet/Reader/Xlsx/Theme.php | 7 - src/PhpSpreadsheet/Reader/Xml.php | 2 +- .../Shared/JAMA/EigenvalueDecomposition.php | 7 - .../Shared/Trend/PolynomialBestFit.php | 7 +- src/PhpSpreadsheet/Style/Border.php | 23 -- src/PhpSpreadsheet/Style/Color.php | 23 -- src/PhpSpreadsheet/Style/NumberFormat.php | 6 +- src/PhpSpreadsheet/Style/Supervisor.php | 10 +- src/PhpSpreadsheet/Writer/Exception.php | 17 - src/PhpSpreadsheet/Writer/Pdf/DomPDF.php | 4 +- src/PhpSpreadsheet/Writer/Xls/Parser.php | 44 --- src/PhpSpreadsheet/Writer/Xls/Workbook.php | 297 ------------------ src/PhpSpreadsheet/Writer/Xls/Worksheet.php | 121 ------- 26 files changed, 35 insertions(+), 913 deletions(-) diff --git a/samples/Header.php b/samples/Header.php index bb14f520..fb8bd986 100644 --- a/samples/Header.php +++ b/samples/Header.php @@ -15,15 +15,17 @@ if ($helper->isCli()) { return; } ?> -<?php echo $helper->getPageTitle(); ?> - - - - - - - - + + + <?php echo $helper->getPageTitle(); ?> + + + + + + + +
diff --git a/src/PhpSpreadsheet/Calculation.php b/src/PhpSpreadsheet/Calculation.php index f41c1489..b755667a 100644 --- a/src/PhpSpreadsheet/Calculation.php +++ b/src/PhpSpreadsheet/Calculation.php @@ -3800,7 +3800,7 @@ class Calculation return $output; } - private function validateBinaryOperand($cellID, &$operand, &$stack) + private function validateBinaryOperand(&$operand, &$stack) { if (is_array($operand)) { if ((count($operand, COUNT_RECURSIVE) - count($operand)) == 1) { @@ -4002,10 +4002,10 @@ class Calculation private function executeNumericBinaryOperation($cellID, $operand1, $operand2, $operation, $matrixFunction, &$stack) { // Validate the two operands - if (!$this->validateBinaryOperand($cellID, $operand1, $stack)) { + if (!$this->validateBinaryOperand($operand1, $stack)) { return false; } - if (!$this->validateBinaryOperand($cellID, $operand2, $stack)) { + if (!$this->validateBinaryOperand($operand2, $stack)) { return false; } diff --git a/src/PhpSpreadsheet/Calculation/ExceptionHandler.php b/src/PhpSpreadsheet/Calculation/ExceptionHandler.php index 34986765..41e51d4a 100644 --- a/src/PhpSpreadsheet/Calculation/ExceptionHandler.php +++ b/src/PhpSpreadsheet/Calculation/ExceptionHandler.php @@ -2,8 +2,6 @@ namespace PhpOffice\PhpSpreadsheet\Calculation; -use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; - class ExceptionHandler { /** @@ -11,7 +9,7 @@ class ExceptionHandler */ public function __construct() { - set_error_handler([CalculationException::class, 'errorHandlerCallback'], E_ALL); + set_error_handler([Exception::class, 'errorHandlerCallback'], E_ALL); } /** diff --git a/src/PhpSpreadsheet/Calculation/Financial.php b/src/PhpSpreadsheet/Calculation/Financial.php index 91890c22..27fcd616 100644 --- a/src/PhpSpreadsheet/Calculation/Financial.php +++ b/src/PhpSpreadsheet/Calculation/Financial.php @@ -24,20 +24,6 @@ class Financial 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) { $months = 12 / $frequency; @@ -542,8 +528,6 @@ class Financial // US (NASD) 30/360, Actual/360 or European 30/360 return 360 / $frequency; } - - return Functions::VALUE(); } /** diff --git a/src/PhpSpreadsheet/Calculation/Statistical.php b/src/PhpSpreadsheet/Calculation/Statistical.php index 50631b5c..9e0fe1cb 100644 --- a/src/PhpSpreadsheet/Calculation/Statistical.php +++ b/src/PhpSpreadsheet/Calculation/Statistical.php @@ -41,27 +41,6 @@ class Statistical 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. * @@ -540,153 +519,6 @@ class Statistical 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. * diff --git a/src/PhpSpreadsheet/Chart/Exception.php b/src/PhpSpreadsheet/Chart/Exception.php index 8947b728..3f95b599 100644 --- a/src/PhpSpreadsheet/Chart/Exception.php +++ b/src/PhpSpreadsheet/Chart/Exception.php @@ -6,21 +6,4 @@ use PhpOffice\PhpSpreadsheet\Exception as 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; - } } diff --git a/src/PhpSpreadsheet/Chart/Properties.php b/src/PhpSpreadsheet/Chart/Properties.php index 2a3c03d8..07b8cf52 100644 --- a/src/PhpSpreadsheet/Chart/Properties.php +++ b/src/PhpSpreadsheet/Chart/Properties.php @@ -355,11 +355,11 @@ abstract class Properties if (!is_array($elements)) { return $reference[$elements]; } + foreach ($elements as $keys) { $reference = &$reference[$keys]; } return $reference; - return $this; } } diff --git a/src/PhpSpreadsheet/Exception.php b/src/PhpSpreadsheet/Exception.php index 1c8be172..9c5ab30e 100644 --- a/src/PhpSpreadsheet/Exception.php +++ b/src/PhpSpreadsheet/Exception.php @@ -4,21 +4,4 @@ namespace PhpOffice\PhpSpreadsheet; 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; - } } diff --git a/src/PhpSpreadsheet/Reader/Exception.php b/src/PhpSpreadsheet/Reader/Exception.php index 54004132..ddbc9b51 100644 --- a/src/PhpSpreadsheet/Reader/Exception.php +++ b/src/PhpSpreadsheet/Reader/Exception.php @@ -6,21 +6,4 @@ use PhpOffice\PhpSpreadsheet\Exception as 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; - } } diff --git a/src/PhpSpreadsheet/Reader/Gnumeric.php b/src/PhpSpreadsheet/Reader/Gnumeric.php index c766f400..2baf292c 100644 --- a/src/PhpSpreadsheet/Reader/Gnumeric.php +++ b/src/PhpSpreadsheet/Reader/Gnumeric.php @@ -20,13 +20,6 @@ use XMLReader; class Gnumeric extends BaseReader implements IReader { - /** - * Formats. - * - * @var array - */ - private $styles = []; - /** * Shared Expressions. * diff --git a/src/PhpSpreadsheet/Reader/Ods.php b/src/PhpSpreadsheet/Reader/Ods.php index 39bba5f0..48edc43d 100644 --- a/src/PhpSpreadsheet/Reader/Ods.php +++ b/src/PhpSpreadsheet/Reader/Ods.php @@ -19,13 +19,6 @@ use ZipArchive; class Ods extends BaseReader implements IReader { - /** - * Formats. - * - * @var array - */ - private $styles = []; - /** * 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) { $mergeSize = $xml->getAttribute('table:number-columns-repeated'); - $currCells += $mergeSize; + $currCells += (int) $mergeSize; $xml->read(); } } while ($xml->name != 'table:table-row'); @@ -249,20 +242,6 @@ class Ods extends BaseReader implements IReader 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. * diff --git a/src/PhpSpreadsheet/Reader/Xls.php b/src/PhpSpreadsheet/Reader/Xls.php index 624ed1e4..fbb248da 100644 --- a/src/PhpSpreadsheet/Reader/Xls.php +++ b/src/PhpSpreadsheet/Reader/Xls.php @@ -164,13 +164,6 @@ class Xls extends BaseReader implements IReader */ private $documentSummaryInformation; - /** - * User-Defined Properties stream data. - * - * @var string - */ - private $userDefinedProperties; - /** * Workbook stream data. (Includes workbook globals substream as well as sheet substreams). * @@ -1043,7 +1036,6 @@ class Xls extends BaseReader implements IReader $this->readNote(); break; - //case self::XLS_TYPE_IMDATA: $this->readImData(); break; case self::XLS_TYPE_TXO: $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 * When MSODRAWING data on a sheet exceeds 8224 bytes, CONTINUE records are used instead. Undocumented. diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 000f0424..ece5d1e6 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -247,7 +247,6 @@ class Xlsx extends BaseReader implements IReader } return (bool) $c->v; - return $value; } private static function castToError($c) diff --git a/src/PhpSpreadsheet/Reader/Xlsx/Theme.php b/src/PhpSpreadsheet/Reader/Xlsx/Theme.php index 0892a862..c105f3c1 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx/Theme.php +++ b/src/PhpSpreadsheet/Reader/Xlsx/Theme.php @@ -18,13 +18,6 @@ class Theme */ private $colourSchemeName; - /** - * Colour Map indexed by position. - * - * @var array of string - */ - private $colourMapValues; - /** * Colour Map. * diff --git a/src/PhpSpreadsheet/Reader/Xml.php b/src/PhpSpreadsheet/Reader/Xml.php index 7773e7ac..cfd18388 100644 --- a/src/PhpSpreadsheet/Reader/Xml.php +++ b/src/PhpSpreadsheet/Reader/Xml.php @@ -236,7 +236,7 @@ class Xml extends BaseReader implements IReader return $this->loadIntoExisting($pFilename, $spreadsheet); } - protected static function identifyFixedStyleValue($styleList, &$styleAttributeValue) + private static function identifyFixedStyleValue($styleList, &$styleAttributeValue) { $styleAttributeValue = strtolower($styleAttributeValue); foreach ($styleList as $style) { diff --git a/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php b/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php index 00842c79..3e59bddd 100644 --- a/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php +++ b/src/PhpSpreadsheet/Shared/JAMA/EigenvalueDecomposition.php @@ -31,13 +31,6 @@ class EigenvalueDecomposition */ private $n; - /** - * Internal symmetry flag. - * - * @var int - */ - private $issymmetric; - /** * Arrays for internal storage of eigenvalues. * diff --git a/src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php b/src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php index cab4afcd..cfac30b4 100644 --- a/src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php +++ b/src/PhpSpreadsheet/Shared/Trend/PolynomialBestFit.php @@ -122,9 +122,8 @@ class PolynomialBestFit extends BestFit * @param int $order Order of Polynomial 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 bool $const */ - private function polynomialRegression($order, $yValues, $xValues, $const) + private function polynomialRegression($order, $yValues, $xValues) { // calculate sums $x_sum = array_sum($xValues); @@ -156,7 +155,7 @@ class PolynomialBestFit extends BestFit $C = $matrixA->solve($matrixB); $coefficients = []; - for ($i = 0; $i < $C->m; ++$i) { + for ($i = 0; $i < $C->getRowDimension(); ++$i) { $r = $C->get($i, 0); if (abs($r) <= pow(10, -9)) { $r = 0; @@ -187,7 +186,7 @@ class PolynomialBestFit extends BestFit if ($order < $this->valueCount) { $this->bestFitType .= '_' . $order; $this->order = $order; - $this->polynomialRegression($order, $yValues, $xValues, $const); + $this->polynomialRegression($order, $yValues, $xValues); if (($this->getGoodnessOfFit() < 0.0) || ($this->getGoodnessOfFit() > 1.0)) { $this->_error = true; } diff --git a/src/PhpSpreadsheet/Style/Border.php b/src/PhpSpreadsheet/Style/Border.php index fdc251d7..bf405167 100644 --- a/src/PhpSpreadsheet/Style/Border.php +++ b/src/PhpSpreadsheet/Style/Border.php @@ -37,13 +37,6 @@ class Border extends Supervisor implements IComparable */ protected $color; - /** - * Parent property name. - * - * @var string - */ - protected $parentPropertyName; - /** * 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. * Only used for style supervisor. diff --git a/src/PhpSpreadsheet/Style/Color.php b/src/PhpSpreadsheet/Style/Color.php index e30916a7..d1c8410d 100644 --- a/src/PhpSpreadsheet/Style/Color.php +++ b/src/PhpSpreadsheet/Style/Color.php @@ -33,13 +33,6 @@ class Color extends Supervisor implements IComparable */ protected $argb; - /** - * Parent property name. - * - * @var string - */ - protected $parentPropertyName; - /** * 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. * Only used for style supervisor. diff --git a/src/PhpSpreadsheet/Style/NumberFormat.php b/src/PhpSpreadsheet/Style/NumberFormat.php index 119e15bf..3fc3696d 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat.php +++ b/src/PhpSpreadsheet/Style/NumberFormat.php @@ -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); $number = abs($number); if (strpos($mask, '.') !== false) { $numbers = explode('.', $number . '.0'); $masks = explode('.', $mask . '.0'); - $result1 = self::complexNumberFormatMask($numbers[0], $masks[0], 1); - $result2 = strrev(self::complexNumberFormatMask(strrev($numbers[1]), strrev($masks[1]), 1)); + $result1 = self::complexNumberFormatMask($numbers[0], $masks[0]); + $result2 = strrev(self::complexNumberFormatMask(strrev($numbers[1]), strrev($masks[1]))); return (($sign) ? '-' : '') . $result1 . '.' . $result2; } diff --git a/src/PhpSpreadsheet/Style/Supervisor.php b/src/PhpSpreadsheet/Style/Supervisor.php index a3b11a41..a82ab495 100644 --- a/src/PhpSpreadsheet/Style/Supervisor.php +++ b/src/PhpSpreadsheet/Style/Supervisor.php @@ -18,6 +18,13 @@ abstract class Supervisor */ protected $parent; + /** + * Parent property name. + * + * @var null|string + */ + protected $parentPropertyName; + /** * Create a new Supervisor. * @@ -35,13 +42,14 @@ abstract class Supervisor * Bind parent. Only used for supervisor. * * @param Style $parent - * @param null|mixed $parentPropertyName + * @param null|string $parentPropertyName * * @return Supervisor */ public function bindParent($parent, $parentPropertyName = null) { $this->parent = $parent; + $this->parentPropertyName = $parentPropertyName; return $this; } diff --git a/src/PhpSpreadsheet/Writer/Exception.php b/src/PhpSpreadsheet/Writer/Exception.php index 6dc4774e..92e6f5f4 100644 --- a/src/PhpSpreadsheet/Writer/Exception.php +++ b/src/PhpSpreadsheet/Writer/Exception.php @@ -6,21 +6,4 @@ use PhpOffice\PhpSpreadsheet\Exception as 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; - } } diff --git a/src/PhpSpreadsheet/Writer/Pdf/DomPDF.php b/src/PhpSpreadsheet/Writer/Pdf/DomPDF.php index d24caf81..0c4b39e9 100644 --- a/src/PhpSpreadsheet/Writer/Pdf/DomPDF.php +++ b/src/PhpSpreadsheet/Writer/Pdf/DomPDF.php @@ -53,9 +53,9 @@ class DomPDF extends Core implements IWriter // Create PDF $pdf = new \Dompdf\Dompdf(); - $pdf->set_paper(strtolower($paperSize), $orientation); + $pdf->setPaper(strtolower($paperSize), $orientation); - $pdf->load_html( + $pdf->loadHtml( $this->generateHTMLHeader(false) . $this->generateSheetData() . $this->generateHTMLFooter() diff --git a/src/PhpSpreadsheet/Writer/Xls/Parser.php b/src/PhpSpreadsheet/Writer/Xls/Parser.php index e9150bee..cad13c61 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Parser.php +++ b/src/PhpSpreadsheet/Writer/Xls/Parser.php @@ -734,50 +734,6 @@ class Parser 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 * (or range). If it doesn't exist yet add it to the workbook's references diff --git a/src/PhpSpreadsheet/Writer/Xls/Workbook.php b/src/PhpSpreadsheet/Writer/Xls/Workbook.php index 9666114d..ac0f1cbc 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Workbook.php +++ b/src/PhpSpreadsheet/Writer/Xls/Workbook.php @@ -527,114 +527,6 @@ class Workbook extends BIFFwriter $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). * 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); } - /** - * 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. * diff --git a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php index 387f94a4..222df5a6 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php @@ -682,43 +682,6 @@ class Worksheet extends BIFFwriter $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). * This is the BIFF8 version (no 255 chars limit). @@ -752,37 +715,6 @@ class Worksheet extends BIFFwriter $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). * 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. * The panes can either be frozen or thawed (unfrozen).