-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chart Dynamic Title and Special Font Properties (#3800)
* Chart Dynamic Title and Special Font Properties Fix #3797. Excel allows a Chart Title to be a formula, albeit a very rigidly limited one. It can only be a reference to a single cell, and the worksheet name must be specified, and the column and row must be absolute. Methods are added to Chart/Title to accommodate this (and styling for it). This will be handled for input/output for Xlsx, and for output for Html. The sample file which was submitted with this issue demonstrated that something else was missing. When setting the font for a chart title in Excel, you can specify all-caps or small-caps, options not available for most cell formatting. These are now added. The sample file also fell into the category of spreadsheets which lose one or more charts when converted to Html. I have redone the "extend rows and charts" logic in Html Writer. It is now clearer (I hope) and more efficient, and hopefully this problem will not arise again. * Scrutinizer 50/50 One false positive, one correct "unused parameter".
- Loading branch information
Showing
11 changed files
with
480 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.