Skip to content

Commit

Permalink
Merge branch 'master' into issue731
Browse files Browse the repository at this point in the history
  • Loading branch information
oleibman authored Nov 30, 2023
2 parents 9f27d5a + 009e009 commit ea55d7b
Show file tree
Hide file tree
Showing 17 changed files with 544 additions and 188 deletions.
92 changes: 46 additions & 46 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Cannot call method getTokenSubType\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\FormulaToken\\|null\\.$#"
count: 4
path: src/PhpSpreadsheet/Calculation/FormulaParser.php

-
message: "#^Cannot call method getTokenType\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\FormulaToken\\|null\\.$#"
count: 8
path: src/PhpSpreadsheet/Calculation/FormulaParser.php

-
message: "#^Binary operation \"/\" between float and array\\|float\\|int\\|string results in an error\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/MathTrig/Combinations.php

-
message: "#^Offset 2 does not exist on array\\{int, int, int, int\\}\\|array\\{int, int\\}\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/Validations.php

-
message: "#^Offset 3 does not exist on array\\{int, int, int, int\\}\\|array\\{int, int\\}\\.$#"
count: 1
path: src/PhpSpreadsheet/Worksheet/Validations.php

-
message: "#^Parameter \\#2 \\$value of function ini_set expects string, int given\\.$#"
count: 1
path: tests/bootstrap.php
2 changes: 1 addition & 1 deletion samples/Chart/32_Chart_read_write.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
foreach ($chartNames as $i => $chartName) {
$chart = $worksheet->getChartByName($chartName);
if ($chart->getTitle() !== null) {
$caption = '"' . implode(' ', $chart->getTitle()->getCaption()) . '"';
$caption = '"' . $chart->getTitle()->getCaptionText($spreadsheet) . '"';
} else {
$caption = 'Untitled';
}
Expand Down
83 changes: 83 additions & 0 deletions samples/Chart/37_Chart_dynamic_title.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Settings;

require __DIR__ . '/../Header.php';

$inputFileType = 'Xlsx';
$inputFileName = __DIR__ . '/../templates/37dynamictitle.xlsx';
var_dump($inputFileName);
var_dump(realpath($inputFileName));
$inputFileNames = [$inputFileName];

foreach ($inputFileNames as $inputFileName) {
$inputFileNameShort = basename($inputFileName);

if (!file_exists($inputFileName)) {
$helper->log('File ' . $inputFileNameShort . ' does not exist');

continue;
}
$reader = IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true);
$callStartTime = microtime(true);
$spreadsheet = $reader->load($inputFileName);
$helper->logRead($inputFileType, $inputFileName, $callStartTime);

$helper->log('Iterate worksheets looking at the charts');
foreach ($spreadsheet->getWorksheetIterator() as $worksheet) {
$sheetName = $worksheet->getTitle();
$worksheet->getCell('A1')->setValue('Changed Title');
$helper->log('Worksheet: ' . $sheetName);

$chartNames = $worksheet->getChartNames();
if (empty($chartNames)) {
$helper->log(' There are no charts in this worksheet');
} else {
natsort($chartNames);
foreach ($chartNames as $i => $chartName) {
$chart = $worksheet->getChartByName($chartName);
if ($chart->getTitle() !== null) {
$caption = '"' . $chart->getTitle()->getCaptionText($spreadsheet) . '"';
} else {
$caption = 'Untitled';
}
$helper->log(' ' . $chartName . ' - ' . $caption);
$indentation = str_repeat(' ', strlen($chartName) + 3);
$groupCount = $chart->getPlotArea()->getPlotGroupCount();
if ($groupCount == 1) {
$chartType = $chart->getPlotArea()->getPlotGroupByIndex(0)->getPlotType();
$helper->log($indentation . ' ' . $chartType);
$helper->renderChart($chart, __FILE__, $spreadsheet);
} else {
$chartTypes = [];
for ($i = 0; $i < $groupCount; ++$i) {
$chartTypes[] = $chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
}
$chartTypes = array_unique($chartTypes);
if (count($chartTypes) == 1) {
$chartType = 'Multiple Plot ' . array_pop($chartTypes);
$helper->log($indentation . ' ' . $chartType);
$helper->renderChart($chart, __FILE__);
} elseif (count($chartTypes) == 0) {
$helper->log($indentation . ' *** Type not yet implemented');
} else {
$helper->log($indentation . ' Combination Chart');
$helper->renderChart($chart, __FILE__);
}
}
}
}
}

$callStartTime = microtime(true);
$helper->write($spreadsheet, $inputFileName, ['Xlsx'], true);

Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\MtJpGraphRenderer::class);
$callStartTime = microtime(true);
$helper->write($spreadsheet, $inputFileName, ['Html'], true);

$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
}
Binary file added samples/templates/37dynamictitle.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Calculation/Calculation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4715,7 +4715,7 @@ private function processTokenStack(mixed $tokens, $cellID = null, ?Cell $cell =
if (($operand2Data = $stack->pop()) === null) {
return $this->raiseFormulaError('Internal error - Operand value missing from stack');
}
if (($operand1Data = $stack->pop()) === null) {
if (($operand1Data = $stack->pop()) === null) { // @phpstan-ignore-line
return $this->raiseFormulaError('Internal error - Operand value missing from stack');
}

Expand Down
24 changes: 12 additions & 12 deletions src/PhpSpreadsheet/Calculation/FormulaParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,12 @@ private function parseToTokens(): void
if ($i == 0) {
$token->setTokenType(FormulaToken::TOKEN_TYPE_OPERATORPREFIX);
} elseif (
(($previousToken->getTokenType() == FormulaToken::TOKEN_TYPE_FUNCTION)
&& ($previousToken->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_STOP))
|| (($previousToken->getTokenType() == FormulaToken::TOKEN_TYPE_SUBEXPRESSION)
&& ($previousToken->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_STOP))
|| ($previousToken->getTokenType() == FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX)
|| ($previousToken->getTokenType() == FormulaToken::TOKEN_TYPE_OPERAND)
(($previousToken?->getTokenType() == FormulaToken::TOKEN_TYPE_FUNCTION)
&& ($previousToken?->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_STOP))
|| (($previousToken?->getTokenType() == FormulaToken::TOKEN_TYPE_SUBEXPRESSION)
&& ($previousToken?->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_STOP))
|| ($previousToken?->getTokenType() == FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX)
|| ($previousToken?->getTokenType() == FormulaToken::TOKEN_TYPE_OPERAND)
) {
$token->setTokenSubType(FormulaToken::TOKEN_SUBTYPE_MATH);
} else {
Expand All @@ -551,12 +551,12 @@ private function parseToTokens(): void
if ($i == 0) {
continue;
} elseif (
(($previousToken->getTokenType() == FormulaToken::TOKEN_TYPE_FUNCTION)
&& ($previousToken->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_STOP))
|| (($previousToken->getTokenType() == FormulaToken::TOKEN_TYPE_SUBEXPRESSION)
&& ($previousToken->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_STOP))
|| ($previousToken->getTokenType() == FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX)
|| ($previousToken->getTokenType() == FormulaToken::TOKEN_TYPE_OPERAND)
(($previousToken?->getTokenType() == FormulaToken::TOKEN_TYPE_FUNCTION)
&& ($previousToken?->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_STOP))
|| (($previousToken?->getTokenType() == FormulaToken::TOKEN_TYPE_SUBEXPRESSION)
&& ($previousToken?->getTokenSubType() == FormulaToken::TOKEN_SUBTYPE_STOP))
|| ($previousToken?->getTokenType() == FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX)
|| ($previousToken?->getTokenType() == FormulaToken::TOKEN_TYPE_OPERAND)
) {
$token->setTokenSubType(FormulaToken::TOKEN_SUBTYPE_MATH);
} else {
Expand Down
Loading

0 comments on commit ea55d7b

Please sign in to comment.