Merge pull request #2830 from PHPOffice/ChartSheet
Read ChartSheets with the Xlsx Reader if includeCharts is enabled
This commit is contained in:
commit
4df236a688
|
|
@ -10,12 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
### Added
|
||||
|
||||
- Add point size option for scatter charts
|
||||
- Basic support for Xlsx reading/writing Chart Sheets [PR #2830](https://github.com/PHPOffice/PhpSpreadsheet/pull/2830)
|
||||
|
||||
Note that a ChartSheet is still only written as a normal Worksheet containing a single chart, not as an actual ChartSheet.
|
||||
|
||||
### Changed
|
||||
|
||||
- Memory and speed improvements, particularly for the Cell Collection, and the Writers.
|
||||
|
||||
See [the Discussion](https://github.com/PHPOffice/PhpSpreadsheet/discussions/2821) for details of performance
|
||||
See [the Discussion section on github](https://github.com/PHPOffice/PhpSpreadsheet/discussions/2821) for details of performance across versions
|
||||
|
||||
### Deprecated
|
||||
|
||||
|
|
|
|||
|
|
@ -1160,76 +1160,6 @@ parameters:
|
|||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:getBottomRightXOffset\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:getBottomRightYOffset\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:getTopLeftXOffset\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:getTopLeftYOffset\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setBottomRightCell\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setBottomRightCell\\(\\) has parameter \\$cell with no type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setBottomRightXOffset\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setBottomRightXOffset\\(\\) has parameter \\$xOffset with no type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setBottomRightYOffset\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setBottomRightYOffset\\(\\) has parameter \\$yOffset with no type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setTopLeftXOffset\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setTopLeftXOffset\\(\\) has parameter \\$xOffset with no type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setTopLeftYOffset\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:setTopLeftYOffset\\(\\) has parameter \\$yOffset with no type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Chart/Chart.php
|
||||
|
||||
-
|
||||
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart\\:\\:\\$legend \\(PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Legend\\) does not accept PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Legend\\|null\\.$#"
|
||||
count: 1
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ class Chart
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $bottomRightCellRef = 'A1';
|
||||
private $bottomRightCellRef = '';
|
||||
|
||||
/**
|
||||
* Bottom-Right X-Offset.
|
||||
|
|
@ -400,15 +400,15 @@ class Chart
|
|||
/**
|
||||
* Set the Top Left position for the chart.
|
||||
*
|
||||
* @param string $cell
|
||||
* @param string $cellAddress
|
||||
* @param int $xOffset
|
||||
* @param int $yOffset
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTopLeftPosition($cell, $xOffset = null, $yOffset = null)
|
||||
public function setTopLeftPosition($cellAddress, $xOffset = null, $yOffset = null)
|
||||
{
|
||||
$this->topLeftCellRef = $cell;
|
||||
$this->topLeftCellRef = $cellAddress;
|
||||
if ($xOffset !== null) {
|
||||
$this->setTopLeftXOffset($xOffset);
|
||||
}
|
||||
|
|
@ -446,13 +446,13 @@ class Chart
|
|||
/**
|
||||
* Set the Top Left cell position for the chart.
|
||||
*
|
||||
* @param string $cell
|
||||
* @param string $cellAddress
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTopLeftCell($cell)
|
||||
public function setTopLeftCell($cellAddress)
|
||||
{
|
||||
$this->topLeftCellRef = $cell;
|
||||
$this->topLeftCellRef = $cellAddress;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -491,6 +491,11 @@ class Chart
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $xOffset
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTopLeftXOffset($xOffset)
|
||||
{
|
||||
$this->topLeftXOffset = $xOffset;
|
||||
|
|
@ -498,11 +503,16 @@ class Chart
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getTopLeftXOffset()
|
||||
public function getTopLeftXOffset(): int
|
||||
{
|
||||
return $this->topLeftXOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $yOffset
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTopLeftYOffset($yOffset)
|
||||
{
|
||||
$this->topLeftYOffset = $yOffset;
|
||||
|
|
@ -510,7 +520,7 @@ class Chart
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getTopLeftYOffset()
|
||||
public function getTopLeftYOffset(): int
|
||||
{
|
||||
return $this->topLeftYOffset;
|
||||
}
|
||||
|
|
@ -518,15 +528,15 @@ class Chart
|
|||
/**
|
||||
* Set the Bottom Right position of the chart.
|
||||
*
|
||||
* @param string $cell
|
||||
* @param string $cellAddress
|
||||
* @param int $xOffset
|
||||
* @param int $yOffset
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBottomRightPosition($cell, $xOffset = null, $yOffset = null)
|
||||
public function setBottomRightPosition($cellAddress = '', $xOffset = null, $yOffset = null)
|
||||
{
|
||||
$this->bottomRightCellRef = $cell;
|
||||
$this->bottomRightCellRef = $cellAddress;
|
||||
if ($xOffset !== null) {
|
||||
$this->setBottomRightXOffset($xOffset);
|
||||
}
|
||||
|
|
@ -551,19 +561,22 @@ class Chart
|
|||
];
|
||||
}
|
||||
|
||||
public function setBottomRightCell($cell)
|
||||
/**
|
||||
* Set the Bottom Right cell for the chart.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBottomRightCell(string $cellAddress = '')
|
||||
{
|
||||
$this->bottomRightCellRef = $cell;
|
||||
$this->bottomRightCellRef = $cellAddress;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cell address where the bottom right of the chart is fixed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBottomRightCell()
|
||||
public function getBottomRightCell(): string
|
||||
{
|
||||
return $this->bottomRightCellRef;
|
||||
}
|
||||
|
|
@ -602,6 +615,11 @@ class Chart
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $xOffset
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBottomRightXOffset($xOffset)
|
||||
{
|
||||
$this->bottomRightXOffset = $xOffset;
|
||||
|
|
@ -609,11 +627,16 @@ class Chart
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getBottomRightXOffset()
|
||||
public function getBottomRightXOffset(): int
|
||||
{
|
||||
return $this->bottomRightXOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $yOffset
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setBottomRightYOffset($yOffset)
|
||||
{
|
||||
$this->bottomRightYOffset = $yOffset;
|
||||
|
|
@ -621,7 +644,7 @@ class Chart
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getBottomRightYOffset()
|
||||
public function getBottomRightYOffset(): int
|
||||
{
|
||||
return $this->bottomRightYOffset;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,7 +226,10 @@ class Xlsx extends BaseReader
|
|||
$worksheets = [];
|
||||
foreach ($relsWorkbook->Relationship as $elex) {
|
||||
$ele = self::getAttributes($elex);
|
||||
if ((string) $ele['Type'] === "$namespace/worksheet") {
|
||||
if (
|
||||
((string) $ele['Type'] === "$namespace/worksheet") ||
|
||||
((string) $ele['Type'] === "$namespace/chartsheet")
|
||||
) {
|
||||
$worksheets[(string) $ele['Id']] = $ele['Target'];
|
||||
}
|
||||
}
|
||||
|
|
@ -512,6 +515,12 @@ class Xlsx extends BaseReader
|
|||
case Namespaces::PURL_WORKSHEET:
|
||||
$worksheets[(string) $ele['Id']] = $ele['Target'];
|
||||
|
||||
break;
|
||||
case Namespaces::CHARTSHEET:
|
||||
if ($this->includeCharts === true) {
|
||||
$worksheets[(string) $ele['Id']] = $ele['Target'];
|
||||
}
|
||||
|
||||
break;
|
||||
// a vbaProject ? (: some macros)
|
||||
case Namespaces::VBA:
|
||||
|
|
@ -690,6 +699,13 @@ class Xlsx extends BaseReader
|
|||
continue;
|
||||
}
|
||||
|
||||
$sheetReferenceId = (string) self::getArrayItem(self::getAttributes($eleSheet, $xmlNamespaceBase), 'id');
|
||||
if (isset($worksheets[$sheetReferenceId]) === false) {
|
||||
++$countSkippedSheets;
|
||||
$mapSheetId[$oldSheetId] = null;
|
||||
|
||||
continue;
|
||||
}
|
||||
// Map old sheet id in original workbook to new sheet id.
|
||||
// They will differ if loadSheetsOnly() is being used
|
||||
$mapSheetId[$oldSheetId] = $oldSheetId - $countSkippedSheets;
|
||||
|
|
@ -701,7 +717,8 @@ class Xlsx extends BaseReader
|
|||
// and we're simply bringing the worksheet name in line with the formula, not the
|
||||
// reverse
|
||||
$docSheet->setTitle((string) $eleSheetAttr['name'], false, false);
|
||||
$fileWorksheet = (string) $worksheets[(string) self::getArrayItem(self::getAttributes($eleSheet, $xmlNamespaceBase), 'id')];
|
||||
|
||||
$fileWorksheet = (string) $worksheets[$sheetReferenceId];
|
||||
$xmlSheet = $this->loadZipNoNamespace("$dir/$fileWorksheet", $mainNS);
|
||||
$xmlSheetNS = $this->loadZip("$dir/$fileWorksheet", $mainNS);
|
||||
|
||||
|
|
@ -1195,6 +1212,7 @@ class Xlsx extends BaseReader
|
|||
$drawings[(string) $ele['Id']] = self::dirAdd("$dir/$fileWorksheet", $ele['Target']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($xmlSheet->drawing && !$this->readDataOnly) {
|
||||
$unparsedDrawings = [];
|
||||
$fileDrawing = null;
|
||||
|
|
@ -1203,6 +1221,7 @@ class Xlsx extends BaseReader
|
|||
$fileDrawing = $drawings[$drawingRelId];
|
||||
$drawingFilename = dirname($fileDrawing) . '/_rels/' . basename($fileDrawing) . '.rels';
|
||||
$relsDrawing = $this->loadZipNoNamespace($drawingFilename, $xmlNamespaceBase);
|
||||
|
||||
$images = [];
|
||||
$hyperlinks = [];
|
||||
if ($relsDrawing && $relsDrawing->Relationship) {
|
||||
|
|
@ -1223,6 +1242,7 @@ class Xlsx extends BaseReader
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$xmlDrawing = $this->loadZipNoNamespace($fileDrawing, '');
|
||||
$xmlDrawingChildren = $xmlDrawing->children(Namespaces::SPREADSHEET_DRAWING);
|
||||
|
||||
|
|
@ -1401,6 +1421,27 @@ class Xlsx extends BaseReader
|
|||
}
|
||||
}
|
||||
}
|
||||
if ($xmlDrawingChildren->absoluteAnchor) {
|
||||
foreach ($xmlDrawingChildren->absoluteAnchor as $absoluteAnchor) {
|
||||
if (($this->includeCharts) && ($absoluteAnchor->graphicFrame)) {
|
||||
$graphic = $absoluteAnchor->graphicFrame->children(Namespaces::DRAWINGML)->graphic;
|
||||
/** @var SimpleXMLElement $chartRef */
|
||||
$chartRef = $graphic->graphicData->children(Namespaces::CHART)->chart;
|
||||
$thisChart = (string) self::getAttributes($chartRef, $xmlNamespaceBase);
|
||||
$width = Drawing::EMUToPixels((int) self::getArrayItem(self::getAttributes($absoluteAnchor->ext), 'cx')[0]);
|
||||
$height = Drawing::EMUToPixels((int) self::getArrayItem(self::getAttributes($absoluteAnchor->ext), 'cy')[0]);
|
||||
|
||||
$chartDetails[$docSheet->getTitle() . '!' . $thisChart] = [
|
||||
'fromCoordinate' => 'A1',
|
||||
'fromOffsetX' => 0,
|
||||
'fromOffsetY' => 0,
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
'worksheetTitle' => $docSheet->getTitle(),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($relsDrawing) && $xmlDrawing->count() == 0) {
|
||||
// Save Drawing without rels and children as unparsed
|
||||
$unparsedDrawings[$drawingRelId] = $xmlDrawing->asXML();
|
||||
|
|
@ -1600,16 +1641,21 @@ class Xlsx extends BaseReader
|
|||
$chartEntryRef = ltrim((string) $contentType['PartName'], '/');
|
||||
$chartElements = $this->loadZip($chartEntryRef);
|
||||
$objChart = Chart::readChart($chartElements, basename($chartEntryRef, '.xml'));
|
||||
|
||||
if (isset($charts[$chartEntryRef])) {
|
||||
$chartPositionRef = $charts[$chartEntryRef]['sheet'] . '!' . $charts[$chartEntryRef]['id'];
|
||||
if (isset($chartDetails[$chartPositionRef])) {
|
||||
$excel->getSheetByName($charts[$chartEntryRef]['sheet'])->addChart($objChart);
|
||||
$objChart->setWorksheet($excel->getSheetByName($charts[$chartEntryRef]['sheet']));
|
||||
$objChart->setTopLeftPosition($chartDetails[$chartPositionRef]['fromCoordinate'], $chartDetails[$chartPositionRef]['fromOffsetX'], $chartDetails[$chartPositionRef]['fromOffsetY']);
|
||||
// For oneCellAnchor or absoluteAnchor positioned charts,
|
||||
// toCoordinate is not in the data. Does it need to be calculated?
|
||||
if (array_key_exists('toCoordinate', $chartDetails[$chartPositionRef])) {
|
||||
// For oneCellAnchor positioned charts, toCoordinate is not in the data. Does it need to be calculated?
|
||||
// twoCellAnchor
|
||||
$objChart->setTopLeftPosition($chartDetails[$chartPositionRef]['fromCoordinate'], $chartDetails[$chartPositionRef]['fromOffsetX'], $chartDetails[$chartPositionRef]['fromOffsetY']);
|
||||
$objChart->setBottomRightPosition($chartDetails[$chartPositionRef]['toCoordinate'], $chartDetails[$chartPositionRef]['toOffsetX'], $chartDetails[$chartPositionRef]['toOffsetY']);
|
||||
} else {
|
||||
// oneCellAnchor or absoluteAnchor (e.g. Chart sheet)
|
||||
$objChart->setTopLeftPosition($chartDetails[$chartPositionRef]['fromCoordinate'], $chartDetails[$chartPositionRef]['fromOffsetX'], $chartDetails[$chartPositionRef]['fromOffsetY']);
|
||||
$objChart->setBottomRightPosition('', $chartDetails[$chartPositionRef]['width'], $chartDetails[$chartPositionRef]['height']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ class Namespaces
|
|||
|
||||
const WORKSHEET = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet';
|
||||
|
||||
const CHARTSHEET = 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet';
|
||||
|
||||
const SCHEMA_MICROSOFT = 'http://schemas.microsoft.com/office/2006/relationships';
|
||||
|
||||
const EXTENSIBILITY = 'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility';
|
||||
|
|
|
|||
|
|
@ -89,22 +89,36 @@ class Drawing extends WriterPart
|
|||
$tl = $chart->getTopLeftPosition();
|
||||
$tlColRow = Coordinate::indexesFromString($tl['cell']);
|
||||
$br = $chart->getBottomRightPosition();
|
||||
$brColRow = Coordinate::indexesFromString($br['cell']);
|
||||
|
||||
$objWriter->startElement('xdr:twoCellAnchor');
|
||||
$isTwoCellAnchor = $br['cell'] !== '';
|
||||
if ($isTwoCellAnchor) {
|
||||
$brColRow = Coordinate::indexesFromString($br['cell']);
|
||||
|
||||
$objWriter->startElement('xdr:from');
|
||||
$objWriter->writeElement('xdr:col', (string) ($tlColRow[0] - 1));
|
||||
$objWriter->writeElement('xdr:colOff', self::stringEmu($tl['xOffset']));
|
||||
$objWriter->writeElement('xdr:row', (string) ($tlColRow[1] - 1));
|
||||
$objWriter->writeElement('xdr:rowOff', self::stringEmu($tl['yOffset']));
|
||||
$objWriter->endElement();
|
||||
$objWriter->startElement('xdr:to');
|
||||
$objWriter->writeElement('xdr:col', (string) ($brColRow[0] - 1));
|
||||
$objWriter->writeElement('xdr:colOff', self::stringEmu($br['xOffset']));
|
||||
$objWriter->writeElement('xdr:row', (string) ($brColRow[1] - 1));
|
||||
$objWriter->writeElement('xdr:rowOff', self::stringEmu($br['yOffset']));
|
||||
$objWriter->endElement();
|
||||
$objWriter->startElement('xdr:twoCellAnchor');
|
||||
|
||||
$objWriter->startElement('xdr:from');
|
||||
$objWriter->writeElement('xdr:col', (string) ($tlColRow[0] - 1));
|
||||
$objWriter->writeElement('xdr:colOff', self::stringEmu($tl['xOffset']));
|
||||
$objWriter->writeElement('xdr:row', (string) ($tlColRow[1] - 1));
|
||||
$objWriter->writeElement('xdr:rowOff', self::stringEmu($tl['yOffset']));
|
||||
$objWriter->endElement();
|
||||
$objWriter->startElement('xdr:to');
|
||||
$objWriter->writeElement('xdr:col', (string) ($brColRow[0] - 1));
|
||||
$objWriter->writeElement('xdr:colOff', self::stringEmu($br['xOffset']));
|
||||
$objWriter->writeElement('xdr:row', (string) ($brColRow[1] - 1));
|
||||
$objWriter->writeElement('xdr:rowOff', self::stringEmu($br['yOffset']));
|
||||
$objWriter->endElement();
|
||||
} else {
|
||||
$objWriter->startElement('xdr:absoluteAnchor');
|
||||
$objWriter->startElement('xdr:pos');
|
||||
$objWriter->writeAttribute('x', '0');
|
||||
$objWriter->writeAttribute('y', '0');
|
||||
$objWriter->endElement();
|
||||
$objWriter->startElement('xdr:ext');
|
||||
$objWriter->writeAttribute('cx', self::stringEmu($br['xOffset']));
|
||||
$objWriter->writeAttribute('cy', self::stringEmu($br['yOffset']));
|
||||
$objWriter->endElement();
|
||||
}
|
||||
|
||||
$objWriter->startElement('xdr:graphicFrame');
|
||||
$objWriter->writeAttribute('macro', '');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ChartSheetTest extends TestCase
|
||||
{
|
||||
public function testLoadChartSheetWithCharts(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLSX/ChartSheet.xlsx';
|
||||
$reader = new Xlsx();
|
||||
$reader->setIncludeCharts(true);
|
||||
$spreadsheet = $reader->load($filename);
|
||||
|
||||
self::assertCount(2, $spreadsheet->getAllSheets());
|
||||
$chartSheet = $spreadsheet->getSheetByName('Chart1');
|
||||
self::assertInstanceOf(Worksheet::class, $chartSheet);
|
||||
self::assertSame(1, $chartSheet->getChartCount());
|
||||
}
|
||||
|
||||
public function testLoadChartSheetWithoutCharts(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLSX/ChartSheet.xlsx';
|
||||
$reader = new Xlsx();
|
||||
$reader->setIncludeCharts(false);
|
||||
$spreadsheet = $reader->load($filename);
|
||||
|
||||
self::assertCount(1, $spreadsheet->getAllSheets());
|
||||
$chartSheet = $spreadsheet->getSheetByName('Chart1');
|
||||
self::assertNull($chartSheet);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,4 +77,29 @@ class WorksheetInfoNamesTest extends TestCase
|
|||
|
||||
self::assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testListWorksheetNamesChartSheet(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLSX/ChartSheet.xlsx';
|
||||
$reader = new Xlsx();
|
||||
$actual = $reader->listWorksheetNames($filename);
|
||||
|
||||
$expected = ['Sheet1', 'Chart1'];
|
||||
|
||||
self::assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testListWorksheetInfoChartSheet(): void
|
||||
{
|
||||
$filename = 'tests/data/Reader/XLSX/ChartSheet.xlsx';
|
||||
$reader = new Xlsx();
|
||||
$actual = $reader->listWorksheetInfo($filename);
|
||||
|
||||
$chartSheetInfo = $actual[1];
|
||||
|
||||
self::assertSame('Chart1', $chartSheetInfo['worksheetName']);
|
||||
self::assertSame(-1, $chartSheetInfo['lastColumnIndex']);
|
||||
self::assertSame(0, $chartSheetInfo['totalRows']);
|
||||
self::assertSame(0, $chartSheetInfo['totalColumns']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue