repo
stringlengths
7
63
file_url
stringlengths
81
284
file_path
stringlengths
5
200
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:02:33
2026-01-05 05:24:06
truncated
bool
2 classes
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/ShadowPresetsTest.php
tests/PhpSpreadsheetTests/Chart/ShadowPresetsTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\GridLines; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PHPUnit\Framework\TestCase; class ShadowPresetsTest extends TestCase { public function testGridlineShadowPresets(): void { $gridlines = new GridLines(); $gridlines->setShadowProperties(17); $expectedShadow = [ 'effect' => 'innerShdw', 'distance' => 4, 'direction' => 270, 'blur' => 5, ]; foreach ($expectedShadow as $key => $value) { self::assertEquals($gridlines->getShadowProperty($key), $value, $key); } } public function testGridlineShadowPresetsWithArray(): void { $gridlines = new GridLines(); $gridlines->setShadowProperties(20); $expectedShadow = [ 'effect' => 'outerShdw', 'blur' => 6, 'direction' => 315, 'size' => [ 'sx' => null, 'sy' => 0.23, 'kx' => -20, 'ky' => null, ], 'algn' => 'bl', 'rotWithShape' => '0', ]; foreach ($expectedShadow as $key => $value) { self::assertEquals($gridlines->getShadowProperty($key), $value, $key); } } public function testAxisShadowPresets(): void { $axis = new Axis(); $axis->setShadowProperties(9); $expectedShadow = [ 'effect' => 'outerShdw', 'blur' => 4, 'distance' => 3, 'direction' => 225, 'algn' => 'br', 'rotWithShape' => '0', ]; foreach ($expectedShadow as $key => $value) { self::assertEquals($axis->getShadowProperty($key), $value, $key); } } public function testAxisShadowPresetsWithChanges(): void { $axis = new Axis(); $axis->setShadowProperties( 9, // preset 'FF0000', // colorValue 'srgbClr', // colorType 20, // alpha 6, // blur 30, // direction 4, // distance ); $expectedShadow = [ 'effect' => 'outerShdw', 'blur' => 6, 'distance' => 4, 'direction' => 30, 'algn' => 'br', 'rotWithShape' => '0', 'color' => [ 'value' => 'FF0000', 'type' => 'srgbClr', 'alpha' => 20, ], ]; foreach ($expectedShadow as $key => $value) { self::assertEquals($axis->getShadowProperty($key), $value, $key); } } public function testGridlinesShadowPresetsWithChanges(): void { $gridline = new GridLines(); $gridline->setShadowProperties( 9, // preset 'FF0000', // colorValue 'srgbClr', // colorType 20, // alpha 6, // blur 30, // direction 4, // distance ); $expectedShadow = [ 'effect' => 'outerShdw', 'blur' => 6, 'distance' => 4, 'direction' => 30, 'algn' => 'br', 'rotWithShape' => '0', 'color' => [ 'value' => 'FF0000', 'type' => 'srgbClr', 'alpha' => 20, ], ]; foreach ($expectedShadow as $key => $value) { self::assertEquals($gridline->getShadowProperty($key), $value, $key); } } public function testPreset0(): void { $axis = new Axis(); $axis->setShadowProperties(0); $expectedShadow = [ 'presets' => Properties::SHADOW_PRESETS_NOSHADOW, 'effect' => null, 'color' => [ 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD, 'value' => 'black', 'alpha' => 40, ], 'size' => [ 'sx' => null, 'sy' => null, 'kx' => null, 'ky' => null, ], 'blur' => null, 'direction' => null, 'distance' => null, 'algn' => null, 'rotWithShape' => null, ]; foreach ($expectedShadow as $key => $value) { self::assertEquals($value, $axis->getShadowProperty($key), $key); } } public function testOutOfRangePresets(): void { $axis = new Axis(); $axis->setShadowProperties(99); $expectedShadow = [ 'presets' => Properties::SHADOW_PRESETS_NOSHADOW, 'effect' => null, 'color' => [ 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD, 'value' => 'black', 'alpha' => 40, ], 'size' => [ 'sx' => null, 'sy' => null, 'kx' => null, 'ky' => null, ], 'blur' => null, 'direction' => null, 'distance' => null, 'algn' => null, 'rotWithShape' => null, ]; foreach ($expectedShadow as $key => $value) { self::assertEquals($value, $axis->getShadowProperty($key), $key); } } public function testOutOfRangeGridlines(): void { $gridline = new GridLines(); $gridline->setShadowProperties(99); $expectedShadow = [ 'presets' => Properties::SHADOW_PRESETS_NOSHADOW, 'effect' => null, 'color' => [ 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD, 'value' => 'black', 'alpha' => 40, ], 'size' => [ 'sx' => null, 'sy' => null, 'kx' => null, 'ky' => null, ], 'blur' => null, 'direction' => null, 'distance' => null, 'algn' => null, 'rotWithShape' => null, ]; foreach ($expectedShadow as $key => $value) { self::assertEquals($value, $gridline->getShadowProperty($key), $key); } } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/ColorTest.php
tests/PhpSpreadsheetTests/Chart/ColorTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PHPUnit\Framework\TestCase; class ColorTest extends TestCase { public function testDefaultTypes(): void { $color = new ChartColor('800000'); self::assertSame('srgbClr', $color->getType()); self::assertSame('800000', $color->getValue()); $color->setColorProperties('*accent1'); self::assertSame('schemeClr', $color->getType()); self::assertSame('accent1', $color->getValue()); $color->setColorProperties('/red'); self::assertSame('prstClr', $color->getType()); self::assertSame('red', $color->getValue()); } public function testDataSeriesValues(): void { $dsv = new DataSeriesValues(); $dsv->setFillColor([new ChartColor(), new ChartColor()]); self::assertSame(['', ''], $dsv->getFillColor()); $dsv->setFillColor('cccccc'); self::assertSame('cccccc', $dsv->getFillColor()); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Charts32DsvLabelsTest.php
tests/PhpSpreadsheetTests/Chart/Charts32DsvLabelsTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class Charts32DsvLabelsTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testBar4(): void { $file = self::DIRECTORY . '32readwriteBarChart4.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $dataSeriesArray = $plotArea->getPlotGroup(); self::assertCount(1, $dataSeriesArray); $dataSeries = $dataSeriesArray[0]; $dataSeriesValuesArray = $dataSeries->getPlotValues(); self::assertCount(1, $dataSeriesValuesArray); $dataSeriesValues = $dataSeriesValuesArray[0]; $layout = $dataSeriesValues->getLabelLayout(); self::assertNotNull($layout); self::assertTrue($layout->getShowVal()); $fillColor = $layout->getLabelFillColor(); self::assertNotNull($fillColor); self::assertSame('schemeClr', $fillColor->getType()); self::assertSame('accent1', $fillColor->getValue()); $borderColor = $layout->getLabelBorderColor(); self::assertNotNull($borderColor); self::assertSame('srgbClr', $borderColor->getType()); self::assertSame('FFC000', $borderColor->getValue()); $fontColor = $layout->getLabelFontColor(); self::assertNotNull($fontColor); self::assertSame('srgbClr', $fontColor->getType()); self::assertSame('FFFF00', $fontColor->getValue()); self::assertEquals( [15, 73, 61, 32], $dataSeriesValues->getDataValues() ); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/AxisShadowTest.php
tests/PhpSpreadsheetTests/Chart/AxisShadowTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class AxisShadowTest extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testGlowY(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_AREACHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel // yAxisLabel ); $yAxis = $chart->getChartAxisY(); $expectedY = [ 'effect' => 'outerShdw', 'algn' => 'tl', 'blur' => 5, 'direction' => 45, 'distance' => 3, 'rotWithShape' => 0, 'color' => [ 'type' => ChartColor::EXCEL_COLOR_TYPE_STANDARD, 'value' => 'black', 'alpha' => 40, ], ]; foreach ($expectedY as $key => $value) { $yAxis->setShadowProperty($key, $value); } foreach ($expectedY as $key => $value) { self::assertEquals($value, $yAxis->getShadowProperty($key), $key); } $xAxis = $chart->getChartAxisX(); $expectedX = [ 'effect' => 'outerShdw', 'algn' => 'bl', 'blur' => 6, 'direction' => 315, 'distance' => 3, 'rotWithShape' => 0, 'size' => [ 'sx' => null, 'sy' => 254, 'kx' => -94, 'ky' => null, ], 'color' => [ 'type' => ChartColor::EXCEL_COLOR_TYPE_RGB, 'value' => 'FF0000', 'alpha' => 20, ], ]; foreach ($expectedX as $key => $value) { $xAxis->setShadowProperty($key, $value); } foreach ($expectedX as $key => $value) { self::assertEquals($value, $xAxis->getShadowProperty($key), $key); } // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $yAxis2 = $chart2->getChartAxisY(); foreach ($expectedY as $key => $value) { self::assertEquals($value, $yAxis2->getShadowProperty($key), $key); } $xAxis2 = $chart2->getChartAxisX(); foreach ($expectedX as $key => $value) { self::assertEquals($value, $xAxis2->getShadowProperty($key), $key); } $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/TitleTest.php
tests/PhpSpreadsheetTests/Chart/TitleTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class TitleTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testTitleHasCenteredOverlay(): void { $file = self::DIRECTORY . 'chart-with-and-without-overlays.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheetName = 'With Overlay'; $sheet = $spreadsheet->getSheetByName($sheetName); self::assertNotNull($sheet); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheetByName($sheetName); self::assertNotNull($sheet); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $title = $chart->getTitle(); self::assertNotNull($title); self::assertTrue($title->getOverlay()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testTitleIsAboveChart(): void { $file = self::DIRECTORY . 'chart-with-and-without-overlays.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheetName = 'Without Overlay'; $sheet = $spreadsheet->getSheetByName($sheetName); self::assertNotNull($sheet); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheetByName($sheetName); self::assertNotNull($sheet); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $title = $chart->getTitle(); self::assertNotNull($title); self::assertFalse($title->getOverlay()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testString(): void { $title = new Title('hello'); self::assertSame('hello', $title->getCaption()); self::assertSame('hello', $title->getCaptionText()); } public function testStringArray(): void { $title = new Title(); $title->setCaption(['Hello', ', ', 'world.']); self::assertSame('Hello, world.', $title->getCaptionText()); } public function testRichText(): void { $title = new Title(); $richText = new RichText(); $part = $richText->createTextRun('Hello'); $font = $part->getFont(); if ($font === null) { self::fail('Unable to retrieve font'); } else { $font->setBold(true); $title->setCaption($richText); self::assertSame('Hello', $title->getCaptionText()); } } public function testMixedArray(): void { $title = new Title(); $richText1 = new RichText(); $part1 = $richText1->createTextRun('Hello'); $font1 = $part1->getFont(); $richText2 = new RichText(); $part2 = $richText2->createTextRun('world'); $font2 = $part2->getFont(); if ($font1 === null || $font2 === null) { self::fail('Unable to retrieve font'); } else { $font1->setBold(true); $font2->setItalic(true); $title->setCaption([$richText1, ', ', $richText2, '.']); self::assertSame('Hello, world.', $title->getCaptionText()); } } public function testSetOverlay(): void { $overlayValues = [ true, false, ]; $testInstance = new Title(); foreach ($overlayValues as $overlayValue) { $testInstance->setOverlay($overlayValue); self::assertSame($overlayValue, $testInstance->getOverlay()); } } public function testGetOverlay(): void { $overlayValue = true; $testInstance = new Title(); $testInstance->setOverlay($overlayValue); $result = $testInstance->getOverlay(); self::assertEquals($overlayValue, $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue3397Test.php
tests/PhpSpreadsheetTests/Chart/Issue3397Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Layout; use PhpOffice\PhpSpreadsheet\Chart\Legend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PHPUnit\Framework\TestCase; class Issue3397Test extends TestCase { public function testPreliminaries(): void { // Issue 3397, writing srgbClr for label fill in wrong place $spreadsheet = new Spreadsheet(); $dataSheet = $spreadsheet->getActiveSheet(); $dataSheet->setTitle('Summary_report'); $label1 = 'Before 10 a.m.'; $label2 = 'Between 10 a.m. and 2 p.m.'; $label3 = 'After 2 p.m.'; $dataSheet->getCell('D8')->setValue($label1); $dataSheet->getCell('D9')->setValue($label2); $dataSheet->getCell('D10')->setValue($label3); $dataSheet->getCell('E7')->setValue(100); $dataSheet->getCell('E8')->setValue(101); $dataSheet->getCell('E9')->setValue(102); $dataSheet->getCell('E10')->setValue(103); $dataSheet->getCell('F7')->setValue(200); $dataSheet->getCell('F8')->setValue(201); $dataSheet->getCell('F9')->setValue(202); $dataSheet->getCell('F10')->setValue(203); $dataSheet->getCell('G7')->setValue(300); $dataSheet->getCell('G8')->setValue(301); $dataSheet->getCell('G9')->setValue(302); $dataSheet->getCell('G10')->setValue(303); $dataSheet->getCell('H7')->setValue(400); $dataSheet->getCell('H8')->setValue(401); $dataSheet->getCell('H9')->setValue(402); $dataSheet->getCell('H10')->setValue(403); $dataSheet->getCell('I7')->setValue(500); $dataSheet->getCell('I8')->setValue(501); $dataSheet->getCell('I9')->setValue(502); $dataSheet->getCell('I10')->setValue(503); $dataSheet->getCell('J7')->setValue(600); $dataSheet->getCell('J8')->setValue(601); $dataSheet->getCell('J9')->setValue(602); $dataSheet->getCell('J10')->setValue(603); $sheet = $spreadsheet->createSheet(); $sheet->setTitle('Chart'); $col = 'J'; $colNumber = 7; $dataSeriesLabels = [ new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_STRING, // label is string 'Summary_report!$D$8', // data source null, // format code 1, // point count null, // label values come from data source null, // marker 'ff0000' // rgb fill color ), new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_STRING, // label is string 'Summary_report!$D$9', // data source null, // format code 1, // point count null, // label values come from data source null, // marker '70ad47' // rgb fill color ), new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_STRING, // label is string 'Summary_report!$D$10', // data source null, // format code 1, // point count null, // label values come from data source null, // marker 'ffff00' // rgb fill color ), ]; $xAxisTickValues = [ new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_STRING, 'Summary_report!$E$7:$' . $col . '$7', null, $colNumber ), ]; $dataSeriesValues = [ new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Summary_report!$E$8:$' . $col . '$8', null, $colNumber ), new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Summary_report!$E$9:$' . $col . '$9', null, $colNumber ), new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Summary_report!$E$10:$' . $col . '$10', null, $colNumber ), ]; $series = new DataSeries( DataSeries::TYPE_BARCHART, // plotType DataSeries::GROUPING_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); $layout1 = new Layout(); $layout1->setShowVal(true); $plotArea = new PlotArea($layout1, [$series]); $legend = new Legend(Legend::POSITION_BOTTOM, null, false); $title = new Title('Submission Report'); $yAxisLabel = new Title('Count'); $xAxisLabel = new Title('period'); $yaxis = new Axis(); $yaxis->setAxisOptionsProperties('low'); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly 'gap', // displayBlanksAs $xAxisLabel, // xAxisLabel $yAxisLabel, // yAxisLabel null, $yaxis ); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $sheet->addChart($chart); $writer = new Xlsx($spreadsheet); $writer->setIncludeCharts(true); $outputFilename = File::temporaryFilename(); $writer->save($outputFilename); $spreadsheet->disconnectWorksheets(); $file = 'zip://'; $file .= $outputFilename; $file .= '#xl/charts/chart1.xml'; $data = file_get_contents($file); unlink($outputFilename); // confirm that file contains expected namespaced xml tag if ($data === false) { self::fail('Unable to read file'); } else { self::assertStringContainsString('<c:tx><c:strRef><c:f>Summary_report!$D$8</c:f><c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>Before 10 a.m.</c:v></c:pt></c:strCache></c:strRef></c:tx><c:spPr><a:solidFill><a:srgbClr val="ff0000"/></a:solidFill><a:ln/></c:spPr>', $data); self::assertStringContainsString('<c:tx><c:strRef><c:f>Summary_report!$D$9</c:f><c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>Between 10 a.m. and 2 p.m.</c:v></c:pt></c:strCache></c:strRef></c:tx><c:spPr><a:solidFill><a:srgbClr val="70ad47"/></a:solidFill><a:ln/></c:spPr>', $data); self::assertStringContainsString('<c:tx><c:strRef><c:f>Summary_report!$D$10</c:f><c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>After 2 p.m.</c:v></c:pt></c:strCache></c:strRef></c:tx><c:spPr><a:solidFill><a:srgbClr val="ffff00"/></a:solidFill><a:ln/></c:spPr>', $data); } } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue2931Test.php
tests/PhpSpreadsheetTests/Chart/Issue2931Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PHPUnit\Framework\TestCase; class Issue2931Test extends TestCase { public function testSurface(): void { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['5-6']), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['6-7']), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, null, null, 1, ['7-8']), ]; $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9]), ]; $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 6, 6, 6, 5.9, 6, 6]), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 6.5, 7, 7, 7, 7, 7]), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 9, [6, 6, 6, 7, 8, 8, 8, 8, 7.9]), ]; $series = new DataSeries( DataSeries::TYPE_SURFACECHART, DataSeries::GROUPING_STANDARD, // grouping should not be written for surface chart range(0, count($dataSeriesValues) - 1), $dataSeriesLabels, $xAxisTickValues, $dataSeriesValues, null, // plotDirection false, // smooth line DataSeries::STYLE_LINEMARKER // plotStyle ); $plotArea = new PlotArea(null, [$series]); $legend = new ChartLegend(ChartLegend::POSITION_BOTTOM, null, false); $title = new Title('График распредления температур в пределах кр'); $chart = new Chart( 'chart2', $title, $legend, $plotArea, true, DataSeries::EMPTY_AS_GAP, ); $chart->setTopLeftPosition('$A$1'); $chart->setBottomRightPosition('$P$20'); $sheet->addChart($chart); $writer = new XlsxWriter($spreadsheet); $writer->setIncludeCharts(true); $writer = new XlsxWriter($spreadsheet); $writer->setIncludeCharts(true); $writerChart = new XlsxWriter\Chart($writer); $data = $writerChart->writeChart($chart); // rotX etc. should be generated for surfaceChart 2D // even when unspecified. $expectedXml2D = [ '<c:view3D><c:rotX val="90"/><c:rotY val="0"/><c:rAngAx val="0"/><c:perspective val="0"/></c:view3D>', ]; $expectedXml3D = [ '<c:view3D/>', ]; $expectedXmlNoX = [ 'c:grouping', ]; // confirm that file contains expected tags foreach ($expectedXml2D as $expected) { self::assertSame(1, substr_count($data, $expected), $expected); } foreach ($expectedXmlNoX as $expected) { self::assertSame(0, substr_count($data, $expected), $expected); } $series->setPlotType(DataSeries::TYPE_SURFACECHART_3D); $plotArea = new PlotArea(null, [$series]); $chart->setPlotArea($plotArea); $writerChart = new XlsxWriter\Chart($writer); $data = $writerChart->writeChart($chart); // confirm that file contains expected tags foreach ($expectedXml3D as $expected) { self::assertSame(1, substr_count($data, $expected), $expected); } foreach ($expectedXmlNoX as $expected) { self::assertSame(0, substr_count($data, $expected), $expected); } $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/PieFillTest.php
tests/PhpSpreadsheetTests/Chart/PieFillTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Layout; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class PieFillTest extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testPieFill(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Custom colors for dataSeries (gray, blue, red, orange) $colors = [ 'cccccc', '*accent1', // use schemeClr, was '00abb8', '/green', // use prstClr, was 'b8292f', 'eb8500', ]; // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels1 = [ new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1 ), // 2011 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues1 = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker // Custom Colors $dataSeriesValues1Element = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4); $dataSeriesValues1Element->setFillColor($colors); $dataSeriesValues1 = [$dataSeriesValues1Element]; // Build the dataseries $series1 = new DataSeries( DataSeries::TYPE_PIECHART, // plotType null, // plotGrouping (Pie charts don't have any grouping) range(0, count($dataSeriesValues1) - 1), // plotOrder $dataSeriesLabels1, // plotLabel $xAxisTickValues1, // plotCategory $dataSeriesValues1 // plotValues ); // Set up a layout object for the Pie chart $layout1 = new Layout(); $layout1->setShowVal(true); $layout1->setShowPercent(true); // Set the series in the plot area $plotArea1 = new PlotArea($layout1, [$series1]); // Set the chart legend $legend1 = new ChartLegend(ChartLegend::POSITION_RIGHT, null, false); $title1 = new Title('Test Pie Chart'); // Create the chart $chart1 = new Chart( 'chart1', // name $title1, // title $legend1, // legend $plotArea1, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel null // no Y-Axis for Pie Chart ); // Set the position where the chart should appear in the worksheet $chart1->setTopLeftPosition('A7'); $chart1->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart1); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $plotArea2 = $chart2->getPlotArea(); self::assertNotNull($plotArea2); $dataSeries2 = $plotArea2->getPlotGroup(); self::assertCount(1, $dataSeries2); $plotValues = $dataSeries2[0]->getPlotValues(); self::assertCount(1, $plotValues); $fillColors = $plotValues[0]->getFillColor(); self::assertSame($colors, $fillColors); $writer = new XlsxWriter($reloadedSpreadsheet); $writer->setIncludeCharts(true); $writerChart = new XlsxWriter\Chart($writer); $data = $writerChart->writeChart($chart2); self::assertSame(1, substr_count($data, '<a:srgbClr val="cccccc"/>')); self::assertSame(1, substr_count($data, '<a:schemeClr val="accent1"/>')); self::assertSame(1, substr_count($data, '<a:prstClr val="green"/>')); self::assertSame(1, substr_count($data, '<a:srgbClr val="eb8500"/>')); self::assertSame(4, substr_count($data, '<c:dPt>')); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue2506Test.php
tests/PhpSpreadsheetTests/Chart/Issue2506Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class Issue2506Test extends AbstractFunctional { private const DIRECTORY = 'tests' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'Reader' . DIRECTORY_SEPARATOR . 'XLSX' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testDataSeriesValues(): void { $reader = new XlsxReader(); $this->readCharts($reader); $spreadsheet = $reader->load(self::DIRECTORY . 'issue.2506.xlsx'); $worksheet = $spreadsheet->getActiveSheet(); $charts = $worksheet->getChartCollection(); self::assertCount(4, $charts); $originalChart1 = $charts[0]; self::assertNotNull($originalChart1); $originalPlotArea1 = $originalChart1->getPlotArea(); self::assertNotNull($originalPlotArea1); $originalPlotSeries1 = $originalPlotArea1->getPlotGroup(); self::assertCount(1, $originalPlotSeries1); self::assertSame('0', $originalPlotSeries1[0]->getPlotStyle()); $originalChart2 = $charts[1]; self::assertNotNull($originalChart2); $originalPlotArea2 = $originalChart2->getPlotArea(); self::assertNotNull($originalPlotArea2); $originalPlotSeries2 = $originalPlotArea2->getPlotGroup(); self::assertCount(1, $originalPlotSeries2); self::assertSame('5', $originalPlotSeries2[0]->getPlotStyle()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(4, $charts2); $chart1 = $charts[0]; self::assertNotNull($chart1); $plotArea1 = $chart1->getPlotArea(); self::assertNotNull($plotArea1); $plotSeries1 = $plotArea1->getPlotGroup(); self::assertCount(1, $plotSeries1); self::assertSame('0', $plotSeries1[0]->getPlotStyle()); $chart2 = $charts[1]; self::assertNotNull($chart2); $plotArea2 = $chart2->getPlotArea(); self::assertNotNull($plotArea2); $plotSeries2 = $plotArea2->getPlotGroup(); self::assertCount(1, $plotSeries2); self::assertSame('5', $plotSeries2[0]->getPlotStyle()); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue4201Test.php
tests/PhpSpreadsheetTests/Chart/Issue4201Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Layout; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class Issue4201Test extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testLabelFont(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); // Sample data for pie chart $data = [ ['Category', 'Value'], ['Category A', 40], ['Category B', 30], ['Category C', 20], ['Category D', 10], ]; $worksheet->fromArray($data, null, 'A1'); $worksheet->getColumnDimension('A')->setAutoSize(true); // Create data series for the pie chart $categories = [new DataSeriesValues('String', 'Worksheet!$A$2:$A$5', null, 4)]; $values = [new DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', null, 4)]; // Set layout for data labels $font = new Font(); $font->setName('Times New Roman'); $font->setSize(8); $layout = new Layout(); $layout->setShowVal(true); // Display values $layout->setShowCatName(true); // Display category names $layout->setLabelFont($font); $series = new DataSeries( DataSeries::TYPE_PIECHART, // Chart type: Pie chart null, range(0, count($values) - 1), [], $categories, $values ); $plotArea = new PlotArea($layout, [$series]); $chart = new Chart('Pie Chart', null, null, $plotArea); $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart2 = $charts[0]; self::assertNotNull($chart2); $plotArea2 = $chart2->getPlotArea(); self::assertNotNull($plotArea2); $layout2 = $plotArea2->getLayout(); self::assertNotNull($layout2); $font2 = $layout2->getLabelFont(); self::assertNotNull($font2); self::assertSame('Times New Roman', $font2->getLatin()); self::assertSame(8.0, $font2->getSize()); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/ChartBorderTest.php
tests/PhpSpreadsheetTests/Chart/ChartBorderTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class ChartBorderTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); $writer->setUseDiskCaching(true, sys_get_temp_dir()); } public function testChartBorder(): void { $file = self::DIRECTORY . '32readwriteLineChart5.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertSame('ffffff', $chart->getFillColor()->getValue()); self::assertSame('srgbClr', $chart->getFillColor()->getType()); self::assertSame('d9d9d9', $chart->getBorderLines()->getLineColorProperty('value')); self::assertSame('srgbClr', $chart->getBorderLines()->getLineColorProperty('type')); self::assertEqualsWithDelta(9360 / Properties::POINTS_WIDTH_MULTIPLIER, $chart->getBorderLines()->getLineStyleProperty('width'), 1.0E-8); self::assertTrue($chart->getChartAxisY()->getNoFill()); self::assertFalse($chart->getChartAxisX()->getNoFill()); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/AxisGlowTest.php
tests/PhpSpreadsheetTests/Chart/AxisGlowTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class AxisGlowTest extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testGlowY(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_AREACHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel // yAxisLabel ); $yAxis = $chart->getChartAxisY(); $xAxis = $chart->getChartAxisX(); $yGlowSize = 10.0; $yAxis->setGlowProperties($yGlowSize, 'FFFF00', 30, ChartColor::EXCEL_COLOR_TYPE_RGB); $expectedGlowColor = [ 'type' => 'srgbClr', 'value' => 'FFFF00', 'alpha' => 30, ]; $softEdgesY = 2.5; $yAxis->setSoftEdges($softEdgesY); $softEdgesX = 5; $xAxis->setSoftEdges($softEdgesX); self::assertEquals($yGlowSize, $yAxis->getGlowProperty('size')); self::assertEquals($expectedGlowColor, $yAxis->getGlowProperty('color')); self::assertSame($expectedGlowColor['value'], $yAxis->getGlowProperty(['color', 'value'])); self::assertEquals($softEdgesY, $yAxis->getSoftEdgesSize()); self::assertEquals($softEdgesX, $xAxis->getSoftEdgesSize()); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $yAxis2 = $chart2->getChartAxisY(); self::assertEquals($yGlowSize, $yAxis2->getGlowProperty('size')); self::assertEquals($expectedGlowColor, $yAxis2->getGlowProperty('color')); self::assertEquals($softEdgesY, $yAxis2->getSoftEdgesSize()); $xAxis2 = $chart2->getChartAxisX(); self::assertNull($xAxis2->getGlowProperty('size')); $reloadedSpreadsheet->disconnectWorksheets(); } public function testGlowX(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_AREACHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel // yAxisLabel ); $yAxis = $chart->getChartAxisX(); // deliberate $yGlowSize = 20.0; $yAxis->setGlowProperties($yGlowSize, 'accent1', 20, ChartColor::EXCEL_COLOR_TYPE_SCHEME); $expectedGlowColor = [ 'type' => 'schemeClr', 'value' => 'accent1', 'alpha' => 20, ]; self::assertEquals($yGlowSize, $yAxis->getGlowProperty('size')); self::assertEquals($expectedGlowColor, $yAxis->getGlowProperty('color')); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $yAxis2 = $chart2->getChartAxisX(); // deliberate self::assertEquals($yGlowSize, $yAxis2->getGlowProperty('size')); self::assertEquals($expectedGlowColor, $yAxis2->getGlowProperty('color')); $xAxis2 = $chart2->getChartAxisY(); // deliberate self::assertNull($xAxis2->getGlowProperty('size')); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/LegendColorTest.php
tests/PhpSpreadsheetTests/Chart/LegendColorTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\AxisText; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class LegendColorTest extends AbstractFunctional { // based on 33_Chart_create_stock public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testLegend(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['Counts', 'Max', 'Min', 'Min Threshold', 'Max Threshold'], [10, 10, 5, 0, 50], [30, 20, 10, 0, 50], [20, 30, 15, 0, 50], [40, 10, 0, 0, 50], [100, 40, 5, 0, 50], ], null, 'A1', true ); $worksheet->getStyle('B2:E6')->getNumberFormat()->setFormatCode(NumberFormat::FORMAT_NUMBER_00); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), //Max / Open new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), //Min / Close new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), //Min Threshold / Min new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$E$1', null, 1), //Max Threshold / Max ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$6', null, 5), // Counts ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$6', null, 5), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$6', null, 5), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$6', null, 5), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$E$2:$E$6', null, 5), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_STOCKCHART, // plotType null, // plotGrouping - if we set this to not null, then xlsx throws error range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_RIGHT, null, false); $legend->getBorderLines()->setLineColorProperties('ffc000', null, ChartColor::EXCEL_COLOR_TYPE_RGB); $legend->getFillColor()->setColorProperties('cccccc'); $legendText = new AxisText(); $legendText->getFillColorObject()->setValue('008080')->setType(ChartColor::EXCEL_COLOR_TYPE_RGB); $legendText->setShadowProperties(1); $legend->setLegendText($legendText); $title = new Title('Test Stock Chart'); $xAxisLabel = new Title('Counts'); $yAxisLabel = new Title('Values'); // Create the chart $chart = new Chart( 'stock-chart', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs $xAxisLabel, // xAxisLabel $yAxisLabel // yAxisLabel ); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); $worksheet->setSelectedCells('G2'); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $legend2 = $chart2->getLegend(); if ($legend2 === null) { self::fail('Unexpected null legend'); } else { self::assertSame('ffc000', $legend2->getBorderLines()->getLineColorProperty('value')); self::assertSame('cccccc', $legend2->getFillColor()->getValue()); $legendText2 = $legend2->getLegendText(); if ($legendText2 === null) { self::fail('Unexpected null legendText'); } else { self::assertSame('008080', $legendText2->getFillColorObject()->getValue()); self::assertSame('outerShdw', $legendText2->getShadowProperty('effect')); self::assertSame(4.0, (float) $legendText2->getShadowProperty('blur')); self::assertSame(45.0, (float) $legendText2->getShadowProperty('direction')); } } $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/LegendTest.php
tests/PhpSpreadsheetTests/Chart/LegendTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Legend; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class LegendTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testLegendWithOverlay(): void { $file = self::DIRECTORY . 'chart-with-and-without-overlays.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheetName = 'With Overlay'; $sheet = $spreadsheet->getSheetByName($sheetName); self::assertNotNull($sheet); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheetByName($sheetName); self::assertNotNull($sheet); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $legend = $chart->getLegend(); self::assertNotNull($legend); self::assertTrue($legend->getOverlay()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testLegendWithoutOverlay(): void { $file = self::DIRECTORY . 'chart-with-and-without-overlays.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheetName = 'Without Overlay'; $sheet = $spreadsheet->getSheetByName($sheetName); self::assertNotNull($sheet); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheetByName($sheetName); self::assertNotNull($sheet); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $legend = $chart->getLegend(); self::assertNotNull($legend); self::assertFalse($legend->getOverlay()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testSetPosition(): void { $positionValues = [ Legend::POSITION_RIGHT, Legend::POSITION_LEFT, Legend::POSITION_TOP, Legend::POSITION_BOTTOM, Legend::POSITION_TOPRIGHT, ]; $testInstance = new Legend(); foreach ($positionValues as $positionValue) { $result = $testInstance->setPosition($positionValue); self::assertTrue($result); } } public function testSetInvalidPositionReturnsFalse(): void { $testInstance = new Legend(); $result = $testInstance->setPosition('BottomLeft'); self::assertFalse($result); // Ensure that value is unchanged $result = $testInstance->getPosition(); self::assertEquals(Legend::POSITION_RIGHT, $result); } public function testGetPosition(): void { $PositionValue = Legend::POSITION_BOTTOM; $testInstance = new Legend(); $testInstance->setPosition($PositionValue); $result = $testInstance->getPosition(); self::assertEquals($PositionValue, $result); } public function testSetPositionXL(): void { $positionValues = [ Legend::XL_LEGEND_POSITION_BOTTOM, Legend::XL_LEGEND_POSITION_CORNER, Legend::XL_LEGEND_POSITION_CUSTOM, Legend::XL_LEGEND_POSITION_LEFT, Legend::XL_LEGEND_POSITION_RIGHT, Legend::XL_LEGEND_POSITION_TOP, ]; $testInstance = new Legend(); foreach ($positionValues as $positionValue) { $result = $testInstance->setPositionXL($positionValue); self::assertTrue($result); } } public function testSetInvalidXLPositionReturnsFalse(): void { $testInstance = new Legend(); $result = $testInstance->setPositionXL(999); self::assertFalse($result); // Ensure that value is unchanged $result = $testInstance->getPositionXL(); self::assertEquals(Legend::XL_LEGEND_POSITION_RIGHT, $result); } public function testGetPositionXL(): void { $PositionValue = Legend::XL_LEGEND_POSITION_CORNER; $testInstance = new Legend(); $testInstance->setPositionXL($PositionValue); $result = $testInstance->getPositionXL(); self::assertEquals($PositionValue, $result); } public function testSetOverlay(): void { $overlayValues = [ true, false, ]; $testInstance = new Legend(); foreach ($overlayValues as $overlayValue) { $testInstance->setOverlay($overlayValue); self::assertSame($overlayValue, $testInstance->getOverlay()); } } public function testGetOverlay(): void { $OverlayValue = true; $testInstance = new Legend(); $testInstance->setOverlay($OverlayValue); $result = $testInstance->getOverlay(); self::assertEquals($OverlayValue, $result); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/PR3163Test.php
tests/PhpSpreadsheetTests/Chart/PR3163Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; // based on chartSpreadsheet.php // Testing XLSX-Export of y-Axis line styles class PR3163Test extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testYAxisLineStyle(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_BARCHART, // plotType DataSeries::GROUPING_CLUSTERED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set additional dataseries parameters // Make it a horizontal bar rather than a vertical column graph $series->setPlotDirection(DataSeries::DIRECTION_BAR); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_RIGHT, null, false); $title = new Title('Test Bar Chart'); $yAxisLabel = new Title('Value ($k)'); // Create x- and y-axis $xAxis = new Axis(); $xAxis->setLineColorProperties('FF0000'); $yAxis = new Axis(); $yAxis->setLineColorProperties('00FF00'); // Create the chart $chart1 = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel, // yAxisLabel $xAxis, // xAxis $yAxis // yAxis ); // Set the position where the chart should appear in the worksheet $chart1->setTopLeftPosition('A7'); $chart1->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart1); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $xAxis2 = $chart2->getChartAxisX(); $lineColorX2 = $xAxis2->getLineColorProperty('value'); self::assertSame($lineColorX2, 'FF0000'); $yAxis2 = $chart2->getChartAxisY(); $lineColorY2 = $yAxis2->getLineColorProperty('value'); self::assertSame($lineColorY2, '00FF00'); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/LineStylesTest.php
tests/PhpSpreadsheetTests/Chart/LineStylesTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\GridLines; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PHPUnit\Framework\TestCase; class LineStylesTest extends TestCase { public function testLineStyles(): void { $gridlines1 = new GridLines(); $originalLineStyle = $gridlines1->getLineStyleArray(); $gridlines1->setLineStyleProperties( 3, // lineWidth Properties::LINE_STYLE_COMPOUND_DOUBLE, // compoundType '', // dashType Properties::LINE_STYLE_CAP_SQUARE, // capType '', // jointType '', // headArrowType 0, // headArrowSize '', // endArrowType 0, // endArrowSize 'lg', // headArrowWidth 'med', // headArrowLength '', // endArrowWidth '' // endArrowLength ); $gridlines2 = new GridLines(); $lineStyleProperties = [ 'width' => 3, 'compound' => Properties::LINE_STYLE_COMPOUND_DOUBLE, 'cap' => Properties::LINE_STYLE_CAP_SQUARE, 'arrow' => ['head' => ['w' => 'lg', 'len' => 'med']], ]; $gridlines2->setLineStyleArray($lineStyleProperties); self::assertSame($gridlines1->getLineStyleArray(), $gridlines2->getLineStyleArray()); $gridlines2->setLineStyleArray(); // resets line styles self::assertSame($originalLineStyle, $gridlines2->getLineStyleArray()); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/LayoutTest.php
tests/PhpSpreadsheetTests/Chart/LayoutTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\Layout; use PHPUnit\Framework\TestCase; class LayoutTest extends TestCase { public function testSetLayoutTarget(): void { $LayoutTargetValue = 'String'; $testInstance = new Layout(); $result = $testInstance->setLayoutTarget($LayoutTargetValue); self::assertSame('String', $result->getLayoutTarget()); } public function testGetLayoutTarget(): void { $LayoutTargetValue = 'String'; $testInstance = new Layout(); $testInstance->setLayoutTarget($LayoutTargetValue); $result = $testInstance->getLayoutTarget(); self::assertEquals($LayoutTargetValue, $result); } public function testConstructorVsMethods(): void { $fillColor = new ChartColor('FF0000', 20, 'srgbClr'); $borderColor = new ChartColor('accent1', 20, 'schemeClr'); $fontColor = new ChartColor('red', 20, 'prstClr'); $array = [ 'xMode' => 'factor', 'yMode' => 'edge', 'x' => 1.0, 'y' => 2.0, 'w' => 3.0, 'h' => 4.0, 'showVal' => true, 'dLblPos' => 't', 'numFmtCode' => '0.00%', 'numFmtLinked' => true, 'labelFillColor' => $fillColor, 'labelBorderColor' => $borderColor, 'labelFontColor' => $fontColor, ]; $layout1 = new Layout($array); $layout2 = new Layout(); $layout2 ->setXMode('factor') ->setYMode('edge') ->setXposition(1.0) ->setYposition(2.0) ->setWidth(3.0) ->setHeight(4.0) ->setShowVal(true) ->setDLblPos('t') ->setNumFmtCode('0.00%') ->setNumFmtLinked(true) ->setLabelFillColor($fillColor) ->setLabelBorderColor($borderColor) ->setLabelFontColor($fontColor); self::assertEquals($layout1, $layout2); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/DataSeriesColorTest.php
tests/PhpSpreadsheetTests/Chart/DataSeriesColorTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Axis as ChartAxis; use PhpOffice\PhpSpreadsheet\Chart\AxisText; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class DataSeriesColorTest extends AbstractFunctional { // based on 33_Char_create_scatter2 public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testDataSeriesValues(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); // changed data to simulate a trend chart - Xaxis are dates; Yaxis are 3 measurements from each date $worksheet->fromArray( [ ['', 'metric1', 'metric2', 'metric3'], ['=DATEVALUE("2021-01-01")', 12.1, 15.1, 21.1], ['=DATEVALUE("2021-01-04")', 56.2, 73.2, 86.2], ['=DATEVALUE("2021-01-07")', 52.2, 61.2, 69.2], ['=DATEVALUE("2021-01-10")', 30.2, 32.2, 0.2], ] ); $worksheet->getStyle('A2:A5')->getNumberFormat()->setFormatCode(Properties::FORMAT_CODE_DATE_ISO8601); $worksheet->getColumnDimension('A')->setAutoSize(true); $worksheet->setSelectedCells('A1'); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // was 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // was 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // was 2012 ]; // Set the X-Axis Labels // changed from STRING to NUMBER // added 2 additional x-axis values associated with each of the 3 metrics // added FORMATE_CODE_NUMBER $xAxisTickValues = [ //new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$A$2:$A$5', Properties::FORMAT_CODE_DATE, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$A$2:$A$5', Properties::FORMAT_CODE_DATE, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$A$2:$A$5', Properties::FORMAT_CODE_DATE, 4), ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker // added FORMAT_CODE_NUMBER $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', Properties::FORMAT_CODE_NUMBER, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', Properties::FORMAT_CODE_NUMBER, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', Properties::FORMAT_CODE_NUMBER, 4), ]; // series 1 // marker details $dataSeriesValues[0] ->setPointMarker('diamond') ->setPointSize(5) ->getMarkerFillColor() ->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_RGB); $dataSeriesValues[0] ->getMarkerBorderColor() ->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_RGB); // line details - smooth line, connected $dataSeriesValues[0] ->setScatterLines(true) ->setSmoothLine(true) ->setLineColorProperties('accent1', 40, ChartColor::EXCEL_COLOR_TYPE_SCHEME); // value, alpha, type $dataSeriesValues[0]->setLineStyleProperties( 2.5, // width in points Properties::LINE_STYLE_COMPOUND_TRIPLE, // compound Properties::LINE_STYLE_DASH_SQUARE_DOT, // dash Properties::LINE_STYLE_CAP_SQUARE, // cap Properties::LINE_STYLE_JOIN_MITER, // join Properties::LINE_STYLE_ARROW_TYPE_OPEN, // head type Properties::LINE_STYLE_ARROW_SIZE_4, // head size preset index Properties::LINE_STYLE_ARROW_TYPE_ARROW, // end type Properties::LINE_STYLE_ARROW_SIZE_6 // end size preset index ); // series 2 - straight line - no special effects, connected, straight line $dataSeriesValues[1] // square fill ->setPointMarker('square') ->setPointSize(6) ->getMarkerBorderColor() ->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME); $dataSeriesValues[1] // square border ->getMarkerFillColor() ->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB); $dataSeriesValues[1] ->setScatterLines(true) ->setSmoothLine(false) ->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_RGB); $dataSeriesValues[1]->setLineWidth(2.0); // series 3 - markers, no line $dataSeriesValues[2] // triangle fill //->setPointMarker('triangle') // let Excel choose shape ->setPointSize(7) ->getMarkerFillColor() ->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB); $dataSeriesValues[2] // triangle border ->getMarkerBorderColor() ->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME); $dataSeriesValues[2]->setScatterLines(false); // points not connected // Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers $xAxis = new ChartAxis(); //$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE ); $xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true); //$xAxis->setAxisOption('textRotation', '45'); $xAxisText = new AxisText(); $xAxisText->setRotation(45)->getFillColorObject()->setValue('00FF00')->setType(ChartColor::EXCEL_COLOR_TYPE_RGB); $xAxis->setAxisText($xAxisText); $yAxis = new ChartAxis(); $yAxis->setLineStyleProperties( 2.5, // width in points Properties::LINE_STYLE_COMPOUND_SIMPLE, Properties::LINE_STYLE_DASH_DASH_DOT, Properties::LINE_STYLE_CAP_FLAT, Properties::LINE_STYLE_JOIN_BEVEL ); $yAxis->setLineColorProperties('ffc000', null, ChartColor::EXCEL_COLOR_TYPE_RGB); $yAxisText = new AxisText(); $yAxisText->setGlowProperties(20.0, 'accent1', 20, ChartColor::EXCEL_COLOR_TYPE_SCHEME); $yAxis->setAxisText($yAxisText); // Build the dataseries $series = new DataSeries( DataSeries::TYPE_SCATTERCHART, // plotType null, // plotGrouping (Scatter charts don't have any grouping) range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues, // plotValues null, // plotDirection false, // smooth line DataSeries::STYLE_SMOOTHMARKER // plotStyle ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test Scatter Trend Chart'); $yAxisLabel = new Title('Value ($k)'); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel, // yAxisLabel // added xAxis for correct date display $xAxis, // xAxis $yAxis, // yAxis ); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('P20'); // Add the chart to the worksheet $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $xAxisText = $chart2->getChartAxisX()->getAxisText(); $yAxisText = $chart2->getChartAxisY()->getAxisText(); if ($xAxisText === null || $yAxisText === null) { self::fail('Unexpected null x-axis or y-axis'); } else { self::assertSame(45, $xAxisText->getRotation()); self::assertSame('00FF00', $xAxisText->getFillColorObject()->getValue()); self::assertSame(ChartColor::EXCEL_COLOR_TYPE_RGB, $xAxisText->getFillColorObject()->getType()); self::assertSame(20.0, $yAxisText->getGlowProperty('size')); self::assertSame(['value' => 'accent1', 'type' => 'schemeClr', 'alpha' => 20], $yAxisText->getGlowProperty('color')); } $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/AxisPropertiesTest.php
tests/PhpSpreadsheetTests/Chart/AxisPropertiesTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class AxisPropertiesTest extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testAxisProperties(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_LINECHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); $xAxis = new Axis(); $xAxis->setFillParameters('FF0000', null, 'srgbClr'); self::assertSame('FF0000', $xAxis->getFillProperty('value')); self::assertSame('', $xAxis->getFillProperty('alpha')); self::assertSame('srgbClr', $xAxis->getFillProperty('type')); $xAxis->setAxisOptionsProperties( Properties::AXIS_LABELS_HIGH, // axisLabels, null, // $horizontalCrossesValue, Properties::HORIZONTAL_CROSSES_MAXIMUM, //horizontalCrosses Properties::ORIENTATION_REVERSED, //axisOrientation Properties::TICK_MARK_INSIDE, //majorTmt Properties::TICK_MARK_OUTSIDE, //minorTmt '8', //minimum '68', //maximum '20', //majorUnit '5', //minorUnit '6', //textRotation '0', //hidden ); self::assertSame(Properties::AXIS_LABELS_HIGH, $xAxis->getAxisOptionsProperty('axis_labels')); self::assertNull($xAxis->getAxisOptionsProperty('horizontal_crosses_value')); self::assertSame(Properties::HORIZONTAL_CROSSES_MAXIMUM, $xAxis->getAxisOptionsProperty('horizontal_crosses')); self::assertSame(Properties::ORIENTATION_REVERSED, $xAxis->getAxisOptionsProperty('orientation')); self::assertSame(Properties::TICK_MARK_INSIDE, $xAxis->getAxisOptionsProperty('major_tick_mark')); self::assertSame(Properties::TICK_MARK_OUTSIDE, $xAxis->getAxisOptionsProperty('minor_tick_mark')); self::assertSame('8', $xAxis->getAxisOptionsProperty('minimum')); self::assertSame('68', $xAxis->getAxisOptionsProperty('maximum')); self::assertSame('20', $xAxis->getAxisOptionsProperty('major_unit')); self::assertSame('5', $xAxis->getAxisOptionsProperty('minor_unit')); self::assertSame('6', $xAxis->getAxisOptionsProperty('textRotation')); self::assertSame('0', $xAxis->getAxisOptionsProperty('hidden')); $yAxis = new Axis(); $yAxis->setFillParameters('accent1', 30, 'schemeClr'); self::assertSame('accent1', $yAxis->getFillProperty('value')); self::assertSame('30', $yAxis->getFillProperty('alpha')); self::assertSame('schemeClr', $yAxis->getFillProperty('type')); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel, // yAxisLabel $xAxis, // xAxis $yAxis, // yAxis null, //majorGridlines, null // minorGridlines ); $xAxis2 = $chart->getChartAxisX(); self::assertSame('FF0000', $xAxis2->getFillProperty('value')); self::assertSame('', $xAxis2->getFillProperty('alpha')); self::assertSame('srgbClr', $xAxis2->getFillProperty('type')); self::assertSame(Properties::AXIS_LABELS_HIGH, $xAxis2->getAxisOptionsProperty('axis_labels')); self::assertNull($xAxis2->getAxisOptionsProperty('horizontal_crosses_value')); self::assertSame(Properties::HORIZONTAL_CROSSES_MAXIMUM, $xAxis2->getAxisOptionsProperty('horizontal_crosses')); self::assertSame(Properties::ORIENTATION_REVERSED, $xAxis2->getAxisOptionsProperty('orientation')); self::assertSame(Properties::TICK_MARK_INSIDE, $xAxis2->getAxisOptionsProperty('major_tick_mark')); self::assertSame(Properties::TICK_MARK_OUTSIDE, $xAxis2->getAxisOptionsProperty('minor_tick_mark')); self::assertSame('8', $xAxis2->getAxisOptionsProperty('minimum')); self::assertSame('68', $xAxis2->getAxisOptionsProperty('maximum')); self::assertSame('20', $xAxis2->getAxisOptionsProperty('major_unit')); self::assertSame('5', $xAxis2->getAxisOptionsProperty('minor_unit')); self::assertSame('6', $xAxis2->getAxisOptionsProperty('textRotation')); self::assertSame('0', $xAxis2->getAxisOptionsProperty('hidden')); $yAxis2 = $chart->getChartAxisY(); self::assertSame('accent1', $yAxis2->getFillProperty('value')); self::assertSame('30', $yAxis2->getFillProperty('alpha')); self::assertSame('schemeClr', $yAxis2->getFillProperty('type')); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $xAxis3 = $chart2->getChartAxisX(); self::assertSame('FF0000', $xAxis3->getFillProperty('value')); self::assertSame('', $xAxis3->getFillProperty('alpha')); self::assertSame('srgbClr', $xAxis3->getFillProperty('type')); self::assertSame(Properties::AXIS_LABELS_HIGH, $xAxis3->getAxisOptionsProperty('axis_labels')); self::assertSame(Properties::TICK_MARK_INSIDE, $xAxis3->getAxisOptionsProperty('major_tick_mark')); self::assertSame(Properties::TICK_MARK_OUTSIDE, $xAxis3->getAxisOptionsProperty('minor_tick_mark')); self::assertNull($xAxis3->getAxisOptionsProperty('horizontal_crosses_value')); self::assertSame(Properties::HORIZONTAL_CROSSES_MAXIMUM, $xAxis3->getAxisOptionsProperty('horizontal_crosses')); self::assertSame(Properties::ORIENTATION_REVERSED, $xAxis3->getAxisOptionsProperty('orientation')); self::assertSame('8', $xAxis3->getAxisOptionsProperty('minimum')); self::assertSame('68', $xAxis3->getAxisOptionsProperty('maximum')); self::assertSame('20', $xAxis3->getAxisOptionsProperty('major_unit')); self::assertSame('5', $xAxis3->getAxisOptionsProperty('minor_unit')); self::assertSame('6', $xAxis3->getAxisOptionsProperty('textRotation')); self::assertSame('0', $xAxis3->getAxisOptionsProperty('hidden')); $yAxis3 = $chart2->getChartAxisY(); self::assertSame('accent1', $yAxis3->getFillProperty('value')); self::assertSame('30', $yAxis3->getFillProperty('alpha')); self::assertSame('schemeClr', $yAxis3->getFillProperty('type')); $xAxis3->setAxisOrientation(Properties::ORIENTATION_NORMAL); self::assertSame(Properties::ORIENTATION_NORMAL, $xAxis3->getAxisOptionsProperty('orientation')); $xAxis3->setAxisOptionsProperties( Properties::AXIS_LABELS_HIGH, // axisLabels, '5' // $horizontalCrossesValue, ); self::assertSame('5', $xAxis3->getAxisOptionsProperty('horizontal_crosses_value')); $yAxis3->setLineColorProperties('0000FF', null, 'srgbClr'); self::assertSame('0000FF', $yAxis3->getLineColorProperty('value')); self::assertNull($yAxis3->getLineColorProperty('alpha')); self::assertSame('srgbClr', $yAxis3->getLineColorProperty('type')); $yAxis3->setAxisNumberProperties(Properties::FORMAT_CODE_GENERAL); self::assertFalse($yAxis3->getAxisIsNumericFormat()); $yAxis3->setAxisNumberProperties(Properties::FORMAT_CODE_NUMBER); self::assertTrue($yAxis3->getAxisIsNumericFormat()); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/LayoutEffectsTest.php
tests/PhpSpreadsheetTests/Chart/LayoutEffectsTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class LayoutEffectsTest extends AbstractFunctional { private const FILENAME = 'samples/templates/32readwriteLineChart6.xlsx'; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testLegend(): void { $reader = new XlsxReader(); $this->readCharts($reader); $spreadsheet = $reader->load(self::FILENAME); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $yAxis = $chart2->getChartAxisY(); $yAxisText = $yAxis->getAxisText(); self::assertNotNull($yAxisText); self::assertSame(['value' => 'accent4', 'type' => 'schemeClr', 'alpha' => 60], $yAxisText->getGlowProperty('color')); $plotArea2 = $chart2->getPlotArea(); self::assertNotNull($plotArea2); $plotGroup2 = $plotArea2->getPlotGroup()[0]; $plotIndex2 = $plotGroup2->getPlotLabelByIndex(0); if ($plotIndex2 === false) { self::fail('Unexpected false for getPlotLabelByIndex'); } else { $layout2 = $plotIndex2->getLabelLayout(); self::assertNotNull($layout2); $effects2 = $layout2->getLabelEffects(); self::assertNotNull($effects2); $shadows2 = $effects2->getShadowArray(); self::assertSame('outerShdw', $shadows2['effect']); self::assertSame(['value' => 'FF0000', 'type' => 'srgbClr', 'alpha' => 70], $shadows2['color']); } $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php
tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Exception; use PHPUnit\Framework\TestCase; class DataSeriesValuesTest extends TestCase { public function testSetDataType(): void { $dataTypeValues = [ 'Number', 'String', ]; $testInstance = new DataSeriesValues(); foreach ($dataTypeValues as $dataTypeValue) { $result = $testInstance->setDataType($dataTypeValue); self::assertSame($dataTypeValue, $result->getDataType()); } } public function testSetInvalidDataTypeThrowsException(): void { $testInstance = new DataSeriesValues(); try { $testInstance->setDataType('BOOLEAN'); } catch (Exception $e) { self::assertEquals($e->getMessage(), 'Invalid datatype for chart data series values'); return; } self::fail('An expected exception has not been raised.'); } public function testGetDataType(): void { $dataTypeValue = 'String'; $testInstance = new DataSeriesValues(); $testInstance->setDataType($dataTypeValue); $result = $testInstance->getDataType(); self::assertEquals($dataTypeValue, $result); } public function testGetLineWidth(): void { $testInstance = new DataSeriesValues(); // default has changed to null from 1 point (12700) self::assertNull($testInstance->getLineWidth(), 'should have default'); $testInstance->setLineWidth(40000 / Properties::POINTS_WIDTH_MULTIPLIER); self::assertEquals(40000 / Properties::POINTS_WIDTH_MULTIPLIER, $testInstance->getLineWidth()); $testInstance->setLineWidth(1); self::assertEquals(12700 / Properties::POINTS_WIDTH_MULTIPLIER, $testInstance->getLineWidth(), 'should enforce minimum width'); } public function testFillColorCorrectInput(): void { $testInstance = new DataSeriesValues(); self::assertEquals($testInstance, $testInstance->setFillColor('00abb8')); self::assertEquals($testInstance, $testInstance->setFillColor(['00abb8', 'b8292f'])); } public function testFillColorInvalidInput(): void { $testInstance = new DataSeriesValues(); $this->expectException(\Exception::class); $this->expectExceptionMessage('Invalid hex color for chart series'); $testInstance->setFillColor('WRONG COLOR'); } public function testFillColorInvalidInputInArray(): void { $testInstance = new DataSeriesValues(); $this->expectException(\Exception::class); $this->expectExceptionMessage('Invalid hex color for chart series (color: "WRONG COLOR")'); $testInstance->setFillColor(['b8292f', 'WRONG COLOR']); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/GridlinesLineStyleTest.php
tests/PhpSpreadsheetTests/Chart/GridlinesLineStyleTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\GridLines; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class GridlinesLineStyleTest extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testLineStyles(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_LINECHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); $majorGridlines = new GridLines(); $width = 2; $compound = Properties::LINE_STYLE_COMPOUND_THICKTHIN; $dash = Properties::LINE_STYLE_DASH_ROUND_DOT; $cap = Properties::LINE_STYLE_CAP_ROUND; $join = Properties::LINE_STYLE_JOIN_MITER; $headArrowType = Properties::LINE_STYLE_ARROW_TYPE_DIAMOND; $headArrowSize = Properties::LINE_STYLE_ARROW_SIZE_2; $endArrowType = Properties::LINE_STYLE_ARROW_TYPE_OVAL; $endArrowSize = Properties::LINE_STYLE_ARROW_SIZE_3; $majorGridlines->setLineStyleProperties( $width, $compound, $dash, $cap, $join, $headArrowType, $headArrowSize, $endArrowType, $endArrowSize ); $minorGridlines = new GridLines(); $minorGridlines->setLineColorProperties('00FF00', 30, 'srgbClr'); self::assertEquals($width, $majorGridlines->getLineStyleProperty('width')); self::assertEquals($compound, $majorGridlines->getLineStyleProperty('compound')); self::assertEquals($dash, $majorGridlines->getLineStyleProperty('dash')); self::assertEquals($cap, $majorGridlines->getLineStyleProperty('cap')); self::assertEquals($join, $majorGridlines->getLineStyleProperty('join')); self::assertEquals($headArrowType, $majorGridlines->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals($headArrowSize, $majorGridlines->getLineStyleProperty(['arrow', 'head', 'size'])); self::assertEquals($endArrowType, $majorGridlines->getLineStyleProperty(['arrow', 'end', 'type'])); self::assertEquals($endArrowSize, $majorGridlines->getLineStyleProperty(['arrow', 'end', 'size'])); self::assertEquals('sm', $majorGridlines->getLineStyleProperty(['arrow', 'head', 'w'])); self::assertEquals('med', $majorGridlines->getLineStyleProperty(['arrow', 'head', 'len'])); self::assertEquals('sm', $majorGridlines->getLineStyleProperty(['arrow', 'end', 'w'])); self::assertEquals('lg', $majorGridlines->getLineStyleProperty(['arrow', 'end', 'len'])); self::assertEquals('sm', $majorGridlines->getLineStyleArrowWidth('end')); self::assertEquals('lg', $majorGridlines->getLineStyleArrowLength('end')); self::assertEquals('lg', $majorGridlines->getLineStyleArrowParameters('end', 'len')); self::assertSame('00FF00', $minorGridlines->getLineColorProperty('value')); self::assertSame(30, $minorGridlines->getLineColorProperty('alpha')); self::assertSame('srgbClr', $minorGridlines->getLineColorProperty('type')); // Create the chart $yAxis = new Axis(); $yAxis->setMajorGridlines($majorGridlines); $yAxis->setMinorGridlines($minorGridlines); $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel, // yAxisLabel null, // xAxis $yAxis // yAxis ); $yAxis2 = $chart->getChartAxisY(); $majorGridlines2 = $yAxis2->getMajorGridlines(); self::assertNotNull($majorGridlines2); self::assertEquals($width, $majorGridlines2->getLineStyleProperty('width')); self::assertEquals($compound, $majorGridlines2->getLineStyleProperty('compound')); self::assertEquals($dash, $majorGridlines2->getLineStyleProperty('dash')); self::assertEquals($cap, $majorGridlines2->getLineStyleProperty('cap')); self::assertEquals($join, $majorGridlines2->getLineStyleProperty('join')); self::assertEquals($headArrowType, $majorGridlines2->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals($headArrowSize, $majorGridlines2->getLineStyleProperty(['arrow', 'head', 'size'])); self::assertEquals($endArrowType, $majorGridlines2->getLineStyleProperty(['arrow', 'end', 'type'])); self::assertEquals($endArrowSize, $majorGridlines2->getLineStyleProperty(['arrow', 'end', 'size'])); self::assertEquals('sm', $majorGridlines2->getLineStyleProperty(['arrow', 'head', 'w'])); self::assertEquals('med', $majorGridlines2->getLineStyleProperty(['arrow', 'head', 'len'])); self::assertEquals('sm', $majorGridlines2->getLineStyleProperty(['arrow', 'end', 'w'])); self::assertEquals('lg', $majorGridlines2->getLineStyleProperty(['arrow', 'end', 'len'])); $minorGridlines2 = $yAxis2->getMinorGridlines(); self::assertNotNull($minorGridlines2); self::assertSame('00FF00', $minorGridlines2->getLineColorProperty('value')); self::assertSame(30, $minorGridlines2->getLineColorProperty('alpha')); self::assertSame('srgbClr', $minorGridlines2->getLineColorProperty('type')); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); self::assertSame('A7', $chart2->getTopLeftCell()); self::assertSame('H20', $chart2->getBottomRightCell()); self::assertSame($sheet, $chart2->getWorksheet()); $yAxis3 = $chart2->getChartAxisY(); $majorGridlines3 = $yAxis3->getMajorGridlines(); self::assertNotNull($majorGridlines3); self::assertEquals($width, $majorGridlines3->getLineStyleProperty('width')); self::assertEquals($compound, $majorGridlines3->getLineStyleProperty('compound')); self::assertEquals($dash, $majorGridlines3->getLineStyleProperty('dash')); self::assertEquals($cap, $majorGridlines3->getLineStyleProperty('cap')); self::assertEquals($join, $majorGridlines3->getLineStyleProperty('join')); self::assertEquals($headArrowType, $majorGridlines3->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals($endArrowType, $majorGridlines3->getLineStyleProperty(['arrow', 'end', 'type'])); self::assertEquals('sm', $majorGridlines3->getLineStyleProperty(['arrow', 'head', 'w'])); self::assertEquals('med', $majorGridlines3->getLineStyleProperty(['arrow', 'head', 'len'])); self::assertEquals('sm', $majorGridlines3->getLineStyleProperty(['arrow', 'end', 'w'])); self::assertEquals('lg', $majorGridlines3->getLineStyleProperty(['arrow', 'end', 'len'])); $minorGridlines3 = $yAxis3->getMinorGridlines(); self::assertNotNull($minorGridlines3); self::assertSame('00FF00', $minorGridlines3->getLineColorProperty('value')); self::assertSame(30, $minorGridlines3->getLineColorProperty('alpha')); self::assertSame('srgbClr', $minorGridlines3->getLineColorProperty('type')); $reloadedSpreadsheet->disconnectWorksheets(); } public function testLineStylesDeprecated(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_LINECHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); $majorGridlines = new GridLines(); $width = 2; $compound = Properties::LINE_STYLE_COMPOUND_THICKTHIN; $dash = Properties::LINE_STYLE_DASH_ROUND_DOT; $cap = Properties::LINE_STYLE_CAP_ROUND; $join = Properties::LINE_STYLE_JOIN_MITER; $headArrowType = Properties::LINE_STYLE_ARROW_TYPE_DIAMOND; $headArrowSize = Properties::LINE_STYLE_ARROW_SIZE_2; $endArrowType = Properties::LINE_STYLE_ARROW_TYPE_OVAL; $endArrowSize = Properties::LINE_STYLE_ARROW_SIZE_3; $majorGridlines->setLineStyleProperties( $width, $compound, $dash, $cap, $join, $headArrowType, $headArrowSize, $endArrowType, $endArrowSize ); $minorGridlines = new GridLines(); $minorGridlines->setLineColorProperties('00FF00', 30, 'srgbClr'); self::assertEquals($width, $majorGridlines->getLineStyleProperty('width')); self::assertEquals($compound, $majorGridlines->getLineStyleProperty('compound')); self::assertEquals($dash, $majorGridlines->getLineStyleProperty('dash')); self::assertEquals($cap, $majorGridlines->getLineStyleProperty('cap')); self::assertEquals($join, $majorGridlines->getLineStyleProperty('join')); self::assertEquals($headArrowType, $majorGridlines->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals($headArrowSize, $majorGridlines->getLineStyleProperty(['arrow', 'head', 'size'])); self::assertEquals($endArrowType, $majorGridlines->getLineStyleProperty(['arrow', 'end', 'type'])); self::assertEquals($endArrowSize, $majorGridlines->getLineStyleProperty(['arrow', 'end', 'size'])); self::assertEquals('sm', $majorGridlines->getLineStyleProperty(['arrow', 'head', 'w'])); self::assertEquals('med', $majorGridlines->getLineStyleProperty(['arrow', 'head', 'len'])); self::assertEquals('sm', $majorGridlines->getLineStyleProperty(['arrow', 'end', 'w'])); self::assertEquals('lg', $majorGridlines->getLineStyleProperty(['arrow', 'end', 'len'])); self::assertEquals('sm', $majorGridlines->getLineStyleArrowWidth('end')); self::assertEquals('lg', $majorGridlines->getLineStyleArrowLength('end')); self::assertEquals('lg', $majorGridlines->getLineStyleArrowParameters('end', 'len')); self::assertSame('00FF00', $minorGridlines->getLineColorProperty('value')); self::assertSame(30, $minorGridlines->getLineColorProperty('alpha')); self::assertSame('srgbClr', $minorGridlines->getLineColorProperty('type')); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel, // yAxisLabel null, // xAxis null, // yAxis $majorGridlines, $minorGridlines // minorGridlines ); $majorGridlines2 = $chart->getChartAxisY()->getMajorGridlines(); self::assertNotNull($majorGridlines2); self::assertEquals($width, $majorGridlines2->getLineStyleProperty('width')); self::assertEquals($compound, $majorGridlines2->getLineStyleProperty('compound')); self::assertEquals($dash, $majorGridlines2->getLineStyleProperty('dash')); self::assertEquals($cap, $majorGridlines2->getLineStyleProperty('cap')); self::assertEquals($join, $majorGridlines2->getLineStyleProperty('join')); self::assertEquals($headArrowType, $majorGridlines2->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals($headArrowSize, $majorGridlines2->getLineStyleProperty(['arrow', 'head', 'size'])); self::assertEquals($endArrowType, $majorGridlines2->getLineStyleProperty(['arrow', 'end', 'type'])); self::assertEquals($endArrowSize, $majorGridlines2->getLineStyleProperty(['arrow', 'end', 'size'])); self::assertEquals('sm', $majorGridlines2->getLineStyleProperty(['arrow', 'head', 'w'])); self::assertEquals('med', $majorGridlines2->getLineStyleProperty(['arrow', 'head', 'len'])); self::assertEquals('sm', $majorGridlines2->getLineStyleProperty(['arrow', 'end', 'w'])); self::assertEquals('lg', $majorGridlines2->getLineStyleProperty(['arrow', 'end', 'len'])); $minorGridlines2 = $chart->getChartAxisY()->getMinorGridlines(); self::assertNotNull($minorGridlines2); self::assertSame('00FF00', $minorGridlines2->getLineColorProperty('value')); self::assertSame(30, $minorGridlines2->getLineColorProperty('alpha')); self::assertSame('srgbClr', $minorGridlines2->getLineColorProperty('type')); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $majorGridlines3 = $chart2->getChartAxisY()->getMajorGridlines(); self::assertNotNull($majorGridlines3); self::assertEquals($width, $majorGridlines3->getLineStyleProperty('width')); self::assertEquals($compound, $majorGridlines3->getLineStyleProperty('compound')); self::assertEquals($dash, $majorGridlines3->getLineStyleProperty('dash')); self::assertEquals($cap, $majorGridlines3->getLineStyleProperty('cap')); self::assertEquals($join, $majorGridlines3->getLineStyleProperty('join')); self::assertEquals($headArrowType, $majorGridlines3->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals($endArrowType, $majorGridlines3->getLineStyleProperty(['arrow', 'end', 'type'])); self::assertEquals('sm', $majorGridlines3->getLineStyleProperty(['arrow', 'head', 'w'])); self::assertEquals('med', $majorGridlines3->getLineStyleProperty(['arrow', 'head', 'len'])); self::assertEquals('sm', $majorGridlines3->getLineStyleProperty(['arrow', 'end', 'w'])); self::assertEquals('lg', $majorGridlines3->getLineStyleProperty(['arrow', 'end', 'len'])); $minorGridlines3 = $chart2->getChartAxisY()->getMinorGridlines(); self::assertNotNull($minorGridlines3); self::assertSame('00FF00', $minorGridlines3->getLineColorProperty('value')); self::assertSame(30, $minorGridlines3->getLineColorProperty('alpha')); self::assertSame('srgbClr', $minorGridlines3->getLineColorProperty('type')); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/DataSeriesValues2Test.php
tests/PhpSpreadsheetTests/Chart/DataSeriesValues2Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class DataSeriesValues2Test extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testDataSeriesValues(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( null, // plotType null, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); self::assertEmpty($series->getPlotType()); self::assertEmpty($series->getPlotGrouping()); self::assertFalse($series->getSmoothLine()); $series->setPlotType(DataSeries::TYPE_AREACHART); $series->setPlotGrouping(DataSeries::GROUPING_PERCENT_STACKED); $series->setSmoothLine(true); self::assertSame(DataSeries::TYPE_AREACHART, $series->getPlotType()); self::assertSame(DataSeries::GROUPING_PERCENT_STACKED, $series->getPlotGrouping()); self::assertTrue($series->getSmoothLine()); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel // yAxisLabel ); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); self::assertSame(1, $plotArea->getPlotGroupCount()); $plotValues = $plotArea->getPlotGroup()[0]->getPlotValues(); self::assertCount(3, $plotValues); self::assertSame([], $plotValues[1]->getDataValues()); self::assertNull($plotValues[1]->getDataValue()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $plotArea2 = $chart2->getPlotArea(); self::assertNotNull($plotArea2); $plotGroup2 = $plotArea2->getPlotGroup()[0]; $plotValues2 = $plotGroup2->getPlotValues(); self::assertCount(3, $plotValues2); self::assertSame([15.0, 73.0, 61.0, 32.0], $plotValues2[1]->getDataValues()); self::assertSame([15.0, 73.0, 61.0, 32.0], $plotValues2[1]->getDataValue()); $labels2 = $plotGroup2->getPlotLabels(); self::assertCount(3, $labels2); self::assertEquals(2010, $labels2[0]->getDataValue()); $dataSeries = $plotArea2->getPlotGroup()[0]; self::assertFalse($dataSeries->getPlotValuesByIndex(99)); self::assertNotFalse($dataSeries->getPlotValuesByIndex(0)); self::assertEquals([12, 56, 52, 30], $dataSeries->getPlotValuesByIndex(0)->getDataValues()); self::assertSame(DataSeries::TYPE_AREACHART, $dataSeries->getPlotType()); self::assertSame(DataSeries::GROUPING_PERCENT_STACKED, $dataSeries->getPlotGrouping()); // SmoothLine written out for DataSeries only for LineChart. // Original test was wrong - used $chart rather than $chart2 // to retrieve data which was read in. //self::assertTrue($dataSeries->getSmoothLine()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testSomeProperties(): void { $dataSeriesValues = new DataSeriesValues(); self::assertNull($dataSeriesValues->getDataSource()); self::assertEmpty($dataSeriesValues->getPointMarker()); self::assertSame(3, $dataSeriesValues->getPointSize()); $dataSeriesValues->setDataSource('Worksheet!$B$1') ->setPointMarker('square') ->setPointSize(6); self::assertSame('Worksheet!$B$1', $dataSeriesValues->getDataSource()); self::assertSame('square', $dataSeriesValues->getPointMarker()); self::assertSame(6, $dataSeriesValues->getPointSize()); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/DisplayBlanksAsTest.php
tests/PhpSpreadsheetTests/Chart/DisplayBlanksAsTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class DisplayBlanksAsTest extends TestCase { public function testDisplayBlanksAs(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_AREACHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); $plotArea = new PlotArea(null, [$series]); $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); $chart1 = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel // yAxisLabel ); self::assertSame(DataSeries::EMPTY_AS_GAP, $chart1->getDisplayBlanksAs()); $chart1->setDisplayBlanksAs(DataSeries::EMPTY_AS_ZERO); self::assertSame(DataSeries::EMPTY_AS_ZERO, $chart1->getDisplayBlanksAs()); $chart1->setDisplayBlanksAs('0'); self::assertSame(DataSeries::EMPTY_AS_GAP, $chart1->getDisplayBlanksAs(), 'invalid setting converted to default'); $chart2 = new Chart( 'chart2', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_SPAN, // displayBlanksAs null, // xAxisLabel $yAxisLabel // yAxisLabel ); self::assertSame(DataSeries::EMPTY_AS_SPAN, $chart2->getDisplayBlanksAs()); $chart3 = new Chart( 'chart3', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly '0', // displayBlanksAs, PHPExcel default null, // xAxisLabel $yAxisLabel // yAxisLabel ); self::assertSame(DataSeries::EMPTY_AS_GAP, $chart3->getDisplayBlanksAs(), 'invalid setting converted to default'); $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/ChartsTitleTest.php
tests/PhpSpreadsheetTests/Chart/ChartsTitleTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\IOFactory; use PHPUnit\Framework\TestCase; class ChartsTitleTest extends TestCase { private static function getTitleText(?Title $title): string { return ($title === null) ? '' : $title->getCaptionText(); } public function testChartTitles(): void { $filename = 'tests/data/Reader/XLSX/excelChartsTest.xlsx'; $reader = IOFactory::createReader('Xlsx')->setIncludeCharts(true); $spreadsheet = $reader->load($filename); $worksheet = $spreadsheet->getActiveSheet(); $charts = $worksheet->getChartCollection(); self::assertEquals(5, $worksheet->getChartCount()); self::assertCount(5, $charts); // No title or axis labels $chart1 = $charts[0]; self::assertNotNull($chart1); $title = self::getTitleText($chart1->getTitle()); self::assertEmpty($title); self::assertEmpty(self::getTitleText($chart1->getXAxisLabel())); self::assertEmpty(self::getTitleText($chart1->getYAxisLabel())); // Title, no axis labels $chart2 = $charts[1]; self::assertNotNull($chart2); self::assertEquals('Chart with Title and no Axis Labels', self::getTitleText($chart2->getTitle())); self::assertEmpty(self::getTitleText($chart2->getXAxisLabel())); self::assertEmpty(self::getTitleText($chart2->getYAxisLabel())); // No title, only horizontal axis label $chart3 = $charts[2]; self::assertNotNull($chart3); self::assertEmpty(self::getTitleText($chart3->getTitle())); self::assertEquals('Horizontal Axis Title Only', self::getTitleText($chart3->getXAxisLabel())); self::assertEmpty(self::getTitleText($chart3->getYAxisLabel())); // No title, only vertical axis label $chart4 = $charts[3]; self::assertNotNull($chart4); self::assertEmpty(self::getTitleText($chart4->getTitle())); self::assertEquals('Vertical Axis Title Only', self::getTitleText($chart4->getYAxisLabel())); self::assertEmpty(self::getTitleText($chart4->getXAxisLabel())); // Title and both axis labels $chart5 = $charts[4]; self::assertNotNull($chart5); self::assertEquals('Complete Annotations', self::getTitleText($chart5->getTitle())); self::assertEquals('Horizontal Axis Title', self::getTitleText($chart5->getXAxisLabel())); self::assertEquals('Vertical Axis Title', self::getTitleText($chart5->getYAxisLabel())); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/RoundedCornersTest.php
tests/PhpSpreadsheetTests/Chart/RoundedCornersTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class RoundedCornersTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testRounded(): void { $file = self::DIRECTORY . '32readwriteAreaChart1.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Data', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertTrue($chart->getRoundedCorners()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testNotRounded(): void { $file = self::DIRECTORY . '32readwriteAreaChart2.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Data', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertFalse($chart->getRoundedCorners()); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/ChartsOpenpyxlTest.php
tests/PhpSpreadsheetTests/Chart/ChartsOpenpyxlTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PHPUnit\Framework\TestCase; class ChartsOpenpyxlTest extends TestCase { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function testBubble2(): void { $file = self::DIRECTORY . '32readwriteBubbleChart2.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); self::assertSame('Sheet', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertEmpty($chart->getTitle()); self::assertTrue($chart->getOneCellAnchor()); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $plotSeries = $plotArea->getPlotGroup(); self::assertCount(1, $plotSeries); $dataSeries = $plotSeries[0]; $labels = $dataSeries->getPlotLabels(); self::assertCount(2, $labels); self::assertSame(['2013'], $labels[0]->getDataValues()); self::assertSame(['2014'], $labels[1]->getDataValues()); $plotCategories = $dataSeries->getPlotCategories(); self::assertCount(2, $plotCategories); $categories = $plotCategories[0]; self::assertSame('Number', $categories->getDataType()); self::assertSame('\'Sheet\'!$A$2:$A$5', $categories->getDataSource()); self::assertFalse($categories->getBubble3D()); $categories = $plotCategories[1]; self::assertCount(2, $plotCategories); self::assertSame('Number', $categories->getDataType()); self::assertSame('\'Sheet\'!$A$7:$A$10', $categories->getDataSource()); self::assertFalse($categories->getBubble3D()); $plotValues = $dataSeries->getPlotValues(); self::assertCount(2, $plotValues); $values = $plotValues[0]; self::assertSame('Number', $values->getDataType()); self::assertSame('\'Sheet\'!$B$2:$B$5', $values->getDataSource()); self::assertFalse($values->getBubble3D()); $values = $plotValues[1]; self::assertCount(2, $plotValues); self::assertSame('Number', $values->getDataType()); self::assertSame('\'Sheet\'!$B$7:$B$10', $values->getDataSource()); self::assertFalse($values->getBubble3D()); $plotValues = $dataSeries->getPlotBubbleSizes(); self::assertCount(2, $plotValues); $values = $plotValues[0]; self::assertSame('Number', $values->getDataType()); self::assertSame('\'Sheet\'!$C$2:$C$5', $values->getDataSource()); self::assertFalse($values->getBubble3D()); $values = $plotValues[1]; self::assertCount(2, $plotValues); self::assertSame('Number', $values->getDataType()); self::assertSame('\'Sheet\'!$C$7:$C$10', $values->getDataSource()); self::assertFalse($values->getBubble3D()); $spreadsheet->disconnectWorksheets(); } public function testXml(): void { $infile = self::DIRECTORY . '32readwriteBubbleChart2.xlsx'; $file = 'zip://'; $file .= $infile; $file .= '#xl/charts/chart1.xml'; $data = file_get_contents($file); // confirm that file contains expected tags if ($data === false) { self::fail('Unable to read file'); } else { self::assertSame(0, substr_count($data, 'c:'), 'unusual choice of prefix'); self::assertSame(0, substr_count($data, 'bubbleScale')); self::assertSame(1, substr_count($data, '<tx><v>2013</v></tx>'), 'v tag for 2013'); self::assertSame(1, substr_count($data, '<tx><v>2014</v></tx>'), 'v tag for 2014'); self::assertSame(0, substr_count($data, 'numCache'), 'no cached values'); } $file = 'zip://'; $file .= $infile; $file .= '#xl/drawings/_rels/drawing1.xml.rels'; $data = file_get_contents($file); // confirm that file contains expected tags if ($data === false) { self::fail('Unable to read file'); } else { self::assertSame(1, substr_count($data, 'Target="/xl/charts/chart1.xml"'), 'Unusual absolute address in drawing rels file'); } $file = 'zip://'; $file .= $infile; $file .= '#xl/worksheets/_rels/sheet1.xml.rels'; $data = file_get_contents($file); // confirm that file contains expected tags if ($data === false) { self::fail('Unable to read file'); } else { self::assertSame(1, substr_count($data, 'Target="/xl/drawings/drawing1.xml"'), 'Unusual absolute address in worksheet rels file'); } } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue562Test.php
tests/PhpSpreadsheetTests/Chart/Issue562Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class Issue562Test extends AbstractFunctional { // based on 33_Char_create_area // test for chart borders public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } #[\PHPUnit\Framework\Attributes\DataProvider('providerNoBorder')] public function testNoBorder(?bool $noBorder, bool $expectedResult): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_AREACHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); $plotArea = new PlotArea(null, [$series]); $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel // yAxisLabel ); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); if ($noBorder !== null) { $chart->setNoBorder($noBorder); } // Add the chart to the worksheet $worksheet->addChart($chart); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); self::assertSame($expectedResult, $chart2->getNoBorder()); $reloadedSpreadsheet->disconnectWorksheets(); } public static function providerNoBorder(): array { return [ [true, true], [false, false], [null, false], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue2965Test.php
tests/PhpSpreadsheetTests/Chart/Issue2965Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PHPUnit\Framework\TestCase; class Issue2965Test extends TestCase { private const DIRECTORY = 'tests' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'Reader' . DIRECTORY_SEPARATOR . 'XLSX' . DIRECTORY_SEPARATOR; public function testPreliminaries(): void { $file = 'zip://'; $file .= self::DIRECTORY . 'issue.2965.xlsx'; $file .= '#xl/charts/chart1.xml'; $data = file_get_contents($file); // confirm that file contains expected namespaced xml tag if ($data === false) { self::fail('Unable to read file'); } else { self::assertStringContainsString('<c:title><c:tx><c:strRef><c:f>Sheet1!$A$1</c:f><c:strCache><c:ptCount val="1"/><c:pt idx="0"><c:v>NewTitle</c:v></c:pt></c:strCache></c:strRef></c:tx>', $data); } } public function testChartTitleFormula(): void { $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load(self::DIRECTORY . 'issue.2965.xlsx'); $worksheet = $spreadsheet->getActiveSheet(); $charts = $worksheet->getChartCollection(); self::assertCount(1, $charts); $originalChart1 = $charts[0]; self::assertNotNull($originalChart1); $originalTitle1 = $originalChart1->getTitle(); self::assertNotNull($originalTitle1); self::assertSame('NewTitle', $originalTitle1->getCaptionText()); $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Charts32ScatterTest.php
tests/PhpSpreadsheetTests/Chart/Charts32ScatterTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\Run; use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class Charts32ScatterTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testScatter1(): void { $file = self::DIRECTORY . '32readwriteScatterChart1.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Charts', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $title = $chart->getTitle(); self::assertNotNull($title); $captionArray = $title->getCaption(); self::assertIsArray($captionArray); self::assertCount(1, $captionArray); $caption = $captionArray[0]; self::assertInstanceOf(RichText::class, $caption); self::assertSame('Scatter - No Join and Markers', $caption->getPlainText()); $elements = $caption->getRichTextElements(); self::assertCount(1, $elements); $run = $elements[0]; self::assertInstanceOf(Run::class, $run); $font = $run->getFont(); self::assertInstanceOf(Font::class, $font); self::assertSame('Calibri', $font->getLatin()); self::assertEquals(12, $font->getSize()); self::assertTrue($font->getBold()); self::assertFalse($font->getItalic()); self::assertFalse($font->getSuperscript()); self::assertFalse($font->getSubscript()); self::assertFalse($font->getStrikethrough()); self::assertSame('none', $font->getUnderline()); $chartColor = $font->getChartColor(); self::assertNotNull($chartColor); self::assertSame('000000', $chartColor->getValue()); self::assertSame('srgbClr', $chartColor->getType()); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $plotSeries = $plotArea->getPlotGroup(); self::assertCount(1, $plotSeries); $dataSeries = $plotSeries[0]; $plotValues = $dataSeries->getPlotValues(); self::assertCount(3, $plotValues); $values = $plotValues[0]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $values = $plotValues[1]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $values = $plotValues[2]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(7, $values->getPointSize()); // Had been testing for Fill Color, but we actually // meant to test for marker color, which is now distinct. self::assertSame('FFFF00', $values->getMarkerFillColor()->getValue()); self::assertSame('srgbClr', $values->getMarkerFillColor()->getType()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testScatter6(): void { $file = self::DIRECTORY . '32readwriteScatterChart6.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Charts', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $title = $chart->getTitle(); self::assertNotNull($title); $captionArray = $title->getCaption(); self::assertIsArray($captionArray); self::assertCount(1, $captionArray); $caption = $captionArray[0]; self::assertInstanceOf(RichText::class, $caption); self::assertSame('Scatter - Rich Text Title No Join and Markers', $caption->getPlainText()); $elements = $caption->getRichTextElements(); self::assertCount(3, $elements); $run = $elements[0]; self::assertInstanceOf(Run::class, $run); $font = $run->getFont(); self::assertInstanceOf(Font::class, $font); self::assertSame('Calibri', $font->getLatin()); self::assertEquals(12, $font->getSize()); self::assertTrue($font->getBold()); self::assertFalse($font->getItalic()); self::assertFalse($font->getSuperscript()); self::assertFalse($font->getSubscript()); self::assertFalse($font->getStrikethrough()); self::assertSame('none', $font->getUnderline()); $chartColor = $font->getChartColor(); self::assertNotNull($chartColor); self::assertSame('000000', $chartColor->getValue()); self::assertSame('srgbClr', $chartColor->getType()); $run = $elements[1]; self::assertInstanceOf(Run::class, $run); $font = $run->getFont(); self::assertInstanceOf(Font::class, $font); self::assertSame('Courier New', $font->getLatin()); self::assertEquals(10, $font->getSize()); self::assertFalse($font->getBold()); self::assertFalse($font->getItalic()); self::assertFalse($font->getSuperscript()); self::assertFalse($font->getSubscript()); self::assertFalse($font->getStrikethrough()); self::assertSame('single', $font->getUnderline()); $chartColor = $font->getChartColor(); self::assertNotNull($chartColor); self::assertSame('00B0F0', $chartColor->getValue()); self::assertSame('srgbClr', $chartColor->getType()); $run = $elements[2]; self::assertInstanceOf(Run::class, $run); $font = $run->getFont(); self::assertInstanceOf(Font::class, $font); self::assertSame('Calibri', $font->getLatin()); self::assertEquals(12, $font->getSize()); self::assertTrue($font->getBold()); self::assertFalse($font->getItalic()); self::assertFalse($font->getSuperscript()); self::assertFalse($font->getSubscript()); self::assertFalse($font->getStrikethrough()); self::assertSame('none', $font->getUnderline()); $chartColor = $font->getChartColor(); self::assertNotNull($chartColor); self::assertSame('000000', $chartColor->getValue()); self::assertSame('srgbClr', $chartColor->getType()); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $plotSeries = $plotArea->getPlotGroup(); self::assertCount(1, $plotSeries); $dataSeries = $plotSeries[0]; $plotValues = $dataSeries->getPlotValues(); self::assertCount(3, $plotValues); $values = $plotValues[0]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $values = $plotValues[1]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $values = $plotValues[2]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(7, $values->getPointSize()); // Had been testing for Fill Color, but we actually // meant to test for marker color, which is now distinct. self::assertSame('FFFF00', $values->getMarkerFillColor()->getValue()); self::assertSame('srgbClr', $values->getMarkerFillColor()->getType()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testScatter3(): void { $file = self::DIRECTORY . '32readwriteScatterChart3.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Charts', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $title = $chart->getTitle(); self::assertNotNull($title); $captionArray = $title->getCaption(); self::assertIsArray($captionArray); self::assertCount(1, $captionArray); $caption = $captionArray[0]; self::assertInstanceOf(RichText::class, $caption); self::assertSame('Scatter - Join Straight Lines and Markers', $caption->getPlainText()); $elements = $caption->getRichTextElements(); self::assertCount(1, $elements); $run = $elements[0]; self::assertInstanceOf(Run::class, $run); $font = $run->getFont(); self::assertInstanceOf(Font::class, $font); self::assertSame('Calibri', $font->getLatin()); self::assertEquals(12, $font->getSize()); self::assertTrue($font->getBold()); self::assertFalse($font->getItalic()); self::assertFalse($font->getSuperscript()); self::assertFalse($font->getSubscript()); self::assertFalse($font->getStrikethrough()); self::assertSame('none', $font->getUnderline()); $chartColor = $font->getChartColor(); self::assertNotNull($chartColor); self::assertSame('000000', $chartColor->getValue()); self::assertSame('srgbClr', $chartColor->getType()); self::assertSame(50, $chartColor->getAlpha()); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $plotSeries = $plotArea->getPlotGroup(); self::assertCount(1, $plotSeries); $dataSeries = $plotSeries[0]; $plotValues = $dataSeries->getPlotValues(); self::assertCount(3, $plotValues); $values = $plotValues[0]; self::assertTrue($values->getScatterLines()); // the default value of 1 point is no longer written out // when not explicitly specified. self::assertNull($values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $values = $plotValues[1]; self::assertTrue($values->getScatterLines()); self::assertNull($values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $values = $plotValues[2]; self::assertTrue($values->getScatterLines()); self::assertNull($values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testScatter7(): void { $file = self::DIRECTORY . '32readwriteScatterChart7.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Charts', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $title = $chart->getTitle(); self::assertNotNull($title); $captionArray = $title->getCaption(); self::assertIsArray($captionArray); self::assertCount(1, $captionArray); $caption = $captionArray[0]; self::assertInstanceOf(RichText::class, $caption); self::assertSame('Latin/EA/CS Title ABCאבגDEFァ', $caption->getPlainText()); $elements = $caption->getRichTextElements(); self::assertGreaterThan(0, count($elements)); foreach ($elements as $run) { self::assertInstanceOf(Run::class, $run); $font = $run->getFont(); self::assertInstanceOf(Font::class, $font); self::assertSame('Times New Roman', $font->getLatin()); self::assertSame('Malgun Gothic', $font->getEastAsian()); self::assertSame('Courier New', $font->getComplexScript()); self::assertEquals(12, $font->getSize()); self::assertTrue($font->getBold()); self::assertFalse($font->getItalic()); self::assertFalse($font->getSuperscript()); self::assertFalse($font->getSubscript()); self::assertFalse($font->getStrikethrough()); self::assertSame('none', $font->getUnderline()); $chartColor = $font->getChartColor(); self::assertNotNull($chartColor); self::assertSame('000000', $chartColor->getValue()); self::assertSame('srgbClr', $chartColor->getType()); } $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $plotSeries = $plotArea->getPlotGroup(); self::assertCount(1, $plotSeries); $dataSeries = $plotSeries[0]; $plotValues = $dataSeries->getPlotValues(); self::assertCount(3, $plotValues); $values = $plotValues[0]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $values = $plotValues[1]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(3, $values->getPointSize()); self::assertSame('', $values->getFillColor()); $values = $plotValues[2]; self::assertFalse($values->getScatterLines()); self::assertSame(28575 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame(7, $values->getPointSize()); // Had been testing for Fill Color, but we actually // meant to test for marker color, which is now distinct. self::assertSame('FFFF00', $values->getMarkerFillColor()->getValue()); self::assertSame('srgbClr', $values->getMarkerFillColor()->getType()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testScatter8(): void { $file = self::DIRECTORY . '32readwriteScatterChart8.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Worksheet', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $xAxis = $chart->getChartAxisX(); self::assertEquals(45, $xAxis->getAxisOptionsProperty('textRotation')); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $plotSeries = $plotArea->getPlotGroup(); self::assertCount(1, $plotSeries); $dataSeries = $plotSeries[0]; $plotValues = $dataSeries->getPlotValues(); self::assertCount(3, $plotValues); $values = $plotValues[0]; self::assertSame(31750 / Properties::POINTS_WIDTH_MULTIPLIER, $values->getLineWidth()); self::assertSame('sq', $values->getLineStyleProperty('cap')); self::assertSame('tri', $values->getLineStyleProperty('compound')); self::assertSame('sysDash', $values->getLineStyleProperty('dash')); self::assertSame('miter', $values->getLineStyleProperty('join')); self::assertSame('arrow', $values->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertSame('med', $values->getLineStyleProperty(['arrow', 'head', 'w'])); self::assertSame('sm', $values->getLineStyleProperty(['arrow', 'head', 'len'])); self::assertSame('triangle', $values->getLineStyleProperty(['arrow', 'end', 'type'])); self::assertSame('med', $values->getLineStyleProperty(['arrow', 'end', 'w'])); self::assertSame('lg', $values->getLineStyleProperty(['arrow', 'end', 'len'])); self::assertSame('accent1', $values->getLineColorProperty('value')); self::assertSame('schemeClr', $values->getLineColorProperty('type')); self::assertSame(40, $values->getLineColorProperty('alpha')); self::assertSame('', $values->getFillColor()); self::assertSame(7, $values->getPointSize()); self::assertSame('diamond', $values->getPointMarker()); self::assertSame('0070C0', $values->getMarkerFillColor()->getValue()); self::assertSame('srgbClr', $values->getMarkerFillColor()->getType()); self::assertSame('002060', $values->getMarkerBorderColor()->getValue()); self::assertSame('srgbClr', $values->getMarkerBorderColor()->getType()); $values = $plotValues[1]; self::assertSame(7, $values->getPointSize()); self::assertSame('square', $values->getPointMarker()); self::assertSame('accent6', $values->getMarkerFillColor()->getValue()); self::assertSame('schemeClr', $values->getMarkerFillColor()->getType()); self::assertSame(3, $values->getMarkerFillColor()->getAlpha()); self::assertSame('0FF000', $values->getMarkerBorderColor()->getValue()); self::assertSame('srgbClr', $values->getMarkerBorderColor()->getType()); self::assertNull($values->getMarkerBorderColor()->getAlpha()); $values = $plotValues[2]; self::assertSame(7, $values->getPointSize()); self::assertSame('triangle', $values->getPointMarker()); self::assertSame('FFFF00', $values->getMarkerFillColor()->getValue()); self::assertSame('srgbClr', $values->getMarkerFillColor()->getType()); self::assertNull($values->getMarkerFillColor()->getAlpha()); self::assertSame('accent4', $values->getMarkerBorderColor()->getValue()); self::assertSame('schemeClr', $values->getMarkerBorderColor()->getType()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testScatter9(): void { // gradient testing $file = self::DIRECTORY . '32readwriteScatterChart9.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Worksheet', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertFalse($chart->getNoFill()); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); self::assertFalse($plotArea->getNoFill()); self::assertEquals(315.0, $plotArea->getGradientFillAngle()); $stops = $plotArea->getGradientFillStops(); self::assertCount(3, $stops); self::assertEquals(0.43808, $stops[0][0]); self::assertEquals(0, $stops[1][0]); self::assertEquals(0.91, $stops[2][0]); $color = $stops[0][1]; self::assertSame('srgbClr', $color->getType()); self::assertSame('CDDBEC', $color->getValue()); self::assertNull($color->getAlpha()); self::assertSame(20, $color->getBrightness()); $color = $stops[1][1]; self::assertSame('srgbClr', $color->getType()); self::assertSame('FFC000', $color->getValue()); self::assertNull($color->getAlpha()); self::assertNull($color->getBrightness()); $color = $stops[2][1]; self::assertSame('srgbClr', $color->getType()); self::assertSame('00B050', $color->getValue()); self::assertNull($color->getAlpha()); self::assertSame(4, $color->getBrightness()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testScatter10(): void { // nofill for Chart and PlotArea, hidden Axis $file = self::DIRECTORY . '32readwriteScatterChart10.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Worksheet', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertTrue($chart->getNoFill()); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); self::assertTrue($plotArea->getNoFill()); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue589Test.php
tests/PhpSpreadsheetTests/Chart/Issue589Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use DOMDocument; use DOMNode; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as Writer; use PHPUnit\Framework\TestCase; use ZipArchive; class Issue589Test extends TestCase { /** * Build a testable chart in a spreadsheet and set fill color for series. * * @param string|string[] $color HEX color or array with HEX colors */ private function buildChartSpreadsheet(string|array $color): Spreadsheet { // Problem occurs when setting plot line color // The output chart xml file is missing the a:ln tag $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ [2010], [12], [56], ] ); $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$1', null, 1), ]; $dataSeriesLabels[0]->setFillColor($color); $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$A$2:$A$3', null, 2), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_LINECHART, DataSeries::GROUPING_STACKED, range(0, count($dataSeriesValues) - 1), $dataSeriesLabels, [], $dataSeriesValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Create the chart $chart = new Chart( 'chart1', null, null, $plotArea ); // Add the chart to the worksheet $worksheet->addChart($chart); return $spreadsheet; } public function testBadDirectory(): void { $this->expectException(WriterException::class); $this->expectExceptionMessage('Directory does not exist'); $spreadsheet = new Spreadsheet(); $writer = new Writer($spreadsheet); $writer->setUseDiskCaching(true, __FILE__); } public function testLineChartFill(): void { $outputFilename = File::temporaryFilename(); $spreadsheet = $this->buildChartSpreadsheet('98B954'); $writer = new Writer($spreadsheet); $writer->setUseDiskCaching(true, sys_get_temp_dir()); $writer->save($outputFilename, Writer::SAVE_WITH_CHARTS); self::assertTrue($writer->getIncludeCharts()); $zip = new ZipArchive(); $zip->open($outputFilename); $resultChart1Raw = $zip->getFromName('xl/charts/chart1.xml'); $zip->close(); unlink($outputFilename); $dom = new DOMDocument(); if ($resultChart1Raw === false) { self::fail('Unable to open the chart file'); } else { $loaded = $dom->loadXML($resultChart1Raw); if (!$loaded) { self::fail('Unable to load the chart xml'); } else { $series = $dom->getElementsByTagName('ser'); $firstSeries = $series->item(0); if ($firstSeries === null) { self::fail('The chart XML does not contain a \'ser\' tag!'); } else { $spPrList = $firstSeries->getElementsByTagName('spPr'); // expect to see only one element with name 'c:spPr' self::assertCount(1, $spPrList); /** @var DOMNode $node */ $node = $spPrList->item(0); // Get the spPr element $actualXml = $dom->saveXML($node); if ($actualXml === false) { self::fail('Failure saving the spPr element as xml string!'); } else { self::assertSame('<c:spPr><a:ln><a:solidFill><a:srgbClr val="98B954"/></a:solidFill></a:ln></c:spPr>', $actualXml); } } } } } public function testLineChartFillIgnoresColorArray(): void { $outputFilename = File::temporaryFilename(); $spreadsheet = $this->buildChartSpreadsheet(['98B954']); $writer = new Writer($spreadsheet); $writer->setIncludeCharts(true); $writer->save($outputFilename); $zip = new ZipArchive(); $zip->open($outputFilename); $resultChart1Raw = $zip->getFromName('xl/charts/chart1.xml'); $zip->close(); unlink($outputFilename); $dom = new DOMDocument(); if ($resultChart1Raw === false) { self::fail('Unable to open the chart file'); } else { $loaded = $dom->loadXML($resultChart1Raw); if (!$loaded) { self::fail('Unable to load the chart xml'); } else { $series = $dom->getElementsByTagName('ser'); $firstSeries = $series->item(0); if ($firstSeries === null) { self::fail('The chart XML does not contain a \'ser\' tag!'); } else { $spPrList = $firstSeries->getElementsByTagName('spPr'); // expect to see only one element with name 'c:spPr' self::assertCount(1, $spPrList); /** @var DOMNode $node */ $node = $spPrList->item(0); // Get the spPr element $actualXml = $dom->saveXML($node); if ($actualXml === false) { self::fail('Failure saving the spPr element as xml string!'); } else { self::assertSame('<c:spPr><a:ln/></c:spPr>', $actualXml); } } } } } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Charts32CatAxValAxTest.php
tests/PhpSpreadsheetTests/Chart/Charts32CatAxValAxTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PHPUnit\Framework\TestCase; class Charts32CatAxValAxTest extends TestCase { // These tests can only be performed by examining xml. // They are based on sample 33_Chart_Create_Scatter2. private string $outputFileName = ''; private const FORMAT_CODE_DATE_ISO8601_SLASH = 'yyyy/mm/dd'; // not automatically treated as numeric protected function tearDown(): void { if ($this->outputFileName !== '') { unlink($this->outputFileName); $this->outputFileName = ''; } } #[\PHPUnit\Framework\Attributes\DataProvider('providerCatAxValAx')] public function test1CatAx1ValAx(?bool $numeric): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); // changed data to simulate a trend chart - Xaxis are dates; Yaxis are 3 meausurements from each date $worksheet->fromArray( [ ['', 'metric1', 'metric2', 'metric3'], ['=DATEVALUE("2021-01-01")', 12.1, 15.1, 21.1], ['=DATEVALUE("2021-01-04")', 56.2, 73.2, 86.2], ['=DATEVALUE("2021-01-07")', 52.2, 61.2, 69.2], ['=DATEVALUE("2021-01-10")', 30.2, 32.2, 0.2], ] ); $worksheet->getStyle('A2:A5')->getNumberFormat()->setFormatCode(self::FORMAT_CODE_DATE_ISO8601_SLASH); $worksheet->getColumnDimension('A')->setAutoSize(true); $worksheet->setSelectedCells('A1'); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // was 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // was 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // was 2012 ]; // Set the X-Axis Labels // changed from STRING to NUMBER // added 2 additional x-axis values associated with each of the 3 metrics // added FORMATE_CODE_NUMBER $xAxisTickValues = [ //new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$A$2:$A$5', Properties::FORMAT_CODE_DATE, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$A$2:$A$5', Properties::FORMAT_CODE_DATE, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$A$2:$A$5', Properties::FORMAT_CODE_DATE, 4), ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker // added FORMAT_CODE_NUMBER $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', Properties::FORMAT_CODE_NUMBER, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', Properties::FORMAT_CODE_NUMBER, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', Properties::FORMAT_CODE_NUMBER, 4), ]; // Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers $xAxis = new Axis(); //$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE ); if (is_bool($numeric)) { $xAxis->setAxisNumberProperties(self::FORMAT_CODE_DATE_ISO8601_SLASH, $numeric); } else { $xAxis->setAxisNumberProperties(self::FORMAT_CODE_DATE_ISO8601_SLASH); } // Build the dataseries $series = new DataSeries( DataSeries::TYPE_SCATTERCHART, // plotType null, // plotGrouping (Scatter charts don't have any grouping) range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues, // plotValues null, // plotDirection false, // smooth line //DataSeries::STYLE_LINEMARKER // plotStyle DataSeries::STYLE_MARKER // plotStyle ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test Scatter Trend Chart'); $yAxisLabel = new Title('Value ($k)'); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel, // yAxisLabel // added xAxis for correct date display $xAxis, // xAxis ); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('P20'); // Add the chart to the worksheet $worksheet->addChart($chart); $writer = new XlsxWriter($spreadsheet); $writer->setIncludeCharts(true); $this->outputFileName = File::temporaryFilename(); $writer->save($this->outputFileName); $spreadsheet->disconnectWorksheets(); $file = 'zip://'; $file .= $this->outputFileName; $file .= '#xl/charts/chart1.xml'; $data = file_get_contents($file); // confirm that file contains expected tags if ($data === false) { self::fail('Unable to read file'); } elseif ($numeric === true) { self::assertSame(0, substr_count($data, '<c:catAx')); self::assertSame(2, substr_count($data, '<c:valAx')); } else { self::assertSame(1, substr_count($data, '<c:catAx')); self::assertSame(1, substr_count($data, '<c:valAx')); } } public static function providerCatAxValAx(): array { return [ [true], [false], [null], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/BarChartCustomColorsTest.php
tests/PhpSpreadsheetTests/Chart/BarChartCustomColorsTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Layout; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; // based on 33_Chart_create_bar_custom_colors.php class BarChartCustomColorsTest extends AbstractFunctional { public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testBarchartColor(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Custom colors for dataSeries (gray, blue, red, orange) $colors = [ 'cccccc', '*accent1', // use schemeClr, was '00abb8', '/green', // use prstClr, was 'b8292f', 'eb8500', ]; // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels1 = [ new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1 ), // 2011 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues1 = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker // Custom Colors $dataSeriesValues1Element = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4); $dataSeriesValues1Element->setFillColor($colors); $dataSeriesValues1 = [$dataSeriesValues1Element]; // Build the dataseries $series1 = new DataSeries( DataSeries::TYPE_PIECHART, // plotType null, // plotGrouping (Pie charts don't have any grouping) range(0, count($dataSeriesValues1) - 1), // plotOrder $dataSeriesLabels1, // plotLabel $xAxisTickValues1, // plotCategory $dataSeriesValues1 // plotValues ); // Set up a layout object for the Pie chart $layout1 = new Layout(); $layout1->setShowVal(true); $layout1->setShowPercent(true); // Set the series in the plot area $plotArea1 = new PlotArea($layout1, [$series1]); // Set the chart legend $legend1 = new ChartLegend(ChartLegend::POSITION_RIGHT, null, false); $title1 = new Title('Test Pie Chart'); // Create the chart $chart1 = new Chart( 'chart1', // name $title1, // title $legend1, // legend $plotArea1, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel null // no Y-Axis for Pie Chart ); // Set the position where the chart should appear in the worksheet $chart1->setTopLeftPosition('A7'); $chart1->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart1); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $plotArea2 = $chart2->getPlotArea(); self::assertNotNull($plotArea2); $dataSeries2 = $plotArea2->getPlotGroup(); self::assertCount(1, $dataSeries2); $plotValues = $dataSeries2[0]->getPlotValues(); self::assertCount(1, $plotValues); $fillColors = $plotValues[0]->getFillColor(); self::assertSame($colors, $fillColors); $writer = new XlsxWriter($reloadedSpreadsheet); $writer->setIncludeCharts(true); $writerChart = new XlsxWriter\Chart($writer); $data = $writerChart->writeChart($chart2); self::assertSame(1, substr_count($data, '<a:srgbClr val="cccccc"/>')); self::assertSame(1, substr_count($data, '<a:schemeClr val="accent1"/>')); self::assertSame(1, substr_count($data, '<a:prstClr val="green"/>')); self::assertSame(1, substr_count($data, '<a:srgbClr val="eb8500"/>')); self::assertSame(4, substr_count($data, '<c:dPt>')); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/ChartsDynamicTitleTest.php
tests/PhpSpreadsheetTests/Chart/ChartsDynamicTitleTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Writer\Html; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class ChartsDynamicTitleTest extends AbstractFunctional { protected function tearDown(): void { Settings::unsetChartRenderer(); } public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testDynamicTitle(): void { // based on samples/templates/issue.3797.2007.xlsx $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle('Only Sheet'); $sheet->fromArray( [ ['Some Title'], [], [null, null, 'Data'], [null, 'L1', 1.3], [null, 'L2', 1.3], [null, 'L3', 2.3], [null, 'L4', 1.6], [null, 'L5', 1.5], [null, 'L6', 1.4], [null, 'L7', 2.2], [null, 'L8', 1.8], [null, 'L9', 1.1], [null, 'L10', 1.8], [null, 'L11', 1.6], [null, 'L12', 2.7], [null, 'L13', 2.2], [null, 'L14', 1.3], ] ); $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, '\'Only Sheet\'!$B$4', null, 1), // 2010 ]; // Set the X-Axis Labels $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, '\'Only Sheet\'!$B$4:$B$17'), ]; // Set the Data values for each data series we want to plot $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, '\'Only Sheet\'!$C$4:$C$17'), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_BARCHART, // plotType DataSeries::GROUPING_STANDARD, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues, // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); $title = new Title(); $title->setCellReference('\'Only Sheet\'!$A$1'); $font = new Font(); $font->setCap(Font::CAP_ALL); $title->setFont($font); // Create the chart $chart = new Chart( 'chart1', // name $title, // title null, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel null, // yAxisLabel null, // xAxis ); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('G7'); $chart->setBottomRightPosition('N21'); // Add the chart to the worksheet $sheet->addChart($chart); $sheet->setSelectedCells('D1'); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $rsheet = $reloadedSpreadsheet->getActiveSheet(); $charts2 = $rsheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $original = $chart2->getTitle()?->getCalculatedTitle($reloadedSpreadsheet); self::assertSame('Some Title', $original); $rsheet->getCell('A1')->setValue('Changed Title'); self::assertNotNull($chart2->getTitle()); self::assertSame('Changed Title', $chart2->getTitle()->getCalculatedTitle($reloadedSpreadsheet)); self::assertSame(Font::CAP_ALL, $chart2->getTitle()->getFont()?->getCap()); $writer = new Html($reloadedSpreadsheet); Settings::setChartRenderer(\PhpOffice\PhpSpreadsheet\Chart\Renderer\MtJpGraphRenderer::class); $writer->setIncludeCharts(true); $content = $writer->generateHtmlAll(); self::assertStringContainsString('alt="Changed Title"', $content); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/ChartsByNameTest.php
tests/PhpSpreadsheetTests/Chart/ChartsByNameTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class ChartsByNameTest extends TestCase { public function testChartByName(): void { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setTitle('Only Sheet'); $sheet->fromArray( [ ['Some Title'], [], [null, null, 'Data'], [null, 'L1', 1.3], [null, 'L2', 1.3], [null, 'L3', 2.3], [null, 'L4', 1.6], [null, 'L5', 1.5], [null, 'L6', 1.4], [null, 'L7', 2.2], [null, 'L8', 1.8], [null, 'L9', 1.1], [null, 'L10', 1.8], [null, 'L11', 1.6], [null, 'L12', 2.7], [null, 'L13', 2.2], [null, 'L14', 1.3], ] ); $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, '\'Only Sheet\'!$B$4', null, 1), // 2010 ]; // Set the X-Axis Labels $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, '\'Only Sheet\'!$B$4:$B$17'), ]; // Set the Data values for each data series we want to plot $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, '\'Only Sheet\'!$C$4:$C$17'), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_BARCHART, // plotType DataSeries::GROUPING_STANDARD, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues, // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Create the chart $chart = new Chart( name: 'namedchart1', plotArea: $plotArea, ); // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('G7'); $chart->setBottomRightPosition('N21'); // Add the chart to the worksheet $sheet->addChart($chart); $sheet->setSelectedCells('D1'); self::assertSame($chart, $sheet->getChartByName('namedchart1')); self::assertSame($chart, $sheet->getChartByNameOrThrow('namedchart1')); self::assertFalse($sheet->getChartByName('namedchart2')); try { $sheet->getChartByNameOrThrow('namedchart2'); $exceptionRaised = false; } catch (SpreadsheetException $e) { self::assertSame('Sheet does not have a chart named namedchart2.', $e->getMessage()); $exceptionRaised = true; } self::assertTrue($exceptionRaised); $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue3833Test.php
tests/PhpSpreadsheetTests/Chart/Issue3833Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Axis; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class Issue3833Test extends AbstractFunctional { // based on 33_Char_create_scatter2 public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testDisplayUnits1(): void { $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load('tests/data/Reader/XLSX/issue.3833.units.xlsx'); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheetByNameOrThrow('charts'); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $yAxis = $chart2->getChartAxisY(); $dispUnits = $yAxis->getAxisOptionsProperty('dispUnitsBuiltIn'); self::assertSame('tenThousands', $dispUnits); $logBase = $yAxis->getAxisOptionsProperty('logBase'); self::assertNull($logBase); $reloadedSpreadsheet->disconnectWorksheets(); } public function testDisplayUnits2(): void { $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load('tests/data/Reader/XLSX/issue.3833.units.xlsx'); $sheet1 = $spreadsheet->getSheetByNameOrThrow('charts'); $charts1 = $sheet1->getChartCollection(); self::assertCount(1, $charts1); $chart1 = $charts1[0]; self::assertNotNull($chart1); $yAxis1 = $chart1->getChartAxisY(); $yAxis1->setAxisOption('dispUnitsBuiltIn', 1000); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheetByNameOrThrow('charts'); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $yAxis = $chart2->getChartAxisY(); $dispUnits = $yAxis->getAxisOptionsProperty('dispUnitsBuiltIn'); self::assertSame('thousands', $dispUnits); $logBase = $yAxis->getAxisOptionsProperty('logBase'); self::assertNull($logBase); $reloadedSpreadsheet->disconnectWorksheets(); } public function testDisplayUnits3(): void { $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load('tests/data/Reader/XLSX/issue.3833.units.xlsx'); $sheet1 = $spreadsheet->getSheetByNameOrThrow('charts'); $charts1 = $sheet1->getChartCollection(); self::assertCount(1, $charts1); $chart1 = $charts1[0]; self::assertNotNull($chart1); $yAxis1 = $chart1->getChartAxisY(); $yAxis1->setDispUnitsTitle(null); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheetByNameOrThrow('charts'); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $yAxis = $chart2->getChartAxisY(); self::assertNull($yAxis->getDispUnitsTitle()); $reloadedSpreadsheet->disconnectWorksheets(); } public function testLogBase(): void { $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load('tests/data/Reader/XLSX/issue.3833.logarithm.xlsx'); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheetByNameOrThrow('charts'); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); $yAxis = $chart2->getChartAxisY(); $logBase = $yAxis->getAxisOptionsProperty('logBase'); self::assertSame('10', $logBase); $dispUnits = $yAxis->getAxisOptionsProperty('dispUnitsBuiltIn'); self::assertNull($dispUnits); $yAxis->setAxisOption('dispUnitsBuiltIn', 1000000000000); $dispUnits = $yAxis->getAxisOptionsProperty('dispUnitsBuiltIn'); // same logic as in Writer/Xlsx/Chart for 32-bit safety $dispUnits = ($dispUnits == Axis::TRILLION_INDEX) ? Axis::DISP_UNITS_TRILLIONS : (is_numeric($dispUnits) ? (Axis::DISP_UNITS_BUILTIN_INT[(int) $dispUnits] ?? '') : $dispUnits); self::assertSame('trillions', $dispUnits); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/MultiplierTest.php
tests/PhpSpreadsheetTests/Chart/MultiplierTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PHPUnit\Framework\TestCase; class MultiplierTest extends TestCase { public function testMultiplier(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2010 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4), ]; // Build the dataseries $series = new DataSeries( DataSeries::TYPE_AREACHART, // plotType DataSeries::GROUPING_PERCENT_STACKED, // plotGrouping range(0, count($dataSeriesValues) - 1), // plotOrder $dataSeriesLabels, // plotLabel $xAxisTickValues, // plotCategory $dataSeriesValues // plotValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Set the chart legend $legend = new ChartLegend(ChartLegend::POSITION_TOPRIGHT, null, false); $title = new Title('Test %age-Stacked Area Chart'); $yAxisLabel = new Title('Value ($k)'); // Create the chart $chart = new Chart( 'chart1', // name $title, // title $legend, // legend $plotArea, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel $yAxisLabel // yAxisLabel ); $xAxis = $chart->getChartAxisX(); $expectedX = [ 'effect' => 'outerShdw', 'algn' => 'bl', 'blur' => 6, 'direction' => 315, 'distance' => 3, 'rotWithShape' => 0, 'size' => [ 'sx' => null, 'sy' => 254, 'kx' => -94, 'ky' => null, ], 'color' => [ 'type' => ChartColor::EXCEL_COLOR_TYPE_RGB, 'value' => 'FF0000', 'alpha' => 20, ], ]; $expectedXmlX = [ '<a:outerShdw ', ' algn="bl"', ' blurRad="76200"', ' dir="18900000"', ' dist="38100"', ' rotWithShape="0"', ' sy="25400000"', ' kx="-5640000"', '<a:srgbClr val="FF0000">', '<a:alpha val="80000"/>', ]; $expectedXmlNoX = [ ' sx=', ' ky=', ]; foreach ($expectedX as $key => $value) { $xAxis->setShadowProperty($key, $value); } // Set the position where the chart should appear in the worksheet $chart->setTopLeftPosition('A7'); $chart->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart); $writer = new XlsxWriter($spreadsheet); $writer->setIncludeCharts(true); $writerChart = new XlsxWriter\Chart($writer); $data = $writerChart->writeChart($chart); // confirm that file contains expected tags foreach ($expectedXmlX as $expected) { self::assertSame(1, substr_count($data, $expected), $expected); } foreach ($expectedXmlNoX as $expected) { self::assertSame(0, substr_count($data, $expected), $expected); } $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/PlotAreaTest.php
tests/PhpSpreadsheetTests/Chart/PlotAreaTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Exception as ChartException; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PHPUnit\Framework\TestCase; class PlotAreaTest extends TestCase { public function testPlotArea(): void { $dataSeriesValues = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, null, null, 4, [1, 2, 3, 4]), ]; // Build the dataseries $series = new DataSeries( plotType: DataSeries::TYPE_AREACHART, plotGrouping: DataSeries::GROUPING_PERCENT_STACKED, plotOrder: range(0, count($dataSeriesValues) - 1), plotValues: $dataSeriesValues ); // Set the series in the plot area $plotArea = new PlotArea(null, [$series]); // Create the chart $chart = new Chart( 'chart1', // name plotArea: $plotArea, ); self::assertNotNull($chart->getPlotArea()); } public function testNoPlotArea(): void { $chart = new Chart('chart1'); $this->expectException(ChartException::class); $this->expectExceptionMessage('Chart has no PlotArea'); $chart->getPlotAreaOrThrow(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Charts32ColoredAxisLabelTest.php
tests/PhpSpreadsheetTests/Chart/Charts32ColoredAxisLabelTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\Run; use PhpOffice\PhpSpreadsheet\Style\Font; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class Charts32ColoredAxisLabelTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testStock5(): void { $file = self::DIRECTORY . '32readwriteStockChart5.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getActiveSheet(); self::assertSame(1, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getActiveSheet(); self::assertSame('Charts', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); $xAxisLabel = $chart->getXAxisLabel(); self::assertNotNull($xAxisLabel); $captionArray = $xAxisLabel->getCaption(); self::assertIsArray($captionArray); self::assertCount(1, $captionArray); $caption = $captionArray[0]; self::assertInstanceOf(RichText::class, $caption); self::assertSame('X-Axis Title in Green', $caption->getPlainText()); $elements = $caption->getRichTextElements(); self::assertCount(1, $elements); $run = $elements[0]; self::assertInstanceOf(Run::class, $run); $font = $run->getFont(); self::assertInstanceOf(Font::class, $font); $chartColor = $font->getChartColor(); self::assertNotNull($chartColor); self::assertSame('00B050', $chartColor->getValue()); self::assertSame('srgbClr', $chartColor->getType()); $yAxisLabel = $chart->getYAxisLabel(); self::assertNotNull($yAxisLabel); $captionArray = $yAxisLabel->getCaption(); self::assertIsArray($captionArray); self::assertCount(1, $captionArray); $caption = $captionArray[0]; self::assertInstanceOf(RichText::class, $caption); self::assertSame('Y-Axis Title in Red', $caption->getPlainText()); $elements = $caption->getRichTextElements(); self::assertCount(1, $elements); $run = $elements[0]; self::assertInstanceOf(Run::class, $run); $font = $run->getFont(); self::assertInstanceOf(Font::class, $font); $chartColor = $font->getChartColor(); self::assertNotNull($chartColor); self::assertSame('FF0000', $chartColor->getValue()); self::assertSame('srgbClr', $chartColor->getType()); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/Issue2077Test.php
tests/PhpSpreadsheetTests/Chart/Issue2077Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Layout; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PHPUnit\Framework\TestCase; class Issue2077Test extends TestCase { public function testPercentLabels(): void { $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', '2010', '2011', '2012'], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 60], ] ); // Set the Labels for each data series we want to plot $dataSeriesLabels1 = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$B$1', null, 1), // 2011 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2012 new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2013 ]; // Set the X-Axis Labels $xAxisTickValues1 = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // TODO I think the third parameter can be set,but I didn't succeed $dataSeriesValues1 = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$5', null, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', NumberFormat::FORMAT_NUMBER_00, 4), new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', NumberFormat::FORMAT_PERCENTAGE_00, 4), ]; // Build the dataseries $series1 = [ new DataSeries( DataSeries::TYPE_PIECHART, // plotType null, // plotGrouping (Pie charts don't have any grouping) range(0, count($dataSeriesValues1) - 1), // plotOrder $dataSeriesLabels1, // plotLabel $xAxisTickValues1, // plotCategory $dataSeriesValues1 // plotValues ), ]; // Set up a layout object for the Pie chart $layout1 = new Layout(); $layout1->setShowVal(true); // Set the layout to show percentage with 2 decimal points $layout1->setShowPercent(true); $layout1->setNumFmtCode(NumberFormat::FORMAT_PERCENTAGE_00); // Set the series in the plot area $plotArea1 = new PlotArea($layout1, $series1); // Set the chart legend $legend1 = new ChartLegend(ChartLegend::POSITION_RIGHT, null, false); $title1 = new Title('Test Pie Chart'); $yAxisLabel = new Title('Value ($k)'); // Create the chart $chart1 = new Chart( 'chart1', // name $title1, // title $legend1, // legend $plotArea1, // plotArea true, // plotVisibleOnly 'gap', // displayBlanksAs null, // xAxisLabel $yAxisLabel ); // Set the position where the chart should appear in the worksheet $chart1->setTopLeftPosition('A7'); $chart1->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart1); $writer = new XlsxWriter($spreadsheet); $writer->setIncludeCharts(true); $writerChart = new XlsxWriter\Chart($writer); $data = $writerChart->writeChart($chart1); self::assertStringContainsString('<c:dLbls><c:numFmt formatCode="0.00%" sourceLinked="0"/><c:showVal val="1"/><c:showPercent val="1"/></c:dLbls>', $data); $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/ChartCloneTest.php
tests/PhpSpreadsheetTests/Chart/ChartCloneTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Chart\Chart; use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues; use PhpOffice\PhpSpreadsheet\Chart\Layout; use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend; use PhpOffice\PhpSpreadsheet\Chart\PlotArea; use PhpOffice\PhpSpreadsheet\Chart\Properties; use PhpOffice\PhpSpreadsheet\Chart\Title; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class ChartCloneTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function testCloneSheet(): void { $file = self::DIRECTORY . '32readwriteLineChart5.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $oldSheet = $spreadsheet->getActiveSheet(); $sheet = clone $oldSheet; $sheet->setTitle('test2'); $spreadsheet->addsheet($sheet); $oldCharts = $oldSheet->getChartCollection(); self::assertCount(1, $oldCharts); $oldChart = $oldCharts[0]; self::assertNotNull($oldChart); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertNotSame($oldChart, $chart); self::assertSame('ffffff', $chart->getFillColor()->getValue()); self::assertSame('srgbClr', $chart->getFillColor()->getType()); self::assertSame('d9d9d9', $chart->getBorderLines()->getLineColorProperty('value')); self::assertSame('srgbClr', $chart->getBorderLines()->getLineColorProperty('type')); self::assertEqualsWithDelta(9360 / Properties::POINTS_WIDTH_MULTIPLIER, $chart->getBorderLines()->getLineStyleProperty('width'), 1.0E-8); self::assertTrue($chart->getChartAxisY()->getNoFill()); self::assertFalse($chart->getChartAxisX()->getNoFill()); $spreadsheet->disconnectWorksheets(); } public function testCloneSheetWithLegendAndTitle(): void { $file = self::DIRECTORY . '32readwriteChartWithImages1.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $oldSheet = $spreadsheet->getActiveSheet(); $sheet = clone $oldSheet; $sheet->setTitle('test2'); $spreadsheet->addsheet($sheet); $oldCharts = $oldSheet->getChartCollection(); self::assertCount(1, $oldCharts); $oldChart = $oldCharts[0]; self::assertNotNull($oldChart); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertNotSame($oldChart, $chart); self::assertNotNull($chart->getLegend()); self::assertNotSame($chart->getLegend(), $oldChart->getLegend()); self::assertNotNull($chart->getTitle()); self::assertNotSame($chart->getTitle(), $oldChart->getTitle()); $spreadsheet->disconnectWorksheets(); } public function testCloneSheetWithBubbleSizes(): void { $file = self::DIRECTORY . '32readwriteBubbleChart2.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $oldSheet = $spreadsheet->getActiveSheet(); $sheet = clone $oldSheet; $sheet->setTitle('test2'); $spreadsheet->addsheet($sheet); $oldCharts = $oldSheet->getChartCollection(); self::assertCount(1, $oldCharts); $oldChart = $oldCharts[0]; self::assertNotNull($oldChart); $charts = $sheet->getChartCollection(); self::assertCount(1, $charts); $chart = $charts[0]; self::assertNotNull($chart); self::assertNotSame($oldChart, $chart); $oldGroup = $oldChart->getPlotArea()?->getPlotGroup(); self::assertNotNull($oldGroup); self::assertCount(1, $oldGroup); $oldSizes = $oldGroup[0]->getPlotBubbleSizes(); self::assertCount(2, $oldSizes); $plotGroup = $chart->getPlotArea()?->getPlotGroup(); self::assertNotNull($plotGroup); self::assertCount(1, $plotGroup); $bubbleSizes = $plotGroup[0]->getPlotBubbleSizes(); self::assertCount(2, $bubbleSizes); self::assertNotSame($bubbleSizes, $oldSizes); $spreadsheet->disconnectWorksheets(); } public function testCloneSheetWithTrendLines(): void { $file = self::DIRECTORY . '32readwriteScatterChartTrendlines1.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $oldSheet = $spreadsheet->getActiveSheet(); $sheet = clone $oldSheet; $sheet->setTitle('test2'); $spreadsheet->addsheet($sheet); $oldCharts = $oldSheet->getChartCollection(); self::assertCount(2, $oldCharts); $oldChart = $oldCharts[1]; self::assertNotNull($oldChart); $charts = $sheet->getChartCollection(); self::assertCount(2, $charts); $chart = $charts[1]; self::assertNotNull($chart); self::assertNotSame($oldChart, $chart); $oldGroup = $chart->getPlotArea()?->getPlotGroup(); self::assertNotNull($oldGroup); self::assertCount(1, $oldGroup); $oldLabels = $oldGroup[0]->getPlotLabels(); self::assertCount(1, $oldLabels); self::assertCount(3, $oldLabels[0]->getTrendLines()); $plotGroup = $chart->getPlotArea()?->getPlotGroup(); self::assertNotNull($plotGroup); self::assertCount(1, $plotGroup); $plotLabels = $plotGroup[0]->getPlotLabels(); self::assertCount(1, $plotLabels); self::assertCount(3, $plotLabels[0]->getTrendLines()); $spreadsheet->disconnectWorksheets(); } public function testCloneFillColorArray(): void { // code borrowed from BarChartCustomColorsTest $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); $worksheet->fromArray( [ ['', 2010, 2011, 2012], ['Q1', 12, 15, 21], ['Q2', 56, 73, 86], ['Q3', 52, 61, 69], ['Q4', 30, 32, 0], ] ); // Custom colors for dataSeries (gray, blue, red, orange) $colors = [ 'cccccc', '*accent1', // use schemeClr, was '00abb8', '/green', // use prstClr, was 'b8292f', 'eb8500', ]; // Set the Labels for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $dataSeriesLabels1 = [ new DataSeriesValues( DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1 ), // 2011 ]; // Set the X-Axis Labels // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker $xAxisTickValues1 = [ new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4 ]; // Set the Data values for each data series we want to plot // Datatype // Cell reference for data // Format Code // Number of datapoints in series // Data values // Data Marker // Custom Colors $dataSeriesValues1Element = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4); $dataSeriesValues1Element->setFillColor($colors); $dataSeriesValues1 = [$dataSeriesValues1Element]; // Build the dataseries $series1 = new DataSeries( DataSeries::TYPE_PIECHART, // plotType null, // plotGrouping (Pie charts don't have any grouping) range(0, count($dataSeriesValues1) - 1), // plotOrder $dataSeriesLabels1, // plotLabel $xAxisTickValues1, // plotCategory $dataSeriesValues1 // plotValues ); // Set up a layout object for the Pie chart $layout1 = new Layout(); $layout1->setShowVal(true); $layout1->setShowPercent(true); // Set the series in the plot area $plotArea1 = new PlotArea($layout1, [$series1]); // Set the chart legend $legend1 = new ChartLegend(ChartLegend::POSITION_RIGHT, null, false); $title1 = new Title('Test Pie Chart'); // Create the chart $chart1 = new Chart( 'chart1', // name $title1, // title $legend1, // legend $plotArea1, // plotArea true, // plotVisibleOnly DataSeries::EMPTY_AS_GAP, // displayBlanksAs null, // xAxisLabel null // no Y-Axis for Pie Chart ); // Set the position where the chart should appear in the worksheet $chart1->setTopLeftPosition('A7'); $chart1->setBottomRightPosition('H20'); // Add the chart to the worksheet $worksheet->addChart($chart1); $sheet = clone $worksheet; $sheet->setTitle('test2'); $spreadsheet->addsheet($sheet); $charts2 = $sheet->getChartCollection(); self::assertCount(1, $charts2); $chart2 = $charts2[0]; self::assertNotNull($chart2); self::assertSame('Test Pie Chart', $chart2->getTitle()?->getCaption()); $plotArea2 = $chart2->getPlotArea(); self::assertNotNull($plotArea2); $dataSeries2 = $plotArea2->getPlotGroup(); self::assertCount(1, $dataSeries2); $plotValues = $dataSeries2[0]->getPlotValues(); self::assertCount(1, $plotValues); $fillColors = $plotValues[0]->getFillColor(); self::assertSame($colors, $fillColors); $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Chart/TrendLineTest.php
tests/PhpSpreadsheetTests/Chart/TrendLineTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Chart; use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class TrendLineTest extends AbstractFunctional { private const DIRECTORY = 'samples' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR; public function readCharts(XlsxReader $reader): void { $reader->setIncludeCharts(true); } public function writeCharts(XlsxWriter $writer): void { $writer->setIncludeCharts(true); } public function testTrendLine(): void { $file = self::DIRECTORY . '32readwriteScatterChartTrendlines1.xlsx'; $reader = new XlsxReader(); $reader->setIncludeCharts(true); $spreadsheet = $reader->load($file); $sheet = $spreadsheet->getSheet(1); self::assertSame(2, $sheet->getChartCount()); /** @var callable */ $callableReader = [$this, 'readCharts']; /** @var callable */ $callableWriter = [$this, 'writeCharts']; $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx', $callableReader, $callableWriter); $spreadsheet->disconnectWorksheets(); $sheet = $reloadedSpreadsheet->getSheet(1); self::assertSame('Scatter Chart', $sheet->getTitle()); $charts = $sheet->getChartCollection(); self::assertCount(2, $charts); $chart = $charts[0]; self::assertNotNull($chart); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $plotSeriesArray = $plotArea->getPlotGroup(); self::assertCount(1, $plotSeriesArray); $plotSeries = $plotSeriesArray[0]; $valuesArray = $plotSeries->getPlotValues(); self::assertCount(3, $valuesArray); self::assertEmpty($valuesArray[0]->getTrendLines()); self::assertEmpty($valuesArray[1]->getTrendLines()); self::assertEmpty($valuesArray[2]->getTrendLines()); $chart = $charts[1]; self::assertNotNull($chart); $plotArea = $chart->getPlotArea(); self::assertNotNull($plotArea); $plotSeriesArray = $plotArea->getPlotGroup(); self::assertCount(1, $plotSeriesArray); $plotSeries = $plotSeriesArray[0]; $valuesArray = $plotSeries->getPlotValues(); self::assertCount(1, $valuesArray); $trendLines = $valuesArray[0]->getTrendLines(); self::assertCount(3, $trendLines); $trendLine = $trendLines[0]; self::assertSame('linear', $trendLine->getTrendLineType()); self::assertFalse($trendLine->getDispRSqr()); self::assertFalse($trendLine->getDispEq()); $lineColor = $trendLine->getLineColor(); self::assertSame('accent4', $lineColor->getValue()); self::assertSame('stealth', $trendLine->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals(0.5, $trendLine->getLineStyleProperty('width')); self::assertSame('', $trendLine->getName()); self::assertSame(0.0, $trendLine->getBackward()); self::assertSame(0.0, $trendLine->getForward()); self::assertSame(0.0, $trendLine->getIntercept()); $trendLine = $trendLines[1]; self::assertSame('poly', $trendLine->getTrendLineType()); self::assertTrue($trendLine->getDispRSqr()); self::assertTrue($trendLine->getDispEq()); $lineColor = $trendLine->getLineColor(); self::assertSame('accent3', $lineColor->getValue()); self::assertNull($trendLine->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals(1.25, $trendLine->getLineStyleProperty('width')); self::assertSame('metric3 polynomial', $trendLine->getName()); self::assertSame(20.0, $trendLine->getBackward()); self::assertSame(28.0, $trendLine->getForward()); self::assertSame(14400.5, $trendLine->getIntercept()); $trendLine = $trendLines[2]; self::assertSame('movingAvg', $trendLine->getTrendLineType()); self::assertTrue($trendLine->getDispRSqr()); self::assertFalse($trendLine->getDispEq()); $lineColor = $trendLine->getLineColor(); self::assertSame('accent2', $lineColor->getValue()); self::assertNull($trendLine->getLineStyleProperty(['arrow', 'head', 'type'])); self::assertEquals(1.5, $trendLine->getLineStyleProperty('width')); self::assertSame('', $trendLine->getName()); self::assertSame(0.0, $trendLine->getBackward()); self::assertSame(0.0, $trendLine->getForward()); self::assertSame(0.0, $trendLine->getIntercept()); $reloadedSpreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Issue1324Test.php
tests/PhpSpreadsheetTests/Shared/Issue1324Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Csv as CsvWriter; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class Issue1324Test extends AbstractFunctional { public function testPrecision(): void { $string1 = '753.149999999999'; $s1 = (float) $string1; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue($s1); self::assertNotSame(753.15, $sheet->getCell('A1')->getValue()); $formats = ['Csv', 'Xlsx', 'Xls', 'Ods', 'Html']; foreach ($formats as $format) { $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format); $rsheet = $reloadedSpreadsheet->getActiveSheet(); $s2 = $rsheet->getCell('A1')->getValue(); self::assertSame($s1, $s2, "difference for $format"); $reloadedSpreadsheet->disconnectWorksheets(); } $spreadsheet->disconnectWorksheets(); } public function testCsv(): void { $string1 = '753.149999999999'; $s1 = (float) $string1; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue($s1); $writer = new CsvWriter($spreadsheet); ob_start(); $writer->save('php://output'); $output = (string) ob_get_clean(); self::assertStringContainsString($string1, $output); $spreadsheet->disconnectWorksheets(); } public static function testLessPrecision(): void { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $inArray = [ [123.4, 753.149999999999, 12.04, 224.245], [12345.6789, 44125.62188657407387], [true, 16, 'hello'], [753.149999999999, 44125.62188657407387], ]; $sheet->fromArray($inArray, null, 'A1', true); $sheet->getStyle('A4:B4')->getNumberFormat() ->setFormatCode('#.##'); $precise = $sheet->toArray(); $expectedPrecise = [ ['123.40000000000001', '753.14999999999895', '12.039999999999999', '224.245'], ['12345.67890000000079', '44125.62188657407387', null, null], ['TRUE', '16', 'hello', null], ['753.15', '44125.62', null, null], ]; self::assertSame($expectedPrecise, $precise); $lessPrecise = $sheet->toArray(lessFloatPrecision: true); $expectedLessPrecise = [ ['123.4', '753.15', '12.04', '224.245'], ['12345.6789', '44125.621886574', null, null], ['TRUE', '16', 'hello', null], ['753.15', '44125.62', null, null], ]; self::assertSame($expectedLessPrecise, $lessPrecise); $spreadsheet->disconnectWorksheets(); $preg = '/^[-+]?\d+[.]\d+$/'; $diffs = []; for ($i = 0; $i < 2; ++$i) { $preciseRow = $precise[$i]; $lessPreciseRow = $lessPrecise[$i]; $entries = count($preciseRow); for ($j = 0; $j < $entries; ++$j) { $comparand1 = $preciseRow[$j]; $comparand2 = $lessPreciseRow[$j]; if (preg_match($preg, $comparand1 ?? '') && preg_match($preg, $comparand2 ?? '')) { $comparand1 = (float) $comparand1; $comparand2 = (float) $comparand2; } if ($comparand1 !== $comparand2) { $diffs[] = [$i, $j]; } } } self::assertSame([[0, 1], [1, 1]], $diffs, 'cells which do not evaluate to same float value'); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/SpgrContainerTest.php
tests/PhpSpreadsheetTests/Shared/SpgrContainerTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer; use PHPUnit\Framework\TestCase; class SpgrContainerTest extends TestCase { public function testParent(): void { $container = new SpgrContainer(); $contained = new SpgrContainer(); $contained->setParent($container); self::assertSame($container, $contained->getParent()); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/StringHelperNoIntl.php
tests/PhpSpreadsheetTests/Shared/StringHelperNoIntl.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; class StringHelperNoIntl extends StringHelper { protected static string $testClass = 'simulateIntlUnavilable'; }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/FontTest.php
tests/PhpSpreadsheetTests/Shared/FontTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Font; use PhpOffice\PhpSpreadsheet\Style\Font as StyleFont; use PHPUnit\Framework\TestCase; class FontTest extends TestCase { const FONT_PRECISION = 1.0E-12; public function testGetAutoSizeMethod(): void { $expectedResult = Font::AUTOSIZE_METHOD_APPROX; $result = Font::getAutoSizeMethod(); self::assertEquals($expectedResult, $result); } public function testSetAutoSizeMethod(): void { $autosizeMethodValues = [ Font::AUTOSIZE_METHOD_EXACT, Font::AUTOSIZE_METHOD_APPROX, ]; foreach ($autosizeMethodValues as $autosizeMethodValue) { $result = Font::setAutoSizeMethod($autosizeMethodValue); self::assertTrue($result); } } public function testSetAutoSizeMethodWithInvalidValue(): void { $unsupportedAutosizeMethod = 'guess'; $result = Font::setAutoSizeMethod($unsupportedAutosizeMethod); self::assertFalse($result); } #[\PHPUnit\Framework\Attributes\DataProvider('providerFontSizeToPixels')] public function testFontSizeToPixels(float|int $expectedResult, float|int $size): void { $result = Font::fontSizeToPixels($size); self::assertEquals($expectedResult, $result); } public static function providerFontSizeToPixels(): array { return require 'tests/data/Shared/FontSizeToPixels.php'; } #[\PHPUnit\Framework\Attributes\DataProvider('providerInchSizeToPixels')] public function testInchSizeToPixels(float|int $expectedResult, float|int $size): void { $result = Font::inchSizeToPixels($size); self::assertEqualsWithDelta($expectedResult, $result, self::FONT_PRECISION); } public static function providerInchSizeToPixels(): array { return require 'tests/data/Shared/InchSizeToPixels.php'; } #[\PHPUnit\Framework\Attributes\DataProvider('providerCentimeterSizeToPixels')] public function testCentimeterSizeToPixels(float $expectedResult, float $size): void { $result = Font::centimeterSizeToPixels($size); self::assertEqualsWithDelta($expectedResult, $result, self::FONT_PRECISION); } public static function providerCentimeterSizeToPixels(): array { return require 'tests/data/Shared/CentimeterSizeToPixels.php'; } public function testVerdanaRotation(): void { $font = new StyleFont(); $font->setName('Verdana')->setSize(10); $width = Font::getTextWidthPixelsApprox('n', $font, 0); self::assertEquals(8, $width); $width = Font::getTextWidthPixelsApprox('n', $font, 45); self::assertEquals(7, $width); $width = Font::getTextWidthPixelsApprox('n', $font, -165); self::assertEquals(4, $width); } #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculateApproximateColumnWidth')] public function testCalculateApproximateColumnWidth( float $expectedWidth, StyleFont $font, string $text, int $rotation, StyleFont $defaultFont, bool $filter, int $indent ): void { $columnWidth = Font::calculateColumnWidth($font, $text, $rotation, $defaultFont, $filter, $indent); self::assertEquals($expectedWidth, $columnWidth); } public static function providerCalculateApproximateColumnWidth(): array { return [ [13.9966, new StyleFont(), 'Hello World', 0, new StyleFont(), false, 0], [16.2817, new StyleFont(), 'Hello World', 0, new StyleFont(), true, 0], [16.2817, new StyleFont(), 'Hello World', 0, new StyleFont(), false, 1], [18.7097, new StyleFont(), 'Hello World', 0, new StyleFont(), false, 2], [20.9949, new StyleFont(), 'Hello World', 0, new StyleFont(), false, 3], [6.9983, new StyleFont(), "Hello\nWorld", 0, new StyleFont(), false, 0], [9.2834, new StyleFont(), "Hello\nWorld", 0, new StyleFont(), true, 0], [17.5671, new StyleFont(), 'PhpSpreadsheet', 0, new StyleFont(), false, 0], [19.8523, new StyleFont(), 'PhpSpreadsheet', 0, new StyleFont(), false, 1], 'CJK characters width must be >= 43.00' => [55.2722, new StyleFont(), '如果某一列是CJK 其中的一种,这样的设置方式无效', 0, new StyleFont(), false, 0], 'non-CJK characters width must be >= 24.73' => [31.7065, new StyleFont(), 'abcdefghijklmnopqrstuvwxyz', 0, new StyleFont(), false, 0], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/XmlWriterTest.php
tests/PhpSpreadsheetTests/Shared/XmlWriterTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; use PhpOffice\PhpSpreadsheet\Shared\XMLWriter; use PHPUnit\Framework\TestCase; class XmlWriterTest extends TestCase { private bool $debugEnabled; protected function setUp(): void { $this->debugEnabled = XMLWriter::$debugEnabled; } protected function tearDown(): void { XMLWriter::$debugEnabled = $this->debugEnabled; } public function testUnserialize(): void { $this->expectException(SpreadsheetException::class); $this->expectExceptionMessage('Unserialize not permitted'); $className = XMLWriter::class; $classLen = strlen($className); $text = "O:$classLen:\"$className\":1:{"; $text2 = "\x00$className\x00tempFileName"; $text2Len = strlen($text2); $text .= "s:$text2Len:\"$text2\""; $text .= ';s:0:"";}'; unserialize($text); } public function testDebugEnabled(): void { XMLWriter::$debugEnabled = true; $indent = ' '; $indentnl = "\n"; $objWriter = new XMLWriter(); $objWriter->startDocument('1.0', 'UTF-8', 'yes'); $expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n"; $objWriter->startElement('root'); $expected .= '<root>' . $indentnl; $objWriter->startElement('node'); $expected .= $indent . '<node>'; $objWriter->writeRawData('xyz'); $expected .= 'xyz'; $objWriter->writeRawData(null); $objWriter->writeRawData(['12', '34', '5']); $expected .= "12\n34\n5"; $objWriter->endElement(); // node $expected .= '</node>' . $indentnl; $objWriter->endElement(); // root $expected .= '</root>' . $indentnl; self::assertSame($expected, $objWriter->getData()); } public function testDiskCache(): void { XMLWriter::$debugEnabled = false; $indent = ''; $indentnl = ''; $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK); $objWriter->startDocument('1.0', 'UTF-8', 'yes'); $expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n"; $objWriter->startElement('root'); $expected .= '<root>' . $indentnl; $objWriter->startElement('node'); $expected .= $indent . '<node>'; $objWriter->writeRawData('xyz'); $expected .= 'xyz'; $objWriter->writeRawData(null); $objWriter->writeRawData(['12', '34', '5']); $expected .= "12\n34\n5"; $objWriter->endElement(); // node $expected .= '</node>' . $indentnl; $objWriter->endElement(); // root $expected .= '</root>' . $indentnl; self::assertSame($expected, $objWriter->getData()); } public function testFallbackToMemory(): void { XMLWriter::$debugEnabled = false; $indent = ''; $indentnl = ''; $objWriter = new XMLWriterNoUri(XMLWriter::STORAGE_DISK); $objWriter->startDocument('1.0', 'UTF-8', 'yes'); $expected = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n"; $objWriter->startElement('root'); $expected .= '<root>' . $indentnl; $objWriter->startElement('node'); $expected .= $indent . '<node>'; $objWriter->writeRawData('xyz'); $expected .= 'xyz'; $objWriter->writeRawData(null); $objWriter->writeRawData(['12', '34', '5']); $expected .= "12\n34\n5"; $objWriter->endElement(); // node $expected .= '</node>' . $indentnl; $objWriter->endElement(); // root $expected .= '</root>' . $indentnl; self::assertSame($expected, $objWriter->getData()); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/StringHelperInvalidCharTest.php
tests/PhpSpreadsheetTests/Shared/StringHelperInvalidCharTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class StringHelperInvalidCharTest extends TestCase { public function testInvalidChar(): void { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $substitution = '�'; $array = [ ['Normal string', 'Hello', 'Hello'], ['integer', 2, 2], ['float', 2.1, 2.1], ['boolean true', true, true], ['illegal FFFE/FFFF', "H\xef\xbf\xbe\xef\xbf\xbfello", "H{$substitution}{$substitution}ello"], ['illegal character', "H\xef\x00\x00ello", "H{$substitution}\x00\x00ello"], ['overlong character', "H\xc0\xa0ello", "H{$substitution}{$substitution}ello"], ['Osmanya as single character', "H\xf0\x90\x90\x80ello", 'H𐐀ello'], ['Osmanya as surrogate pair (x)', "\xed\xa0\x81\xed\xb0\x80", "{$substitution}{$substitution}{$substitution}{$substitution}{$substitution}{$substitution}"], ['Osmanya as surrogate pair (u)', "\u{d801}\u{dc00}", "{$substitution}{$substitution}{$substitution}{$substitution}{$substitution}{$substitution}"], ['Half surrogate pair (u)', "\u{d801}", "{$substitution}{$substitution}{$substitution}"], ['Control character', "\u{7}", "\u{7}"], ]; $sheet->fromArray($array); $row = 0; foreach ($array as $value) { self::assertSame($value[1] === $value[2], StringHelper::isUTF8((string) $value[1])); ++$row; $expected = $value[2]; self::assertIsString($sheet->getCell("A$row")->getValue()); self::assertSame( $expected, $sheet->getCell("B$row")->getValue(), $sheet->getCell("A$row")->getValue() ); } $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/ExactFontTest.php
tests/PhpSpreadsheetTests/Shared/ExactFontTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\RichText\RichText; use PhpOffice\PhpSpreadsheet\RichText\Run; use PhpOffice\PhpSpreadsheet\Shared\Font; use PhpOffice\PhpSpreadsheet\Style\Font as StyleFont; use PHPUnit\Framework\TestCase; class ExactFontTest extends TestCase { // Results from this test are not necessarily portable between // systems and Php Releases. // See https://github.com/php/php-src/issues/9073 // Extra tests are added to determine if test should // be marked incomplete. const EXTRA_FONTS = [ 'DejaVu Sans' => [ 'x' => 'DejaVuSans.ttf', 'xb' => 'DejaVuSans-Bold.ttf', 'xi' => 'DejaVuSans-Oblique.ttf', 'xbi' => 'DejaVuSans-BoldOblique.ttf', ], 'DejaVu Sans Mono' => [ 'x' => 'DejaVuSansMono.ttf', 'xb' => 'DejaVuSansMono-Bold.ttf', 'xi' => 'DejaVuSansMono-Oblique.ttf', 'xbi' => 'DejaVuSansMono-BoldOblique.ttf', ], 'DejaVu Serif Condensed' => [ 'x' => 'DejaVuSerifCondensed.ttf', 'xb' => 'DejaVuSerifCondensed-Bold.ttf', 'xi' => 'DejaVuSerifCondensed-Italic.ttf', 'xbi' => 'DejaVuSerifCondensed-BoldItalic.ttf', ], ]; private string $holdDirectory; private string $holdAutoSizeMethod; private string $directoryName = ''; private string $incompleteMessage = ''; private const KNOWN_MD5 = [ '6a15e0a7c0367ba77a959ea27ebf11cf', 'b0e31de57cd5307954a3c54136ce68ae', 'be189a7e2711cdf2a7f6275c60cbc7e2', ]; private float|int|null $paddingAmountExact; protected function setUp(): void { $this->paddingAmountExact = Font::getPaddingAmountExact(); $this->holdDirectory = Font::getTrueTypeFontPath(); $this->holdAutoSizeMethod = Font::getAutoSizeMethod(); $direc = realpath('vendor/mpdf/mpdf/ttfonts') . DIRECTORY_SEPARATOR; $fontFile = 'DejaVuSans.ttf'; $fontPath = $direc . $fontFile; $this->incompleteMessage = ''; if (@is_readable($fontPath)) { $hash = md5_file($fontPath); if (!in_array($hash, self::KNOWN_MD5, true)) { $this->incompleteMessage = "Unrecognized Font file MD5 hash $hash"; } } else { $this->incompleteMessage = 'Unable to locate font file'; } $this->directoryName = $direc; } protected function tearDown(): void { Font::setTrueTypeFontPath($this->holdDirectory); Font::setAutoSizeMethod($this->holdAutoSizeMethod); Font::setPaddingAmountExact($this->paddingAmountExact); $this->directoryName = ''; } #[\PHPUnit\Framework\Attributes\DataProvider('providerFontData')] public function testExact(string $fontName, float $excelWidth, float $xmlWidth, float $winWidth, float $ubuntuWidth): void { if ($this->incompleteMessage !== '') { self::markTestIncomplete($this->incompleteMessage); } $font = new StyleFont(); $font->setName($fontName); $font->setSize(11); Font::setTrueTypeFontPath($this->directoryName); Font::setExtraFontArray(self::EXTRA_FONTS); Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_EXACT); $exactWidth = Font::calculateColumnWidth($font, "This is $fontName"); Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_APPROX); $approxWidth = Font::calculateColumnWidth($font, "This is $fontName"); if ($excelWidth > 0) { self::assertGreaterThanOrEqual(max($excelWidth, $xmlWidth), $exactWidth); // Give ourselves a little wiggle room on upper bound. self::assertLessThanOrEqual(1.05 * max($winWidth, $ubuntuWidth), $exactWidth); self::assertNotEquals($exactWidth, $approxWidth); } else { self::assertEquals($exactWidth, $approxWidth, 'Use approx when exact font file not found'); } } public static function providerFontData(): array { return [ ['DejaVu Sans', 19.82, 20.453125, 22.5659, 21.709], ['DejaVu Sans Mono', 29.18, 29.81640625, 31.9922, 31.8494], ['DejaVu Serif Condensed', 29.55, 30.1796875, 31.9922, 31.1353], ['Arial', -29.55, 30.1796875, 31.9922, 31.1353], ]; } public function testRichText(): void { // RichText treated as text, using Cell font, not Run Font $courier = new StyleFont(); $courier->setName('Courier New'); $courier->setSize(11); Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_APPROX); $element1 = new Run('A'); $element2 = new Run('B'); $element3 = new Run('C'); $element1->setFont($courier); $element2->setFont($courier); $element3->setFont($courier); $richText = new RichText(); $richText->setRichTextElements([$element1, $element2, $element3]); $arial = new StyleFont(); $arial->setName('Arial'); $arial->setSize(9); $widthRich = Font::calculateColumnWidth($arial, $richText); $widthText = Font::calculateColumnWidth($arial, 'ABC'); self::assertSame($widthRich, $widthText); } public function testIssue3626NoPad(): void { $fontName = 'DejaVu Sans'; if ($this->incompleteMessage !== '') { self::markTestIncomplete($this->incompleteMessage); } Font::setTrueTypeFontPath($this->directoryName); Font::setExtraFontArray(self::EXTRA_FONTS); Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_EXACT); Font::setPaddingAmountExact(0); $font = new StyleFont(); $font->setName($fontName); $font->setSize(20); $exactWidth = Font::calculateColumnWidth($font, 'Column2'); $expectedWidth = 16.853; self::assertTrue( $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, "$exactWidth is not within 5% of expected $expectedWidth" ); $font = new StyleFont(); $font->setName($fontName); $exactWidth = Font::calculateColumnWidth($font, 'Col3'); $expectedWidth = 4.5703; self::assertTrue( $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, "$exactWidth is not within 5% of expected $expectedWidth" ); $font = new StyleFont(); $font->setName($fontName); $exactWidth = Font::calculateColumnWidth($font, 'Big Column in 4 position'); $expectedWidth = 26.2793; self::assertTrue( $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, "$exactWidth is not within 5% of expected $expectedWidth" ); } public function testIssue3626Pad(): void { $fontName = 'DejaVu Sans'; if ($this->incompleteMessage !== '') { self::markTestIncomplete($this->incompleteMessage); } Font::setTrueTypeFontPath($this->directoryName); Font::setExtraFontArray(self::EXTRA_FONTS); Font::setAutoSizeMethod(Font::AUTOSIZE_METHOD_EXACT); //Font::setPaddingAmountExact(null); // default - not needed $font = new StyleFont(); $font->setName($fontName); $font->setSize(20); $exactWidth = Font::calculateColumnWidth($font, 'Column2'); $expectedWidth = 18.8525; self::assertTrue( $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, "$exactWidth is not within 5% of expected $expectedWidth" ); $font = new StyleFont(); $font->setName($fontName); $exactWidth = Font::calculateColumnWidth($font, 'Col3'); $expectedWidth = 5.8557; self::assertTrue( $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, "$exactWidth is not within 5% of expected $expectedWidth" ); $font = new StyleFont(); $font->setName($fontName); $exactWidth = Font::calculateColumnWidth($font, 'Big Column in 4 position'); $expectedWidth = 27.5647; self::assertTrue( $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, "$exactWidth is not within 5% of expected $expectedWidth" ); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv3.php
tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv3.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; class StringHelperNoIconv3 extends StringHelper { protected static ?bool $isIconvEnabled = null; protected static bool $iconvTest3 = true; }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Date2Test.php
tests/PhpSpreadsheetTests/Shared/Date2Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException; use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class Date2Test extends TestCase { private ?Spreadsheet $spreadsheet = null; private int $calculateDateTimeType; protected function setUp(): void { $this->calculateDateTimeType = Cell::getCalculateDateTimeType(); } protected function tearDown(): void { Cell::setCalculateDateTimeType($this->calculateDateTimeType); if ($this->spreadsheet !== null) { $this->spreadsheet->disconnectWorksheets(); $this->spreadsheet = null; } } public function testInvalidType(): void { $this->expectException(CalculationException::class); $this->expectExceptionMessage('for calculated date time type'); Cell::setCalculateDateTimeType(-1); } #[DataProvider('providerTimeOnly')] public function testTimeOnly(int|float $expectedResult, int|float|string $value, ?string $format = null): void { Cell::setCalculateDateTimeType(Cell::CALCULATE_TIME_FLOAT); $spreadsheet = $this->spreadsheet = new Spreadsheet(); self::assertSame(0, $spreadsheet->getActiveSheetIndex()); $sheet = $spreadsheet->getActiveSheet(); $newSheet = $spreadsheet->createSheet(); $newSheet->getCell('B7')->setValue('Here'); $sheet->getCell('A1')->setValue($value); if ($format !== null) { $sheet->getStyle('A1') ->getNumberFormat() ->setFormatCode($format); } $sheet->setSelectedCells('B7'); $spreadsheet->setActiveSheetIndex(1); self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue()); self::assertSame('B7', $sheet->getSelectedCells()); self::assertSame(1, $spreadsheet->getActiveSheetIndex()); } public static function providerTimeOnly(): array { $integerValue = 44046; $integerValueAsFloat = (float) $integerValue; $integerValueAsDateFormula = '=DATEVALUE("2020-08-03")'; $floatValue = 44015.25; $floatValueAsDateFormula = '=DATEVALUE("2020-07-03")+TIMEVALUE("06:00")'; return [ 'default format integer' => [$integerValue, $integerValue], 'default format float' => [$floatValue, $floatValue], 'date format integer' => [$integerValue, $integerValue, NumberFormat::FORMAT_DATE_YYYYMMDD], 'date format float' => [$floatValue, $floatValue, NumberFormat::FORMAT_DATE_YYYYMMDD], 'datetime format integer' => [$integerValueAsFloat, $integerValue, 'yyyy-mm-dd h:mm'], 'datetime format float' => [$floatValue, $floatValue, 'yyyy-mm-dd h:mm'], 'time format integer' => [$integerValueAsFloat, $integerValue, NumberFormat::FORMAT_DATE_TIME1], 'time format float' => [$floatValue, $floatValue, NumberFormat::FORMAT_DATE_TIME1], 'date formula integer fltfmt' => [$integerValueAsFloat, $integerValueAsDateFormula, NumberFormat::FORMAT_DATE_TIME1], 'date formula float' => [$floatValue, $floatValueAsDateFormula, NumberFormat::FORMAT_DATE_TIME1], 'date formula integer intfmt but formula returns float' => [$integerValueAsFloat, $integerValueAsDateFormula, NumberFormat::FORMAT_DATE_YYYYMMDD], ]; } #[DataProvider('providerDateAndTime')] public function testDateAndTime(int|float $expectedResult, int|float|string $value, ?string $format = null): void { Cell::setCalculateDateTimeType( Cell::CALCULATE_DATE_TIME_FLOAT ); $spreadsheet = $this->spreadsheet = new Spreadsheet(); self::assertSame(0, $spreadsheet->getActiveSheetIndex()); $sheet = $spreadsheet->getActiveSheet(); $newSheet = $spreadsheet->createSheet(); $newSheet->getCell('B7')->setValue('Here'); $sheet->getCell('A1')->setValue($value); if ($format !== null) { $sheet->getStyle('A1') ->getNumberFormat() ->setFormatCode($format); } $sheet->setSelectedCells('B7'); $spreadsheet->setActiveSheetIndex(1); self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue()); self::assertSame('B7', $sheet->getSelectedCells()); self::assertSame(1, $spreadsheet->getActiveSheetIndex()); } public static function providerDateAndTime(): array { $integerValue = 44046; $integerValueAsFloat = (float) $integerValue; $integerValueAsDateFormula = '=DATEVALUE("2020-08-03")'; $floatValue = 44015.25; $floatValueAsDateFormula = '=DATEVALUE("2020-07-03")+TIMEVALUE("06:00")'; return [ 'default format integer' => [$integerValue, $integerValue], 'default format float' => [$floatValue, $floatValue], 'date format integer' => [$integerValueAsFloat, $integerValue, NumberFormat::FORMAT_DATE_YYYYMMDD], 'date format float' => [$floatValue, $floatValue, NumberFormat::FORMAT_DATE_YYYYMMDD], 'datetime format integer' => [$integerValueAsFloat, $integerValue, 'yyyy-mm-dd h:mm'], 'datetime format float' => [$floatValue, $floatValue, 'yyyy-mm-dd h:mm'], 'time format integer' => [$integerValueAsFloat, $integerValue, NumberFormat::FORMAT_DATE_TIME1], 'time format float' => [$floatValue, $floatValue, NumberFormat::FORMAT_DATE_TIME1], 'date formula integer fltfmt' => [$integerValueAsFloat, $integerValueAsDateFormula, NumberFormat::FORMAT_DATE_TIME1], 'date formula float' => [$floatValue, $floatValueAsDateFormula, NumberFormat::FORMAT_DATE_TIME1], 'date formula integer intfmt but formula returns float' => [$integerValueAsFloat, $integerValueAsDateFormula, NumberFormat::FORMAT_DATE_YYYYMMDD], ]; } #[DataProvider('providerAsis')] public function testDefault(int|float $expectedResult, int|float|string $value, ?string $format = null): void { $spreadsheet = $this->spreadsheet = new Spreadsheet(); self::assertSame(0, $spreadsheet->getActiveSheetIndex()); $sheet = $spreadsheet->getActiveSheet(); $newSheet = $spreadsheet->createSheet(); $newSheet->getCell('B7')->setValue('Here'); $sheet->getCell('A1')->setValue($value); if ($format !== null) { $sheet->getStyle('A1') ->getNumberFormat() ->setFormatCode($format); } $sheet->setSelectedCells('B7'); $spreadsheet->setActiveSheetIndex(1); self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue()); self::assertSame('B7', $sheet->getSelectedCells()); self::assertSame(1, $spreadsheet->getActiveSheetIndex()); } #[DataProvider('providerAsis')] public function testAsis(int|float $expectedResult, int|float|string $value, ?string $format = null): void { Cell::setCalculateDateTimeType( Cell::CALCULATE_DATE_TIME_ASIS ); $spreadsheet = $this->spreadsheet = new Spreadsheet(); self::assertSame(0, $spreadsheet->getActiveSheetIndex()); $sheet = $spreadsheet->getActiveSheet(); $newSheet = $spreadsheet->createSheet(); $newSheet->getCell('B7')->setValue('Here'); $sheet->getCell('A1')->setValue($value); if ($format !== null) { $sheet->getStyle('A1') ->getNumberFormat() ->setFormatCode($format); } $sheet->setSelectedCells('B7'); $spreadsheet->setActiveSheetIndex(1); self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue()); self::assertSame('B7', $sheet->getSelectedCells()); self::assertSame(1, $spreadsheet->getActiveSheetIndex()); } public static function providerAsis(): array { $integerValue = 44046; $integerValueAsFloat = (float) $integerValue; $integerValueAsDateFormula = '=DATEVALUE("2020-08-03")'; $floatValue = 44015.25; $floatValueAsDateFormula = '=DATEVALUE("2020-07-03")+TIMEVALUE("06:00")'; return [ 'default format integer' => [$integerValue, $integerValue], 'default format float' => [$floatValue, $floatValue], 'date format integer' => [$integerValue, $integerValue, NumberFormat::FORMAT_DATE_YYYYMMDD], 'date format float' => [$floatValue, $floatValue, NumberFormat::FORMAT_DATE_YYYYMMDD], 'datetime format integer' => [$integerValue, $integerValue, 'yyyy-mm-dd h:mm'], 'datetime format float' => [$floatValue, $floatValue, 'yyyy-mm-dd h:mm'], 'time format integer' => [$integerValue, $integerValue, NumberFormat::FORMAT_DATE_TIME1], 'time format float' => [$floatValue, $floatValue, NumberFormat::FORMAT_DATE_TIME1], 'date formula integer fltfmt' => [$integerValueAsFloat, $integerValueAsDateFormula, NumberFormat::FORMAT_DATE_TIME1], 'date formula float' => [$floatValue, $floatValueAsDateFormula, NumberFormat::FORMAT_DATE_TIME1], 'date formula integer intfmt but formula returns float' => [$integerValueAsFloat, $integerValueAsDateFormula, NumberFormat::FORMAT_DATE_YYYYMMDD], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php
tests/PhpSpreadsheetTests/Shared/TimeZoneTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use DateTime; use DateTimeZone; use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Shared\TimeZone; use PHPUnit\Framework\TestCase; class TimeZoneTest extends TestCase { private string $tztimezone; private ?DateTimeZone $dttimezone; protected function setUp(): void { $this->tztimezone = TimeZone::getTimeZone(); $this->dttimezone = Date::getDefaultTimeZoneOrNull(); } protected function tearDown(): void { TimeZone::setTimeZone($this->tztimezone); Date::setDefaultTimeZone($this->dttimezone); } public function testSetTimezone(): void { $timezoneValues = [ 'Europe/Prague', 'Asia/Tokyo', 'America/Indiana/Indianapolis', 'Pacific/Honolulu', 'Atlantic/St_Helena', ]; foreach ($timezoneValues as $timezoneValue) { $result = TimeZone::setTimezone($timezoneValue); self::assertTrue($result); $result = Date::setDefaultTimezone($timezoneValue); self::assertTrue($result); } } public function testSetTimezoneBackwardCompatible(): void { $bcTimezone = 'Etc/GMT-10'; $result = TimeZone::setTimezone($bcTimezone); self::assertTrue($result); $result = Date::setDefaultTimezone($bcTimezone); self::assertTrue($result); } public function testSetTimezoneWithInvalidValue(): void { $unsupportedTimezone = 'XEtc/GMT+10'; $result = TimeZone::setTimezone($unsupportedTimezone); self::assertFalse($result); $result = Date::setDefaultTimezone($unsupportedTimezone); self::assertFalse($result); } public function testTimeZoneAdjustmentsInvalidTz(): void { $this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class); $dtobj = DateTime::createFromFormat('Y-m-d H:i:s', '2008-09-22 00:00:00'); if ($dtobj === false) { self::fail('DateTime createFromFormat failed'); } else { $tstmp = $dtobj->getTimestamp(); $unsupportedTimeZone = 'XEtc/GMT+10'; TimeZone::getTimeZoneAdjustment($unsupportedTimeZone, $tstmp); } } public function testTimeZoneAdjustments(): void { $dtobj = DateTime::createFromFormat('Y-m-d H:i:s', '2008-01-01 00:00:00'); if ($dtobj === false) { self::fail('DateTime createFromFormat failed'); } else { $tstmp = $dtobj->getTimestamp(); $supportedTimeZone = 'UTC'; $adj = TimeZone::getTimeZoneAdjustment($supportedTimeZone, $tstmp); self::assertEquals(0, $adj); $supportedTimeZone = 'America/Toronto'; $adj = TimeZone::getTimeZoneAdjustment($supportedTimeZone, $tstmp); self::assertEquals(-18000, $adj); $supportedTimeZone = 'America/Chicago'; TimeZone::setTimeZone($supportedTimeZone); $adj = TimeZone::getTimeZoneAdjustment(null, $tstmp); self::assertEquals(-21600, $adj); } } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/XMLWriterNoUri.php
tests/PhpSpreadsheetTests/Shared/XMLWriterNoUri.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; class XMLWriterNoUri extends \PhpOffice\PhpSpreadsheet\Shared\XMLWriter { public function openUri(string $uri): bool { return false; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/FileTest.php
tests/PhpSpreadsheetTests/Shared/FileTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; use PhpOffice\PhpSpreadsheet\Shared\File; use PHPUnit\Framework\TestCase; class FileTest extends TestCase { private bool $uploadFlag = false; private string $tempfile = ''; protected function setUp(): void { $this->uploadFlag = File::getUseUploadTempDirectory(); } protected function tearDown(): void { File::setUseUploadTempDirectory($this->uploadFlag); if ($this->tempfile !== '') { unlink($this->tempfile); $this->tempfile = ''; } } public function testGetUseUploadTempDirectory(): void { $expectedResult = false; $result = File::getUseUploadTempDirectory(); self::assertEquals($expectedResult, $result); } public function testSetUseUploadTempDirectory(): void { $useUploadTempDirectoryValues = [ true, false, ]; $temp = ini_get('upload_tmp_dir') ?: ''; $badArray = ['', sys_get_temp_dir()]; foreach ($useUploadTempDirectoryValues as $useUploadTempDirectoryValue) { File::setUseUploadTempDirectory($useUploadTempDirectoryValue); $result = File::getUseUploadTempDirectory(); self::assertEquals($useUploadTempDirectoryValue, $result); $result = File::sysGetTempDir(); if (!$useUploadTempDirectoryValue || in_array($temp, $badArray, true)) { self::assertSame(realpath(sys_get_temp_dir()), $result); } else { self::assertSame(realpath($temp), $result); } } } public function testUploadTmpDir(): void { $temp = ini_get('upload_tmp_dir') ?: ''; $badArray = ['', sys_get_temp_dir()]; if (in_array($temp, $badArray, true)) { self::markTestSkipped('upload_tmp_dir setting unusable for this test'); } else { File::setUseUploadTempDirectory(true); $result = File::sysGetTempDir(); self::assertSame(realpath($temp), $result); } } public function testNotExists(): void { $temp = File::temporaryFileName(); file_put_contents($temp, ''); File::assertFile($temp); self::assertTrue(File::testFileNoThrow($temp)); unlink($temp); self::assertFalse(File::testFileNoThrow($temp)); $this->expectException(ReaderException::class); $this->expectExceptionMessage('does not exist'); File::assertFile($temp); } public function testNotReadable(): void { if (PHP_OS_FAMILY === 'Windows' || stristr(PHP_OS, 'CYGWIN') !== false) { self::markTestSkipped('chmod does not work reliably on Windows'); } $this->tempfile = $temp = File::temporaryFileName(); file_put_contents($temp, ''); if (chmod($temp, 7 * 8) === false) { // octal 070 self::markTestSkipped('chmod failed'); } self::assertFalse(File::testFileNoThrow($temp)); $this->expectException(ReaderException::class); $this->expectExceptionMessage('is not readable'); File::assertFile($temp); } public function testZip(): void { $temp = 'samples/templates/26template.xlsx'; File::assertFile($temp, 'xl/workbook.xml'); self::assertTrue(File::testFileNoThrow($temp, 'xl/workbook.xml')); self::assertFalse(File::testFileNoThrow($temp, 'xl/xworkbook.xml')); $this->expectException(ReaderException::class); $this->expectExceptionMessage('Could not find zip member'); File::assertFile($temp, 'xl/xworkbook.xml'); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Issue4696Test.php
tests/PhpSpreadsheetTests/Shared/Issue4696Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Cell\DataType; use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class Issue4696Test extends TestCase { private ?Spreadsheet $spreadsheet = null; protected function tearDown(): void { if ($this->spreadsheet !== null) { $this->spreadsheet->disconnectWorksheets(); $this->spreadsheet = null; } } #[DataProvider('providerIsDateTime')] public function testIsDateTime(bool $expectedResult, string $expectedFormatted, int|float|string $value): void { $this->spreadsheet = new Spreadsheet(); $sheet = $this->spreadsheet->getActiveSheet(); if (is_string($value) && $value[0] !== '=') { $sheet->getCell('A1')->setValueExplicit($value, DataType::TYPE_STRING); } else { $sheet->getCell('A1')->setValue($value); } $sheet->getStyle('A1')->getNumberFormat() ->setFormatCode('yyyy-mm-dd'); self::assertSame( $expectedResult, Date::isDateTime($sheet->getCell('A1')) ); self::assertSame( $expectedFormatted, $sheet->getCell('A1')->getFormattedValue() ); } public static function providerIsDateTime(): array { return [ 'valid integer' => [true, '1903-12-31', 1461], 'valid integer stored as string' => [true, '1904-01-01', '1462'], 'valid integer stored as concatenated string' => [true, '1904-01-01', '="14"&"62"'], 'valid float' => [true, '1903-12-31', 1461.5], 'valid float stored as string' => [true, '1903-12-31', '1461.5'], 'out-of-range integer' => [false, '7000989091802000122', 7000989091802000122], 'out-of-range float' => [false, '7.000989091802E+18', 7000989091802000122.1], 'out-of-range float stored as string' => [false, '7000989091802000122.1', '7000989091802000122.1'], 'non-numeric' => [false, 'xyz', 'xyz'], 'issue 917' => [false, '5e8630b8-603c-43fe-b038-6154a3f893ab', '5e8630b8-603c-43fe-b038-6154a3f893ab'], ]; } #[DataProvider('providerOtherFunctions')] public function testOtherFunctions(string $function): void { $this->spreadsheet = new Spreadsheet(); $sheet = $this->spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue(7000989091802000122); $sheet->getCell('A3')->setValue(39107); // 2007-01-25 $sheet->getCell('A4')->setValue(39767); // 2008-11-15 $sheet->getCell('A5')->setValue(2); $sheet->getCell('A6')->setValue(1); $sheet->getCell('B1')->setValue($function); self::assertSame( '#NUM!', $sheet->getCell('B1')->getFormattedValue() ); } public static function providerOtherFunctions(): array { return [ ['=YEAR(A1)'], ['=MONTH(A1)'], ['=DAY(A1)'], ['=DAYS(A1,A1)'], ['=DAYS360(A1,A1)'], ['=DATEDIF(A1,A1,"D")'], ['=HOUR(A1)'], ['=MINUTE(A1)'], ['=SECOND(A1)'], ['=WEEKNUM(A1)'], ['=ISOWEEKNUM(A1)'], ['=WEEKDAY(A1)'], ['=COUPDAYBS(A1,A4,A5,A6)'], ['=COUPDAYS(A3,A2,A5,A6)'], ['=COUPDAYSNC(A3,A2,A5,A6)'], ['=COUPNCD(A3,A2,A5,A6)'], ['=COUPNUM(A3,A2,A5,A6)'], ['=COUPPCD(A3,A2,A5,A6)'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv.php
tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; class StringHelperNoIconv extends StringHelper { protected static ?bool $isIconvEnabled = null; protected static string $iconvName = 'simulateIconvUnavilable'; }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/PasswordHasherTest.php
tests/PhpSpreadsheetTests/Shared/PasswordHasherTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Exception as SpException; use PhpOffice\PhpSpreadsheet\Shared\PasswordHasher; use PHPUnit\Framework\TestCase; class PasswordHasherTest extends TestCase { #[\PHPUnit\Framework\Attributes\DataProvider('providerHashPassword')] public function testHashPassword( string $expectedResult, string $password, ?string $algorithm = null, ?string $salt = null, ?int $spinCount = null ): void { if ($expectedResult === 'exception') { $this->expectException(SpException::class); } if ($algorithm === null) { $result = PasswordHasher::hashPassword($password); } elseif ($salt === null) { $result = PasswordHasher::hashPassword($password, $algorithm); } elseif ($spinCount === null) { $result = PasswordHasher::hashPassword($password, $algorithm, $salt); } else { $result = PasswordHasher::hashPassword($password, $algorithm, $salt, $spinCount); } self::assertSame($expectedResult, $result); } public static function providerHashPassword(): array { return require 'tests/data/Shared/PasswordHashes.php'; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/DateTest.php
tests/PhpSpreadsheetTests/Shared/DateTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use DateTime; use DateTimeInterface; use DateTimeZone; use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Shared\Date; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class DateTest extends TestCase { private int $excelCalendar; private ?DateTimeZone $dttimezone; protected function setUp(): void { $this->dttimezone = Date::getDefaultTimeZoneOrNull(); $this->excelCalendar = Date::getExcelCalendar(); } protected function tearDown(): void { Date::setDefaultTimeZone($this->dttimezone); Date::setExcelCalendar($this->excelCalendar); } public function testSetExcelCalendar(): void { $calendarValues = [ Date::CALENDAR_MAC_1904, Date::CALENDAR_WINDOWS_1900, ]; $spreadsheet = new Spreadsheet(); foreach ($calendarValues as $calendarValue) { $result = Date::setExcelCalendar($calendarValue); self::assertTrue($result); $result = $spreadsheet->setExcelCalendar($calendarValue); self::assertTrue($result); } self::assertFalse($spreadsheet->setExcelCalendar(0)); $spreadsheet->disconnectWorksheets(); } public function testSetExcelCalendarWithInvalidValue(): void { $unsupportedCalendar = 2012; $result = Date::setExcelCalendar($unsupportedCalendar); self::assertFalse($result); } #[DataProvider('providerDateTimeExcelToTimestamp1900')] public function testDateTimeExcelToTimestamp1900(float|int $expectedResult, float|int $excelDateTimeValue): void { if ($expectedResult > PHP_INT_MAX || $expectedResult < PHP_INT_MIN) { self::markTestSkipped('Test invalid on 32-bit system.'); } Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); $result = Date::excelToTimestamp($excelDateTimeValue); self::assertEquals($expectedResult, $result); } public static function providerDateTimeExcelToTimestamp1900(): array { return require 'tests/data/Shared/Date/ExcelToTimestamp1900.php'; } #[DataProvider('providerDateTimeTimestampToExcel1900')] public function testDateTimeTimestampToExcel1900(float|int $expectedResult, float|int|string $unixTimestamp): void { Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); $result = Date::timestampToExcel($unixTimestamp); self::assertEqualsWithDelta($expectedResult, $result, 1E-5); } public static function providerDateTimeTimestampToExcel1900(): array { return require 'tests/data/Shared/Date/TimestampToExcel1900.php'; } #[DataProvider('providerDateTimeDateTimeToExcel')] public function testDateTimeDateTimeToExcel(float|int $expectedResult, DateTimeInterface $dateTimeObject): void { Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); $result = Date::dateTimeToExcel($dateTimeObject); self::assertEqualsWithDelta($expectedResult, $result, 1E-5); } public static function providerDateTimeDateTimeToExcel(): array { return require 'tests/data/Shared/Date/DateTimeToExcel.php'; } /** * @param array{0: int, 1: int, 2: int, 3: int, 4: int, 5: float|int} $args Array containing year/month/day/hours/minutes/seconds */ #[DataProvider('providerDateTimeFormattedPHPToExcel1900')] public function testDateTimeFormattedPHPToExcel1900(mixed $expectedResult, ...$args): void { Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); $result = Date::formattedPHPToExcel(...$args); // @phpstan-ignore-line self::assertEqualsWithDelta($expectedResult, $result, 1E-5); } public static function providerDateTimeFormattedPHPToExcel1900(): array { return require 'tests/data/Shared/Date/FormattedPHPToExcel1900.php'; } #[DataProvider('providerDateTimeExcelToTimestamp1904')] public function testDateTimeExcelToTimestamp1904(float|int $expectedResult, float|int $excelDateTimeValue): void { if ($expectedResult > PHP_INT_MAX || $expectedResult < PHP_INT_MIN) { self::markTestSkipped('Test invalid on 32-bit system.'); } Date::setExcelCalendar(Date::CALENDAR_MAC_1904); $result = Date::excelToTimestamp($excelDateTimeValue); self::assertEquals($expectedResult, $result); } public static function providerDateTimeExcelToTimestamp1904(): array { return require 'tests/data/Shared/Date/ExcelToTimestamp1904.php'; } #[DataProvider('providerDateTimeTimestampToExcel1904')] public function testDateTimeTimestampToExcel1904(mixed $expectedResult, float|int|string $unixTimestamp): void { Date::setExcelCalendar(Date::CALENDAR_MAC_1904); $result = Date::timestampToExcel($unixTimestamp); self::assertEqualsWithDelta($expectedResult, $result, 1E-5); } public static function providerDateTimeTimestampToExcel1904(): array { return require 'tests/data/Shared/Date/TimestampToExcel1904.php'; } #[DataProvider('providerIsDateTimeFormatCode')] public function testIsDateTimeFormatCode(mixed $expectedResult, string $format): void { $result = Date::isDateTimeFormatCode($format); self::assertEquals($expectedResult, $result); } public static function providerIsDateTimeFormatCode(): array { return require 'tests/data/Shared/Date/FormatCodes.php'; } #[DataProvider('providerDateTimeExcelToTimestamp1900Timezone')] public function testDateTimeExcelToTimestamp1900Timezone(float|int $expectedResult, float|int $excelDateTimeValue, string $timezone): void { if ($expectedResult > PHP_INT_MAX || $expectedResult < PHP_INT_MIN) { self::markTestSkipped('Test invalid on 32-bit system.'); } Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); $result = Date::excelToTimestamp($excelDateTimeValue, $timezone); self::assertEquals($expectedResult, $result); } public static function providerDateTimeExcelToTimestamp1900Timezone(): array { return require 'tests/data/Shared/Date/ExcelToTimestamp1900Timezone.php'; } public function testConvertIsoDateError(): void { Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); $this->expectException(Exception::class); $this->expectExceptionMessage('Non-string value supplied for Iso Date conversion'); Date::convertIsoDate(false); } public function testVarious(): void { Date::setDefaultTimeZone('UTC'); self::assertFalse(Date::stringToExcel('2019-02-29')); self::assertTrue((bool) Date::stringToExcel('2019-02-28')); self::assertTrue((bool) Date::stringToExcel('2019-02-28 11:18')); self::assertFalse(Date::stringToExcel('2019-02-28 11:71')); $timestamp1 = Date::stringToExcel('26.05.2025 14:28:00'); $timestamp2 = Date::stringToExcel('26.05.2025 14:28:00.00'); self::assertNotFalse($timestamp1); self::assertNotFalse($timestamp2); self::assertEqualsWithDelta($timestamp1, 45803.60277777778, 1.0E-10); self::assertSame($timestamp1, $timestamp2); $date = Date::PHPToExcel('2020-01-01'); self::assertEquals(43831.0, $date); $phpDate = new DateTime('2020-01-02T00:00Z'); $date = Date::PHPToExcel($phpDate); self::assertEquals(43832.0, $date); $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('B1', 'x'); /** @var float|int|string */ $val = $sheet->getCell('B1')->getValue(); self::assertFalse(Date::timestampToExcel($val)); $cell = $sheet->getCell('A1'); $cell->setValue($date); $sheet->getStyle('A1') ->getNumberFormat() ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME); self::assertTrue(Date::isDateTime($cell)); $cella2 = $sheet->getCell('A2'); $cella2->setValue('=A1+2'); $sheet->getStyle('A2') ->getNumberFormat() ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME); self::assertTrue(Date::isDateTime($cella2)); $cella3 = $sheet->getCell('A3'); $cella3->setValue('=A1+4'); $sheet->getStyle('A3') ->getNumberFormat() ->setFormatCode('0.00E+00'); self::assertFalse(Date::isDateTime($cella3)); $cella4 = $sheet->getCell('A4'); $cella4->setValue('= 44 7510557347'); $sheet->getStyle('A4') ->getNumberFormat() ->setFormatCode('yyyy-mm-dd'); self::assertFalse(Date::isDateTime($cella4)); $spreadsheet->disconnectWorksheets(); } public function testArray(): void { $spreadsheet = new Spreadsheet(); $spreadsheet->returnArrayAsArray(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 45000); $sheet->setCellValue('A2', 44000); $sheet->setCellValue('A3', 46000); $sheet->setCellValue('C1', '=SORT(A1:A3)'); $sheet->setCellValue('D1', '=SORT(A1:A3)'); $sheet->getStyle('C1') ->getNumberFormat() ->setFormatCode('yyyy-mm-dd'); self::assertTrue(Date::isDateTime($sheet->getCell('C1'))); self::assertFalse(Date::isDateTime($sheet->getCell('D1'))); self::assertIsArray( $sheet->getCell('C1')->getCalculatedValue() ); $spreadsheet->disconnectWorksheets(); } public function testRoundMicroseconds(): void { $dti = new DateTime('2000-01-02 03:04:05.999999'); Date::roundMicroseconds($dti); self::assertEquals(new DateTime('2000-01-02 03:04:06.000000'), $dti); $dti = new DateTime('2000-01-02 03:04:05.500000'); Date::roundMicroseconds($dti); self::assertEquals(new DateTime('2000-01-02 03:04:06.000000'), $dti); $dti = new DateTime('2000-01-02 03:04:05.499999'); Date::roundMicroseconds($dti); self::assertEquals(new DateTime('2000-01-02 03:04:05.000000'), $dti); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Font2Test.php
tests/PhpSpreadsheetTests/Shared/Font2Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Font; use PhpOffice\PhpSpreadsheet\Style\Font as StyleFont; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class Font2Test extends TestCase { #[DataProvider('providerCharsetFromFontName')] public function testCharsetFromFontName(string $fontName, int $expectedResult): void { $result = Font::getCharsetFromFontName($fontName); self::assertEquals($expectedResult, $result); } public function testCharsetFromFontNameCoverage(): void { $covered = []; $expected = Font::CHARSET_FROM_FONT_NAME; foreach (array_keys($expected) as $key) { $covered[$key] = 0; } $defaultCovered = false; $tests = $this->providerCharsetFromFontName(); foreach ($tests as $test) { /** @var string[] $test */ $thisTest = $test[0]; if (array_key_exists($thisTest, $covered)) { $covered[$thisTest] = 1; } else { $defaultCovered = true; } } foreach ($covered as $key => $val) { self::assertEquals(1, $val, "FontName $key not tested"); } self::assertTrue($defaultCovered, 'Default key not tested'); } public static function providerCharsetFromFontName(): array { return [ ['EucrosiaUPC', Font::CHARSET_ANSI_THAI], ['Wingdings', Font::CHARSET_SYMBOL], ['Wingdings 2', Font::CHARSET_SYMBOL], ['Wingdings 3', Font::CHARSET_SYMBOL], ['Default', Font::CHARSET_ANSI_LATIN], ]; } public function testColumnWidths(): void { $widths = Font::DEFAULT_COLUMN_WIDTHS; $fontNames = ['Arial', 'Calibri', 'Verdana']; $font = new StyleFont(); foreach ($fontNames as $fontName) { $font->setName($fontName); $array = $widths[$fontName]; foreach ($array as $points => $array2) { $font->setSize($points); $px = $array2['px']; $width = $array2['width']; self::assertEquals($px, Font::getDefaultColumnWidthByFont($font, true), "$fontName $points px"); self::assertEquals($width, Font::getDefaultColumnWidthByFont($font, false), "$fontName $points ooxml-units"); } } $pxCalibri11 = $widths['Calibri'][11]['px']; $widthCalibri11 = $widths['Calibri'][11]['width']; $fontName = 'unknown'; $points = 11; $font->setName($fontName); $font->setSize($points); self::assertEquals($pxCalibri11, Font::getDefaultColumnWidthByFont($font, true), "$fontName $points px"); self::assertEquals($widthCalibri11, Font::getDefaultColumnWidthByFont($font, false), "$fontName $points ooxml-units"); $points = 22; $font->setSize($points); self::assertEquals(2 * $pxCalibri11, Font::getDefaultColumnWidthByFont($font, true), "$fontName $points px"); self::assertEquals(2 * $widthCalibri11, Font::getDefaultColumnWidthByFont($font, false), "$fontName $points ooxml-units"); $fontName = 'Arial'; $points = 33; $font->setName($fontName); $font->setSize($points); self::assertEquals(3 * $pxCalibri11, Font::getDefaultColumnWidthByFont($font, true), "$fontName $points px"); self::assertEquals(3 * $widthCalibri11, Font::getDefaultColumnWidthByFont($font, false), "$fontName $points ooxml-units"); } public function testRowHeights(): void { $heights = Font::DEFAULT_COLUMN_WIDTHS; $fontNames = ['Arial', 'Calibri', 'Verdana']; $font = new StyleFont(); foreach ($fontNames as $fontName) { $font->setName($fontName); $array = $heights[$fontName]; foreach ($array as $points => $array2) { $font->setSize($points); $height = $array2['height']; self::assertEquals($height, Font::getDefaultRowHeightByFont($font), "$fontName $points points"); } } $heightArial10 = $heights['Arial'][10]['height']; $fontName = 'Arial'; $points = 20; $font->setName($fontName); $font->setSize($points); self::assertEquals(2 * $heightArial10, Font::getDefaultRowHeightByFont($font), "$fontName $points points"); $heightVerdana10 = $heights['Verdana'][10]['height']; $fontName = 'Verdana'; $points = 30; $font->setName($fontName); $font->setSize($points); self::assertEquals(3 * $heightVerdana10, Font::getDefaultRowHeightByFont($font), "$fontName $points points"); $heightCalibri11 = $heights['Calibri'][11]['height']; $fontName = 'Calibri'; $points = 22; $font->setName($fontName); $font->setSize($points); self::assertEquals(2 * $heightCalibri11, Font::getDefaultRowHeightByFont($font), "$fontName $points points"); $fontName = 'unknown'; $points = 33; $font->setName($fontName); $font->setSize($points); self::assertEquals(3 * $heightCalibri11, Font::getDefaultRowHeightByFont($font), "$fontName $points points"); } public function testGetTrueTypeFontFileFromFont(): void { $fileNames = Font::FONT_FILE_NAMES; $font = new StyleFont(); foreach ($fileNames as $fontName => $fontNameArray) { $font->setName($fontName); $font->setBold(false); $font->setItalic(false); self::assertSame($fileNames[$fontName]['x'], Font::getTrueTypeFontFileFromFont($font, false), "$fontName not bold not italic"); $font->setBold(true); $font->setItalic(false); self::assertSame($fileNames[$fontName]['xb'], Font::getTrueTypeFontFileFromFont($font, false), "$fontName bold not italic"); $font->setBold(false); $font->setItalic(true); self::assertSame($fileNames[$fontName]['xi'], Font::getTrueTypeFontFileFromFont($font, false), "$fontName not bold italic"); $font->setBold(true); $font->setItalic(true); self::assertSame($fileNames[$fontName]['xbi'], Font::getTrueTypeFontFileFromFont($font, false), "$fontName bold italic"); } } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/DgContainerTest.php
tests/PhpSpreadsheetTests/Shared/DgContainerTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; use PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer; use PHPUnit\Framework\TestCase; class DgContainerTest extends TestCase { public function testNullContainerWithThrow(): void { $this->expectException(SpreadsheetException::class); $this->expectExceptionMessage('spgrContainer is unexpectedly null'); $container = new DgContainer(); $container->getSpgrContainerOrThrow(); } public function testNullContainerWithoutThrow(): void { $container = new DgContainer(); self::assertNull($container->getSpgrContainer()); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/FontFileNameTest.php
tests/PhpSpreadsheetTests/Shared/FontFileNameTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Chart\ChartColor; use PhpOffice\PhpSpreadsheet\Exception as SSException; use PhpOffice\PhpSpreadsheet\Shared\Font; use PhpOffice\PhpSpreadsheet\Style\Font as StyleFont; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class FontFileNameTest extends TestCase { private const DEFAULT_DIRECTORY = 'tests/data/Shared/FakeFonts/Default'; private const MAC_DIRECTORY = 'tests/data/Shared/FakeFonts/Mac'; private const RECURSE_DIRECTORY = 'tests/data/Shared/FakeFonts/Recurse'; private string $holdDirectory; /** @var array<string, array<string, string>> */ private array $holdExtraFontArray; protected function setUp(): void { $this->holdDirectory = Font::getTrueTypeFontPath(); $this->holdExtraFontArray = Font::getExtraFontArray(); Font::setExtraFontArray([ 'Extra Font' => [ 'x' => 'extrafont.ttf', 'xb' => 'extrafontbd.ttf', 'xi' => 'extrafonti.ttf', 'xbi' => 'extrafontbi.ttf', ], ]); } protected function tearDown(): void { Font::setTrueTypeFontPath($this->holdDirectory); Font::setExtraFontArray($this->holdExtraFontArray); } /** * @param array{name?: string, latin?: string, eastAsian?: string, complexScript?: string, bold?: bool, italic?: bool, superscript?: bool, subscript?: bool, underline?: bool|string, strikethrough?: bool, color?: string[], size?: ?int, chartColor?: ChartColor, scheme?: string, cap?: string} $fontArray Array containing style information */ #[DataProvider('providerDefault')] public function testDefaultFilenames(string $expected, array $fontArray): void { if ($expected === 'exception') { $this->expectException(SSException::class); $this->expectExceptionMessage('TrueType Font file not found'); } Font::setTrueTypeFontPath(self::DEFAULT_DIRECTORY); $font = (new StyleFont())->applyFromArray($fontArray); $result = Font::getTrueTypeFontFileFromFont($font); self::assertSame($expected, basename($result)); } public static function providerDefault(): array { return [ ['arial.ttf', ['name' => 'Arial']], ['arialbd.ttf', ['name' => 'Arial', 'bold' => true]], ['ariali.ttf', ['name' => 'Arial', 'italic' => true]], ['arialbi.ttf', ['name' => 'Arial', 'bold' => true, 'italic' => true]], ['cour.ttf', ['name' => 'Courier New']], ['courbd.ttf', ['name' => 'Courier New', 'bold' => true]], ['couri.ttf', ['name' => 'Courier New', 'italic' => true]], ['courbi.ttf', ['name' => 'Courier New', 'bold' => true, 'italic' => true]], ['impact.ttf', ['name' => 'Impact']], 'no bold impact' => ['impact.ttf', ['name' => 'Impact', 'bold' => true]], 'no italic impact' => ['impact.ttf', ['name' => 'Impact', 'italic' => true]], 'no bold italic impact' => ['impact.ttf', ['name' => 'Impact', 'bold' => true, 'italic' => true]], ['tahoma.ttf', ['name' => 'Tahoma']], ['tahomabd.ttf', ['name' => 'Tahoma', 'bold' => true]], 'no italic tahoma' => ['tahoma.ttf', ['name' => 'Tahoma', 'italic' => true]], 'no bold italic tahoma' => ['tahomabd.ttf', ['name' => 'Tahoma', 'bold' => true, 'italic' => true]], 'Times New Roman not in directory for this test' => ['exception', ['name' => 'Times New Roman']], ['extrafont.ttf', ['name' => 'Extra Font']], ['extrafontbd.ttf', ['name' => 'Extra Font', 'bold' => true]], ['extrafonti.ttf', ['name' => 'Extra Font', 'italic' => true]], ['extrafontbi.ttf', ['name' => 'Extra Font', 'bold' => true, 'italic' => true]], ]; } /** * @param array{name?: string, latin?: string, eastAsian?: string, complexScript?: string, bold?: bool, italic?: bool, superscript?: bool, subscript?: bool, underline?: bool|string, strikethrough?: bool, color?: string[], size?: ?int, chartColor?: ChartColor, scheme?: string, cap?: string} $fontArray Array containing style information */ #[DataProvider('providerMac')] public function testMacFilenames(string $expected, array $fontArray): void { if ($expected === 'exception') { $this->expectException(SSException::class); $this->expectExceptionMessage('TrueType Font file not found'); } Font::setTrueTypeFontPath(self::MAC_DIRECTORY); $font = (new StyleFont())->applyFromArray($fontArray); $result = Font::getTrueTypeFontFileFromFont($font); self::assertSame($expected, ucfirst(basename($result))); // allow for Windows case-insensitivity } public static function providerMac(): array { return [ ['Arial.ttf', ['name' => 'Arial']], ['Arial Bold.ttf', ['name' => 'Arial', 'bold' => true]], ['Arial Italic.ttf', ['name' => 'Arial', 'italic' => true]], ['Arial Bold Italic.ttf', ['name' => 'Arial', 'bold' => true, 'italic' => true]], ['Courier New.ttf', ['name' => 'Courier New']], ['Courier New Bold.ttf', ['name' => 'Courier New', 'bold' => true]], ['Courier New Italic.ttf', ['name' => 'Courier New', 'italic' => true]], ['Courier New Bold Italic.ttf', ['name' => 'Courier New', 'bold' => true, 'italic' => true]], ['Impact.ttf', ['name' => 'Impact']], 'no bold impact' => ['Impact.ttf', ['name' => 'Impact', 'bold' => true]], 'no italic impact' => ['Impact.ttf', ['name' => 'Impact', 'italic' => true]], 'no bold italic impact' => ['Impact.ttf', ['name' => 'Impact', 'bold' => true, 'italic' => true]], ['Tahoma.ttf', ['name' => 'Tahoma']], ['Tahoma Bold.ttf', ['name' => 'Tahoma', 'bold' => true]], 'no italic tahoma' => ['Tahoma.ttf', ['name' => 'Tahoma', 'italic' => true]], 'no bold italic tahoma' => ['Tahoma Bold.ttf', ['name' => 'Tahoma', 'bold' => true, 'italic' => true]], 'Times New Roman not in directory for this test' => ['exception', ['name' => 'Times New Roman']], ['Extra Font.ttf', ['name' => 'Extra Font']], ['Extra Font Bold.ttf', ['name' => 'Extra Font', 'bold' => true]], ['Extra Font Italic.ttf', ['name' => 'Extra Font', 'italic' => true]], ['Extra Font Bold Italic.ttf', ['name' => 'Extra Font', 'bold' => true, 'italic' => true]], ]; } /** * @param array{name?: string, latin?: string, eastAsian?: string, complexScript?: string, bold?: bool, italic?: bool, superscript?: bool, subscript?: bool, underline?: bool|string, strikethrough?: bool, color?: string[], size?: ?int, chartColor?: ChartColor, scheme?: string, cap?: string} $fontArray Array containing style information */ #[DataProvider('providerOverride')] public function testOverrideFilenames(string $expected, array $fontArray): void { Font::setTrueTypeFontPath(self::DEFAULT_DIRECTORY); Font::setExtraFontArray([ 'Arial' => [ 'x' => 'extrafont.ttf', 'xb' => 'extrafontbd.ttf', 'xi' => 'extrafonti.ttf', 'xbi' => 'extrafontbi.ttf', ], ]); $font = (new StyleFont())->applyFromArray($fontArray); $result = Font::getTrueTypeFontFileFromFont($font); self::assertSame($expected, basename($result)); } public static function providerOverride(): array { return [ ['extrafont.ttf', ['name' => 'Arial']], ['extrafontbd.ttf', ['name' => 'Arial', 'bold' => true]], ['extrafonti.ttf', ['name' => 'Arial', 'italic' => true]], ['extrafontbi.ttf', ['name' => 'Arial', 'bold' => true, 'italic' => true]], ['cour.ttf', ['name' => 'Courier New']], ]; } /** * @param array{name?: string, latin?: string, eastAsian?: string, complexScript?: string, bold?: bool, italic?: bool, superscript?: bool, subscript?: bool, underline?: bool|string, strikethrough?: bool, color?: string[], size?: ?int, chartColor?: ChartColor, scheme?: string, cap?: string} $fontArray Array containing style information */ #[DataProvider('providerOverrideAbsolute')] public function testOverrideFilenamesAbsolute(string $expected, array $fontArray): void { $realPath = realpath(self::MAC_DIRECTORY) . DIRECTORY_SEPARATOR; Font::setTrueTypeFontPath(self::DEFAULT_DIRECTORY); Font::setExtraFontArray([ 'Arial' => [ 'x' => $realPath . 'Arial.ttf', 'xb' => $realPath . 'Arial Bold.ttf', 'xi' => $realPath . 'Arial Italic.ttf', 'xbi' => $realPath . 'Arial Bold Italic.ttf', ], ]); $font = (new StyleFont())->applyFromArray($fontArray); $result = Font::getTrueTypeFontFileFromFont($font); self::assertSame($expected, basename($result)); } public static function providerOverrideAbsolute(): array { return [ 'absolute path normal' => ['Arial.ttf', ['name' => 'Arial']], 'absolute path bold' => ['Arial Bold.ttf', ['name' => 'Arial', 'bold' => true]], 'absolute path italic' => ['Arial Italic.ttf', ['name' => 'Arial', 'italic' => true]], 'absolute path bold italic' => ['Arial Bold Italic.ttf', ['name' => 'Arial', 'bold' => true, 'italic' => true]], 'non-absolute path uses TrueTypeFontPath' => ['cour.ttf', ['name' => 'Courier New']], ]; } /** * @param array{name?: string, latin?: string, eastAsian?: string, complexScript?: string, bold?: bool, italic?: bool, superscript?: bool, subscript?: bool, underline?: bool|string, strikethrough?: bool, color?: string[], size?: ?int, chartColor?: ChartColor, scheme?: string, cap?: string} $fontArray Array containing style information */ #[DataProvider('providerRecurse')] public function testRecurseFilenames(string $expected, array $fontArray): void { if ($expected === 'exception') { $this->expectException(SSException::class); $this->expectExceptionMessage('TrueType Font file not found'); } Font::setTrueTypeFontPath(self::RECURSE_DIRECTORY); $font = (new StyleFont())->applyFromArray($fontArray); $result = Font::getTrueTypeFontFileFromFont($font); self::assertSame($expected, basename($result)); } public static function providerRecurse(): array { return [ 'in subdirectory' => ['arial.ttf', ['name' => 'Arial']], 'in subdirectory bold' => ['arialbd.ttf', ['name' => 'Arial', 'bold' => true]], 'in main directory' => ['cour.ttf', ['name' => 'Courier New']], 'not in main or subdirectory' => ['exception', ['name' => 'Courier New', 'bold' => true]], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Issue347Test.php
tests/PhpSpreadsheetTests/Shared/Issue347Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder; use PhpOffice\PhpSpreadsheet\Reader\BaseReader; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; use PHPUnit\Framework\Attributes\DataProvider; class Issue347Test extends AbstractFunctional { public function readerPreserveCr(BaseReader $reader): void { $binder = new DefaultValueBinder(); $binder->setPreserveCr(true); $reader->setValueBinder($binder); } #[DataProvider('providerType')] public function testPreserveCr(string $format): void { $s1 = "AB\r\nC\tD"; $spreadsheet = new Spreadsheet(); $binder = new DefaultValueBinder(); $binder->setPreserveCr(true); $spreadsheet->setValueBinder($binder); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue($s1); $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format, readerCustomizer: $this->readerPreserveCr(...)); $spreadsheet->disconnectWorksheets(); $rsheet = $reloadedSpreadsheet->getActiveSheet(); $s2 = $rsheet->getCell('A1')->getValue(); self::assertSame($s1, $s2); $reloadedSpreadsheet->disconnectWorksheets(); } #[DataProvider('providerType')] public function testNoPreserveCr(string $format): void { $s1 = "AB\r\nC\tD"; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue($s1); $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format); $spreadsheet->disconnectWorksheets(); $rsheet = $reloadedSpreadsheet->getActiveSheet(); $s2 = $rsheet->getCell('A1')->getValue(); self::assertNotEquals($s1, $s2); self::assertSame("AB\nC\tD", $s2); $reloadedSpreadsheet->disconnectWorksheets(); } public static function providerType(): array { return [['Xls'], ['Xlsx'], ['Ods']]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Font3Test.php
tests/PhpSpreadsheetTests/Shared/Font3Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Exception as SSException; use PhpOffice\PhpSpreadsheet\Shared\Font; use PhpOffice\PhpSpreadsheet\Style\Font as StyleFont; use PHPUnit\Framework\TestCase; class Font3Test extends TestCase { private string $holdDirectory; protected function setUp(): void { $this->holdDirectory = Font::getTrueTypeFontPath(); } protected function tearDown(): void { Font::setTrueTypeFontPath($this->holdDirectory); } public function testGetTrueTypeException1(): void { $this->expectException(SSException::class); $this->expectExceptionMessage('Valid directory to TrueType Font files not specified'); $font = new StyleFont(); $font->setName('unknown'); Font::getTrueTypeFontFileFromFont($font); } public function testGetTrueTypeException2(): void { Font::setTrueTypeFontPath(__DIR__); $this->expectException(SSException::class); $this->expectExceptionMessage('Unknown font name'); $font = new StyleFont(); $font->setName('unknown'); Font::getTrueTypeFontFileFromFont($font); } public function testGetTrueTypeException3(): void { Font::setTrueTypeFontPath(__DIR__); $this->expectException(SSException::class); $this->expectExceptionMessage('TrueType Font file not found'); $font = new StyleFont(); $font->setName('Calibri'); Font::getTrueTypeFontFileFromFont($font); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php
tests/PhpSpreadsheetTests/Shared/StringHelperTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use DateTime; use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Csv; use PHPUnit\Framework\TestCase; class StringHelperTest extends TestCase { protected function tearDown(): void { StringHelper::setLocale(null); } public function testGetIsIconvEnabled(): void { $result = StringHelper::getIsIconvEnabled(); self::assertTrue($result); } public function testGetDecimalSeparator(): void { $localeconv = localeconv(); $expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ','; $result = StringHelper::getDecimalSeparator(); self::assertEquals($expectedResult, $result); } public function testSetDecimalSeparator(): void { $expectedResult = ','; StringHelper::setDecimalSeparator($expectedResult); $result = StringHelper::getDecimalSeparator(); self::assertEquals($expectedResult, $result); } public function testGetThousandsSeparator(): void { $localeconv = localeconv(); $expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ','; $result = StringHelper::getThousandsSeparator(); self::assertEquals($expectedResult, $result); } public function testSetThousandsSeparator(): void { $expectedResult = ' '; StringHelper::setThousandsSeparator($expectedResult); $result = StringHelper::getThousandsSeparator(); self::assertEquals($expectedResult, $result); } public function testGetCurrencyCode(): void { $localeconv = localeconv(); $expectedResult = (!empty($localeconv['currency_symbol']) ? $localeconv['currency_symbol'] : (!empty($localeconv['int_curr_symbol']) ? $localeconv['int_curr_symbol'] : '$')); $result = StringHelper::getCurrencyCode(); self::assertEquals($expectedResult, $result); } public function testSetCurrencyCode(): void { $expectedResult = '£'; StringHelper::setCurrencyCode($expectedResult); $result = StringHelper::getCurrencyCode(); self::assertEquals($expectedResult, $result); } public function testControlCharacterPHP2OOXML(): void { $expectedResult = 'foo_x000B_bar'; $result = StringHelper::controlCharacterPHP2OOXML('foo' . chr(11) . 'bar'); self::assertEquals($expectedResult, $result); } public function testControlCharacterOOXML2PHP(): void { $expectedResult = 'foo' . chr(11) . 'bar'; $result = StringHelper::controlCharacterOOXML2PHP('foo_x000B_bar'); self::assertEquals($expectedResult, $result); } public function testSYLKtoUTF8(): void { $expectedResult = 'foo' . chr(11) . 'bar'; $result = StringHelper::SYLKtoUTF8("foo\x1B ;bar"); self::assertEquals($expectedResult, $result); } public function testIssue3900(): void { StringHelper::setDecimalSeparator('.'); StringHelper::setThousandsSeparator(''); $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 1.4); $sheet->setCellValue('B1', 1004.5); $sheet->setCellValue('C1', 1000000.5); ob_start(); $ioWriter = new Csv($spreadsheet); $ioWriter->setDelimiter(';'); $ioWriter->save('php://output'); $output = ob_get_clean(); $spreadsheet->disconnectWorksheets(); self::assertSame('"1.4";"1004.5";"1000000.5"' . PHP_EOL, $output); } public function testNonStringable(): void { $dt = new DateTime(); self::assertSame('', StringHelper::convertToString($dt, false)); $this->expectException(SpreadsheetException::class); $this->expectExceptionMessage('Unable to convert to string'); StringHelper::convertToString($dt); } public function testNoIconv(): void { $string = "\xBF"; // inverted question mark in ISO-8859-1 $expected = '¿'; $from = 'ISO-8859-1'; $to = 'UTF-8'; self::assertSame($expected, StringHelper::convertEncoding($string, $to, $from)); self::assertSame('EUR', StringHelper::convertEncoding('€', 'ISO-8859-1', 'UTF-8'), 'transliterated'); self::assertSame($expected, StringHelperNoIconv::convertEncoding($string, $to, $from)); self::assertSame('?', StringHelperNoIconv::convertEncoding('€', 'ISO-8859-1', 'UTF-8'), 'using MB so no transliteration - just return question mark'); self::assertSame($expected, StringHelperNoIconv2::convertEncoding($string, $to, $from)); self::assertSame('?', StringHelperNoIconv2::convertEncoding('€', 'ISO-8859-1', 'UTF-8'), 'using MB so no transliteration - just return question mark'); self::assertSame($expected, StringHelperNoIconv3::convertEncoding($string, $to, $from)); self::assertSame('?', StringHelperNoIconv3::convertEncoding('€', 'ISO-8859-1', 'UTF-8'), 'using MB so no transliteration - just return question mark'); $noTransliteration = 'ツ'; // There is inconsistency in how //TRANSLIT operates. // On some systems, '?' seems to be used if there is // no other transliteration available. $ignoreResult = '?'; if (StringHelper::getIsIconvEnabled()) { $ignoreResult = iconv('UTF-8', 'ISO-8859-1//IGNORE//TRANSLIT', $noTransliteration); self::assertContains($ignoreResult, ['', '?']); } self::assertSame($ignoreResult, StringHelper::convertEncoding($noTransliteration, 'ISO-8859-1', 'UTF-8'), 'no transliteration available'); self::assertSame('', StringHelper::convertEncoding($noTransliteration, 'ISO-8859-1', 'UTF-8', '//IGNORE'), 'TRANSLIT not used'); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/OLEReadTest.php
tests/PhpSpreadsheetTests/Shared/OLEReadTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\OLERead; use PHPUnit\Framework\TestCase; class OLEReadTest extends TestCase { public function testReadOleStreams(): void { $dataDir = 'tests/data/Shared/OLERead/'; $ole = new OLERead(); $ole->read('tests/data/Reader/XLS/sample.xls'); self::assertEquals( file_get_contents($dataDir . 'wrkbook'), $ole->getStream($ole->wrkbook) ); self::assertEquals( file_get_contents($dataDir . 'summary'), $ole->getStream($ole->summaryInformation) ); self::assertEquals( file_get_contents($dataDir . 'document'), $ole->getStream($ole->documentSummaryInformation) ); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/DggContainerTest.php
tests/PhpSpreadsheetTests/Shared/DggContainerTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Escher\DggContainer; use PHPUnit\Framework\TestCase; class DggContainerTest extends TestCase { public function testBseParent(): void { $container = new DggContainer\BstoreContainer(); $bse = new DggContainer\BstoreContainer\BSE(); $bse->setParent($container); self::assertSame($container, $bse->getParent()); } public function testGetOpt(): void { $dgg = new DggContainer(); self::assertNull($dgg->getOPT(99)); $dgg->setOPT(98, 'whatever'); self::assertSame('whatever', $dgg->getOPT(98)); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv2.php
tests/PhpSpreadsheetTests/Shared/StringHelperNoIconv2.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; class StringHelperNoIconv2 extends StringHelper { protected static ?bool $isIconvEnabled = null; protected static bool $iconvTest2 = true; }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/StringHelperLocaleTest.php
tests/PhpSpreadsheetTests/Shared/StringHelperLocaleTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PHPUnit\Framework\TestCase; class StringHelperLocaleTest extends TestCase { /** * @var false|string */ private $currentLocale; protected function setUp(): void { $this->currentLocale = setlocale(LC_ALL, '0'); StringHelper::setCurrencyCode(null); } protected function tearDown(): void { if (is_string($this->currentLocale)) { setlocale(LC_ALL, $this->currentLocale); } StringHelper::setCurrencyCode(null); } public function testCurrency(): void { $currentLocale = ($this->currentLocale === false) ? null : $this->currentLocale; if ($this->currentLocale === false || !setlocale(LC_ALL, 'de_DE.UTF-8', 'deu_deu.utf8')) { self::markTestSkipped('Unable to set German UTF8 locale for testing.'); } $result = StringHelper::getCurrencyCode(); self::assertSame('€', $result); if (!setlocale(LC_ALL, $currentLocale)) { self::markTestSkipped('Unable to restore default locale.'); } $result = StringHelper::getCurrencyCode(); self::assertSame('€', $result, 'result persists despite locale change'); StringHelper::setCurrencyCode(null); $result = StringHelper::getCurrencyCode(); self::assertSame('$', $result, 'locale now used'); StringHelper::setCurrencyCode(null); if (!setlocale(LC_ALL, 'deu_deu', 'de_DE@euro')) { self::markTestSkipped('Unable to set German single-byte locale for testing.'); } $result = StringHelper::getCurrencyCode(true); // trim if alt symbol is used self::assertSame('EUR', $result, 'non-UTF8 result ignored'); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/XlsTest.php
tests/PhpSpreadsheetTests/Shared/XlsTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Xls as SharedXls; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\TestCase; class XlsTest extends TestCase { public function testSizes(): void { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->fromArray([[1, 2], [3, 4]]); $sheet->getColumnDimension('B')->setVisible(false); $sheet->getRowDimension(2)->setVisible(false); self::assertSame(64, SharedXls::sizeCol($sheet, 'A')); self::assertSame(0, SharedXls::sizeCol($sheet, 'B')); self::assertSame(20, SharedXls::sizeRow($sheet, 1)); self::assertSame(0, SharedXls::sizeRow($sheet, 2)); self::assertNull(SharedXls::oneAnchor2twoAnchor($sheet, 'B1', 0, 0, 100, 100)); self::assertNull(SharedXls::oneAnchor2twoAnchor($sheet, 'A2', 0, 0, 100, 100)); $expected = [ 'startCoordinates' => 'D9', 'startOffsetX' => 0, 'startOffsetY' => 0, 'endCoordinates' => 'E13', 'endOffsetX' => 576.0, 'endOffsetY' => 256, ]; self::assertSame($expected, SharedXls::oneAnchor2twoAnchor($sheet, 'D9', 0, 0, 100, 100)); $spreadsheet->disconnectWorksheets(); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/OLEPhpunit10Test.php
tests/PhpSpreadsheetTests/Shared/OLEPhpunit10Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\OLE; use PHPUnit\Framework\TestCase; /** * There were problems running these tests in OLETest with PhpUnit 10. * These replacements seem to work. */ class OLEPhpunit10Test extends TestCase { private static string $errorString; protected function setUp(): void { self::$errorString = ''; set_error_handler([self::class, 'errorHandler']); } protected function tearDown(): void { restore_error_handler(); } public static function errorHandler(int $errno, string $errstr): bool { if ($errno === E_USER_WARNING) { self::$errorString = $errstr; return true; // stop error handling } return false; // continue error handling } public function testChainedWriteMode(): void { self::assertSame('', self::$errorString); $ole = new OLE\ChainedBlockStream(); $openedPath = ''; self::assertFalse($ole->stream_open('whatever', 'w', 0, $openedPath)); $ole->stream_open('whatever', 'w', STREAM_REPORT_ERRORS, $openedPath); self::assertSame('Only reading is supported', self::$errorString); } public function testChainedBadPath(): void { self::assertSame('', self::$errorString); $ole = new OLE\ChainedBlockStream(); $openedPath = ''; self::assertFalse($ole->stream_open('whatever', 'r', 0, $openedPath)); $ole->stream_open('whatever', 'r', STREAM_REPORT_ERRORS, $openedPath); self::assertSame('OLE stream not found', self::$errorString); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/OLETest.php
tests/PhpSpreadsheetTests/Shared/OLETest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; use PhpOffice\PhpSpreadsheet\Shared\OLE; use PHPUnit\Framework\TestCase; class OLETest extends TestCase { public function testReadNotOle(): void { $this->expectException(ReaderException::class); $this->expectExceptionMessage('File doesn\'t seem to be an OLE container.'); $ole = new OLE(); $ole->read(__FILE__); } public function testReadNotExist(): void { $this->expectException(ReaderException::class); $this->expectExceptionMessage('Can\'t open file'); $ole = new OLE(); $ole->read(__FILE__ . '.xxx'); } public function testReadOleStreams(): void { $dataDir = 'tests/data/Shared/OLERead/'; $ole = new OLE(); $oleData = $ole->read('tests/data/Reader/XLS/sample.xls'); self::assertEquals( file_get_contents($dataDir . 'wrkbook'), $oleData ); self::assertSame(512, $ole->bigBlockSize); self::assertSame(64, $ole->smallBlockSize); self::assertSame(4096, $ole->bigBlockThreshold); self::assertSame(1024, $ole->getBlockOffset(1)); } // testChainedWriteMode moved to OLEPhpunit10Test // testChainedBadPath moved to OLEPhpunit10Test public function testOleFunctions(): void { $ole = new OLE(); $infile = 'tests/data/Reader/XLS/pr.4687.excel.xls'; $ole->read($infile); self::assertSame(4, $ole->ppsTotal()); self::assertFalse($ole->isFile(0), 'root entry'); self::assertTrue($ole->isFile(1), 'workbook'); self::assertTrue($ole->isFile(2), 'summary information'); self::assertTrue($ole->isFile(3), 'document summary information'); self::assertFalse($ole->isFile(4), 'no such index'); self::assertTrue($ole->isRoot(0), 'root entry'); self::assertFalse($ole->isRoot(1), 'workbook'); self::assertFalse($ole->isRoot(2), 'summary information'); self::assertFalse($ole->isRoot(3), 'document summary information'); self::assertFalse($ole->isRoot(4), 'no such index'); self::assertSame(0, $ole->getDataLength(0), 'root entry'); self::assertSame(15712, $ole->getDataLength(1), 'workbook'); self::assertSame(4096, $ole->getDataLength(2), 'summary information'); self::assertSame(4096, $ole->getDataLength(3), 'document summary information'); self::assertSame(0, $ole->getDataLength(4), 'no such index'); self::assertSame('', $ole->getData(2, -1, 4), 'negative position'); self::assertSame('', $ole->getData(2, 5000, 4), 'position > length'); self::assertSame('feff0000', bin2hex($ole->getData(2, 0, 4))); self::assertSame('', $ole->getData(4, 0, 4), 'no such index'); } public function testBadEndian(): void { $this->expectException(ReaderException::class); $this->expectExceptionMessage('Only Little-Endian encoding is supported'); $ole = new OLE(); $infile = 'tests/data/Reader/XLS/pr.4687.excel.badendian.xls'; $ole->read($infile); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/StringHelperLocale2Test.php
tests/PhpSpreadsheetTests/Shared/StringHelperLocale2Test.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class StringHelperLocale2Test extends TestCase { private Spreadsheet $spreadsheet; protected function tearDown(): void { StringHelper::setLocale(null); $this->spreadsheet->disconnectWorksheets(); unset($this->spreadsheet); } #[DataProvider('providerIntlLocales')] public function testIntlLocales(bool|string $expectedResult, string $expectedTrue, ?string $locale): void { $this->spreadsheet = new Spreadsheet(); $number = 12345.67; $numberFormat = '[$]#,##0.0'; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->fromArray([[$number]]); $sheet->getStyle('A1')->getNumberFormat() ->setFormatCode($numberFormat); $success = StringHelper::setLocale($locale); if ($success === false) { self::assertFalse($expectedResult); } else { $result = $sheet->getCell('A1')->getFormattedValue(); self::assertSame($expectedResult, $result); self::assertSame($expectedTrue, Calculation::getTRUE()); } } /** * The data here are somewhat volatile. * They may change with any new release of ICU. */ public static function providerIntlLocales(): array { $nbsp = "\u{A0}"; $nnbsp = "\u{202F}"; $rsquo = "\u{2019}"; return [ [false, 'TRUE', 'unknownlocale'], ["¤12{$nbsp}345,7", 'SANT', 'sv'], ['$12,345.7', 'TRUE', 'en_US'], 'lowercase country' => ["€12{$nnbsp}345,7", 'VRAI', 'fr_fr'], 'reset if locale is null' => ['$12,345.7', 'TRUE', null], ["CHF12{$rsquo}345.7", 'VERO', 'it_CH'], 'ignore utf-8' => ['د.ك.‏12٬345٫7', 'TRUE', 'ar_KW.UTF-8'], 'non-Latin' => ["₽12{$nbsp}345,7", 'ИСТИНА', 'ru_ru'], ]; } public function testNoIntl(): void { $this->spreadsheet = new Spreadsheet(); $number = 12345.67; $numberFormat = '[$]#,##0.0'; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->fromArray([[$number]]); $sheet->getStyle('A1')->getNumberFormat() ->setFormatCode($numberFormat); $success = StringHelperNoIntl::setLocale('en_US'); self::assertFalse($success); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/CodePageTest.php
tests/PhpSpreadsheetTests/Shared/CodePageTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Shared\CodePage; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class CodePageTest extends TestCase { /** * @param string|string[] $expectedResult */ #[DataProvider('providerCodePage')] public function testCodePageNumberToName(array|string $expectedResult, int $codePageIndex): void { if ($expectedResult === 'exception') { $this->expectException(Exception::class); } $result = CodePage::numberToName($codePageIndex); if (is_array($expectedResult)) { self::assertContains($result, $expectedResult); } else { self::assertEquals($expectedResult, $result); } } public static function providerCodePage(): array { return require 'tests/data/Shared/CodePage.php'; } public function testCoverage(): void { $covered = []; $expected = CodePage::getEncodings(); foreach ($expected as $key => $val) { $covered[$key] = 0; } $tests = $this->providerCodePage(); foreach ($tests as $test) { /** @var string[] $test */ $covered[$test[1]] = 1; } foreach ($covered as $key => $val) { self::assertEquals(1, $val, "Codepage $key not tested"); } } public function testNumberToNameWithInvalidCodePage(): void { $invalidCodePage = 12345; try { CodePage::numberToName($invalidCodePage); } catch (Exception $e) { self::assertEquals($e->getMessage(), 'Unknown codepage: 12345'); return; } self::fail('An expected exception has not been raised.'); } public function testNumberToNameWithUnsupportedCodePage(): void { $unsupportedCodePage = 720; try { CodePage::numberToName($unsupportedCodePage); } catch (Exception $e) { self::assertEquals($e->getMessage(), 'Code page 720 not supported.'); return; } self::fail('An expected exception has not been raised.'); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/DrawingTest.php
tests/PhpSpreadsheetTests/Shared/DrawingTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\Drawing; use PhpOffice\PhpSpreadsheet\Style\Font; use PHPUnit\Framework\TestCase; class DrawingTest extends TestCase { #[\PHPUnit\Framework\Attributes\DataProvider('providerPixelsToCellDimension')] public function testPixelsToCellDimension( float $expectedResult, int $pixelSize, string $fontName, int $fontSize ): void { $font = new Font(); $font->setName($fontName); $font->setSize($fontSize); $result = Drawing::pixelsToCellDimension($pixelSize, $font); self::assertSame($expectedResult, $result); } #[\PHPUnit\Framework\Attributes\DataProvider('providerCellDimensionToPixels')] public function testCellDimensionToPixels( int $expectedResult, int $cellSize, string $fontName, int $fontSize ): void { $font = new Font(); $font->setName($fontName); $font->setSize($fontSize); $result = Drawing::cellDimensionToPixels($cellSize, $font); self::assertSame($expectedResult, $result); } public static function providerPixelsToCellDimension(): array { return [ [19.9951171875, 100, 'Arial', 7], [14.2822265625, 100, 'Arial', 9], [14.2822265625, 100, 'Arial', 11], [13.092041015625, 100, 'Arial', 12], // approximation by extrapolating from Calibri 11 [19.9951171875, 100, 'Calibri', 7], [16.664341517857142, 100, 'Calibri', 9], [14.2822265625, 100, 'Calibri', 11], [13.092041015625, 100, 'Calibri', 12], // approximation by extrapolating from Calibri 11 [19.9951171875, 100, 'Verdana', 7], [12.5, 100, 'Verdana', 9], [13.092041015625, 100, 'Verdana', 12], // approximation by extrapolating from Calibri 11 [17.4560546875, 100, 'Wingdings', 9], // approximation by extrapolating from Calibri 11 ]; } public static function providerCellDimensionToPixels(): array { return [ [500, 100, 'Arial', 7], [700, 100, 'Arial', 9], [700, 100, 'Arial', 11], [764, 100, 'Arial', 12], // approximation by extrapolating from Calibri 11 [500, 100, 'Calibri', 7], [600, 100, 'Calibri', 9], [700, 100, 'Calibri', 11], [764, 100, 'Calibri', 12], // approximation by extrapolating from Calibri 11 [500, 100, 'Verdana', 7], [800, 100, 'Verdana', 9], [764, 100, 'Verdana', 12], // approximation by extrapolating from Calibri 11 [573, 100, 'Wingdings', 9], // approximation by extrapolating from Calibri 11 ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/PasswordReloadTest.php
tests/PhpSpreadsheetTests/Shared/PasswordReloadTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared; use PhpOffice\PhpSpreadsheet\Shared\PasswordHasher; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional; class PasswordReloadTest extends AbstractFunctional { #[\PHPUnit\Framework\Attributes\DataProvider('providerPasswords')] public function testPasswordReload(string $format, string $algorithm, bool $supported = true): void { $password = 'hello'; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->getCell('A1')->setValue(1); $protection = $sheet->getProtection(); $protection->setAlgorithm($algorithm); $protection->setPassword($password); $protection->setSheet(true); $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format); $resheet = $reloadedSpreadsheet->getActiveSheet(); $reprot = $resheet->getProtection(); $repassword = $reprot->getPassword(); $hash = ''; if ($supported) { $readAlgorithm = $reprot->getAlgorithm(); self::assertSame($algorithm, $readAlgorithm); $salt = $reprot->getSalt(); $spin = $reprot->getSpinCount(); $hash = PasswordHasher::hashPassword($password, $readAlgorithm, $salt, $spin); } self::assertSame($repassword, $hash); $spreadsheet->disconnectWorksheets(); $reloadedSpreadsheet->disconnectWorksheets(); } public static function providerPasswords(): array { return [ 'Xls basic algorithm' => ['Xls', ''], 'Xls cannot use SHA512' => ['Xls', 'SHA-512', false], 'Xlsx basic algorithm' => ['Xlsx', ''], 'Xlsx can use SHA512' => ['Xlsx', 'SHA-512'], ]; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Trend/BestFitTest.php
tests/PhpSpreadsheetTests/Shared/Trend/BestFitTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared\Trend; use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; use PhpOffice\PhpSpreadsheet\Shared\Trend\Trend; use PHPUnit\Framework\TestCase; class BestFitTest extends TestCase { private const LBF_PRECISION = 1.0E-4; public function testBestFit(): void { $xValues = [45, 55, 47, 75, 90, 100, 100, 95, 88, 50, 45, 58]; $yValues = [15, 25, 17, 30, 41, 47, 50, 46, 37, 22, 20, 26]; $maxGoodness = -1000.0; $maxType = ''; $type = Trend::TREND_LINEAR; $result = Trend::calculate($type, $yValues, $xValues); $goodness = $result->getGoodnessOfFit(); if ($maxGoodness < $goodness) { $maxGoodness = $goodness; $maxType = $type; } self::assertEqualsWithDelta(0.9628, $goodness, self::LBF_PRECISION); $type = Trend::TREND_EXPONENTIAL; $result = Trend::calculate($type, $yValues, $xValues); $goodness = $result->getGoodnessOfFit(); if ($maxGoodness < $goodness) { $maxGoodness = $goodness; $maxType = $type; } self::assertEqualsWithDelta(0.9952, $goodness, self::LBF_PRECISION); $type = Trend::TREND_LOGARITHMIC; $result = Trend::calculate($type, $yValues, $xValues); $goodness = $result->getGoodnessOfFit(); if ($maxGoodness < $goodness) { $maxGoodness = $goodness; $maxType = $type; } self::assertEqualsWithDelta(-0.0724, $goodness, self::LBF_PRECISION); self::assertEqualsWithDelta(0.3116, $result->getValueOfXForY(2.1), self::LBF_PRECISION); $equation = $result->getEquation(); $match = preg_match('/^Y = 0[.]01765\d+ [*] log[(]2.1205\d+ [*] X[)]$/', $equation); self::assertSame(1, $match, $equation); $type = Trend::TREND_POWER; $result = Trend::calculate($type, $yValues, $xValues); $goodness = $result->getGoodnessOfFit(); if ($maxGoodness < $goodness) { $maxGoodness = $goodness; $maxType = $type; } self::assertEqualsWithDelta(0.9946, $goodness, self::LBF_PRECISION); self::assertEqualsWithDelta(28.0886, $result->getValueOfXForY(10.0), self::LBF_PRECISION); $equation = $result->getEquation(); $match = preg_match('/^Y = 0[.]1705\d+ [*] X\^1[.]2207\d+$/', $equation); self::assertSame(1, $match, $equation); self::assertEqualsWithDelta(0.1705, $result->getIntersect(4), self::LBF_PRECISION); $type = Trend::TREND_BEST_FIT_NO_POLY; $result = Trend::calculate($type, $yValues, $xValues); $goodness = $result->getGoodnessOfFit(); self::assertSame($maxGoodness, $goodness); self::assertSame(lcfirst($maxType), $result->getBestFitType()); try { $type = Trend::TREND_BEST_FIT; Trend::calculate($type, $yValues, [0, 1, 2]); self::fail('should have failed - mismatched number of elements'); } catch (SpreadsheetException $e) { self::assertStringContainsString('Number of elements', $e->getMessage()); } try { $type = Trend::TREND_BEST_FIT; Trend::calculate($type, $yValues, $xValues); self::fail('should have failed - TREND_BEST_FIT includes polynomials which are not implemented yet'); } catch (SpreadsheetException $e) { self::assertStringContainsString('not yet implemented', $e->getMessage()); } try { $type = 'unknown'; Trend::calculate($type, $yValues, $xValues); self::fail('should have failed - invalid trend type'); } catch (SpreadsheetException $e) { self::assertStringContainsString('Unknown trend type', $e->getMessage()); } } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Trend/LinearBestFitTest.php
tests/PhpSpreadsheetTests/Shared/Trend/LinearBestFitTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared\Trend; use PhpOffice\PhpSpreadsheet\Shared\Trend\LinearBestFit; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class LinearBestFitTest extends TestCase { const LBF_PRECISION = 1.0E-8; /** * @param array<mixed> $expectedSlope * @param array<mixed> $expectedIntersect * @param array<mixed> $expectedGoodnessOfFit * @param array<float> $yValues * @param array<float> $xValues */ #[DataProvider('providerLinearBestFit')] public function testLinearBestFit( array $expectedSlope, array $expectedIntersect, array $expectedGoodnessOfFit, mixed $expectedEquation, array $yValues, array $xValues, float $xForY, ): void { $bestFit = new LinearBestFit($yValues, $xValues); $slope = $bestFit->getSlope(1); self::assertEqualsWithDelta($expectedSlope[0], $slope, self::LBF_PRECISION); $slope = $bestFit->getSlope(); self::assertEqualsWithDelta($expectedSlope[1], $slope, self::LBF_PRECISION); $intersect = $bestFit->getIntersect(1); self::assertEqualsWithDelta($expectedIntersect[0], $intersect, self::LBF_PRECISION); $intersect = $bestFit->getIntersect(); self::assertEqualsWithDelta($expectedIntersect[1], $intersect, self::LBF_PRECISION); $equation = $bestFit->getEquation(2); self::assertEquals($expectedEquation, $equation); self::assertSame($expectedGoodnessOfFit[0], $bestFit->getGoodnessOfFit(6)); self::assertSame($expectedGoodnessOfFit[1], $bestFit->getGoodnessOfFit()); self::assertEqualsWithDelta($xForY, $bestFit->getValueOfXForY(0.0), self::LBF_PRECISION); } public static function providerLinearBestFit(): array { return require 'tests/data/Shared/Trend/LinearBestFit.php'; } public function testConstructor(): void { $bestFit = new LinearBestFit([1, 2, 3], [4, 5]); self::assertTrue($bestFit->getError()); $bestFit = new LinearBestFit([6.0, 8.0, 10.0]); self::assertFalse($bestFit->getError()); self::assertSame([6.0, 8.0, 10.0], $bestFit->getYValues()); self::assertSame([1.0, 2.0, 3.0], $bestFit->getXValues()); } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Shared/Trend/ExponentialBestFitTest.php
tests/PhpSpreadsheetTests/Shared/Trend/ExponentialBestFitTest.php
<?php declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Shared\Trend; use PhpOffice\PhpSpreadsheet\Shared\Trend\ExponentialBestFit; use PHPUnit\Framework\TestCase; class ExponentialBestFitTest extends TestCase { private const EBF_PRECISION6 = 1.0E-6; private const EBF_PRECISION5 = 1.0E-5; private const DP = 4; /** * @param array<mixed> $expectedSlope * @param array<mixed> $expectedIntersect * @param array<mixed> $expectedGoodnessOfFit * @param array<float> $yValues * @param array<float> $xValues */ #[\PHPUnit\Framework\Attributes\DataProvider('providerExponentialBestFit')] public function testExponentialBestFit( array $expectedSlope, array $expectedIntersect, array $expectedGoodnessOfFit, mixed $expectedEquation, array $yValues, array $xValues ): void { $bestFit = new ExponentialBestFit($yValues, $xValues); $slope = $bestFit->getSlope(1); self::assertEquals($expectedSlope[0], $slope); self::assertFalse($bestFit->getError()); self::assertEqualsWithDelta(0.2117, $bestFit->getSlopeSE(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta(1.5380, $bestFit->getIntersectSE(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta( 90.486819, $bestFit->getGoodnessOfFitPercent(), self::EBF_PRECISION6 ); self::assertEqualsWithDelta( 90.4868, $bestFit->getGoodnessOfFitPercent(self::DP), self::EBF_PRECISION5 ); self::assertEqualsWithDelta(2.3031, $bestFit->getStdevOfResiduals(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta(403.6333, $bestFit->getSSRegression(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta(42.4353, $bestFit->getSSResiduals(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta(8, $bestFit->getDFResiduals(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta(76.0938, $bestFit->getF(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta(-13.1, $bestFit->getCovariance(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta(-0.919, $bestFit->getCorrelation(self::DP), self::EBF_PRECISION5); self::assertEqualsWithDelta(3.51845, $bestFit->getValueOfXForY(10.0), self::EBF_PRECISION5); $values = $bestFit->getYBestFitValues(); self::assertCount(10, $values); self::assertEqualsWithDelta(3.965445, $values[0], self::EBF_PRECISION6); $slope = $bestFit->getSlope(); self::assertEquals($expectedSlope[1], $slope); $intersect = $bestFit->getIntersect(1); self::assertEquals($expectedIntersect[0], $intersect); $intersect = $bestFit->getIntersect(); self::assertEquals($expectedIntersect[1], $intersect); $equation = $bestFit->getEquation(2); self::assertEquals($expectedEquation, $equation); self::assertSame($expectedGoodnessOfFit[0], $bestFit->getGoodnessOfFit(6)); self::assertSame($expectedGoodnessOfFit[1], $bestFit->getGoodnessOfFit()); } public static function providerExponentialBestFit(): array { return require 'tests/data/Shared/Trend/ExponentialBestFit.php'; } }
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellAbsoluteReference.php
tests/data/CellAbsoluteReference.php
<?php declare(strict_types=1); return [ [ '$A$1', 'A1', ], [ '$A$12', 'A12', ], [ '$J$1', 'J1', ], [ '$J$20', 'J20', ], [ '$AI$1', 'AI1', ], [ '$AI$2012', 'AI2012', ], [ '\'Work!sheet1\'!$AI$256', '\'Work!sheet1\'!AI256', ], [ 'Work!sheet1!$AI$256', 'Work!sheet1!AI256', ], [ '\'Data Worksheet\'!$AI$256', '\'Data Worksheet\'!AI256', ], [ '$AI', 'AI', ], [ '$2012', 2012, ], [ 'Worksheet1!$AI', 'Worksheet1!AI', ], [ 'Worksheet1!$256', 'Worksheet1!256', ], [ '\'Worksheet1\'!$AI$256', '\'Worksheet1\'!$AI256', ], [ '\'Worksheet1\'!$AI$256', '\'Worksheet1\'!AI$256', ], [ '\'Worksheet1\'!$AI$256', '\'Worksheet1\'!$AI$256', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellExtractAllCellReferencesInRange.php
tests/data/CellExtractAllCellReferencesInRange.php
<?php declare(strict_types=1); return [ [ [ 'B4', 'B5', 'B6', ], 'B4:B6', ], [ [ 'B4', 'D4', 'B5', 'D5', 'B6', 'D6', ], 'B4:B6,D4:D6', ], [ [ ], 'B4:B6 D4:D6', ], [ [ 'B4', 'C4', 'D4', 'B5', 'C5', 'D5', 'B6', 'C6', 'D6', ], 'B4:D6', ], [ [ 'B4', 'C4', 'D4', 'B5', 'C5', 'D5', 'E5', 'B6', 'C6', 'D6', 'E6', 'C7', 'D7', 'E7', ], 'B4:D6,C5:E7', ], [ [ 'C5', 'D5', 'C6', 'D6', ], 'B4:D6 C5:E7', ], [ [ 'B2', 'C2', 'D2', 'B3', 'C3', 'D3', 'E3', 'B4', 'C4', 'D4', 'E4', 'F4', 'C5', 'D5', 'E5', 'F5', 'D6', 'E6', 'F6', ], 'B2:D4,C5:D5,E3:E5,D6:E6,F4:F6', ], [ [ 'B2', 'C2', 'D2', 'B3', 'C3', 'D3', 'E3', 'B4', 'C4', 'D4', 'E4', 'F4', 'C5', 'D5', 'E5', 'F5', 'D6', 'E6', 'F6', ], 'B2:D4,C3:E5,D4:F6', ], [ [ 'B5', ], 'B4:B6 B5', ], [ [ 'Z2', 'AA2', 'Z3', 'AA3', ], 'Z2:AA3', ], [ [ 'Sheet1!D3', ], 'Sheet1!D3', ], [ [ 'Sheet1!D3', 'Sheet1!E3', 'Sheet1!D4', 'Sheet1!E4', ], 'Sheet1!D3:E4', ], [ [ "'Sheet 1'!D3", "'Sheet 1'!E3", "'Sheet 1'!D4", "'Sheet 1'!E4", ], "'Sheet 1'!D3:E4", ], [ [ "'Mark''s Sheet'!D3", "'Mark''s Sheet'!E3", "'Mark''s Sheet'!D4", "'Mark''s Sheet'!E4", ], "'Mark's Sheet'!D3:E4", ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CalculationBinaryComparisonOperation.php
tests/data/CalculationBinaryComparisonOperation.php
<?php declare(strict_types=1); // formula, expectedResultExcel, expectedResultOpenOffice return [ [ '=TRUE', true, true, ], [ '=1 + 2.5', 3.5, 3.5, ], [ '=2.5 + 1', 3.5, 3.5, ], [ '=1 - 2.5', -1.5, -1.5, ], [ '=2.5 - 1', 1.5, 1.5, ], [ '=3 > 1', true, true, ], [ '=3 > 3', false, false, ], [ '=1 > 3', false, false, ], [ '=3 < 1', false, false, ], [ '=3 < 3', false, false, ], [ '=1 < 3', true, true, ], [ '=3 = 1', false, false, ], [ '=3 = 3', true, true, ], [ '=1 = 1.0', true, true, ], [ '=3 >= 1', true, true, ], [ '=3 >= 3', true, true, ], [ '=1 >= 3', false, false, ], [ '=3 <= 1', false, false, ], [ '=3 <= 3', true, true, ], [ '=1 <= 3', true, true, ], [ '=3 <> 1', true, true, ], [ '=3 <> 3', false, false, ], [ '=1 <> 1.0', false, false, ], [ '="a" > "a"', false, false, ], [ '="A" > "A"', false, false, ], [ '="A" > "a"', false, true, ], [ '="a" > "A"', false, false, ], [ '="a" < "a"', false, false, ], [ '="A" < "A"', false, false, ], [ '="A" < "a"', false, false, ], [ '="a" < "A"', false, true, ], [ '="a" = "a"', true, true, ], [ '="A" = "A"', true, true, ], [ '="A" = "a"', true, false, ], [ '="a" = "A"', true, false, ], [ '="a" <= "a"', true, true, ], [ '="A" <= "A"', true, true, ], [ '="A" <= "a"', true, false, ], [ '="a" <= "A"', true, true, ], [ '="a" >= "a"', true, true, ], [ '="A" >= "A"', true, true, ], [ '="A" >= "a"', true, true, ], [ '="a" >= "A"', true, false, ], [ '="a" <> "a"', false, false, ], [ '="A" <> "A"', false, false, ], [ '="A" <> "a"', false, true, ], [ '="a" <> "A"', false, true, ], [ '= NULL = 0', true, true, ], [ '= NULL < 0', false, false, ], [ '= NULL <= 0', true, true, ], [ '= NULL > 0', false, false, ], [ '= NULL >= 0', true, true, ], [ '= NULL <> 0', false, false, ], [ '="A" > "b"', false, true, ], [ '="a" > "b"', false, false, ], [ '="b" > "a"', true, true, ], [ '="b" > "A"', true, false, ], // Test natural sorting is not used [ '="a2" > "a10"', true, true, ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CoordinateIsRange.php
tests/data/CoordinateIsRange.php
<?php declare(strict_types=1); return [ [ false, 'A1', ], [ false, '$A$1', ], [ true, 'A1,C3', ], [ true, 'A1:A10', ], [ true, 'A1:A10,C4', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellMergeRangesInCollection.php
tests/data/CellMergeRangesInCollection.php
<?php declare(strict_types=1); return [ [ [ 'A1:A3' => 'x', 'A4' => 'y', ], [ 'A1' => 'x', 'A2' => 'x', 'A3' => 'x', 'A4' => 'y', ], ], [ [ 'A1:A4' => 'x', 'A6:A7' => 'x', 'A9' => 'x', ], [ 'A7' => 'x', 'A1' => 'x', 'A4' => 'x', 'A6' => 'x', 'A2' => 'x', 'A9' => 'x', 'A3' => 'x', ], ], [ [ 'A1:A3' => 'x', 'B1:B3' => 'x', ], [ 'A1' => 'x', 'B3' => 'x', 'A2' => 'x', 'B2' => 'x', 'A3' => 'x', 'B1' => 'x', ], ], [ [ 'A1' => 'x', 'A2' => 'y', 'A3' => 'z', ], [ 'A1' => 'x', 'A2' => 'y', 'A3' => 'z', ], ], [ [ 'C1' => 'x', 'A1:A3' => 'x', 'A1:A3,C1:C3' => 'y', ], [ 'C1' => 'x', 'A1:A3' => 'x', 'A1:A3,C1:C3' => 'y', ], ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellBuildRange.php
tests/data/CellBuildRange.php
<?php declare(strict_types=1); return [ [ 'B4:E9', [ [ 'B4', 'E9', ], ], ], [ 'B4:E9,H2:O11', [ [ 'B4', 'E9', ], [ 'H2', 'O11', ], ], ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/ColumnIndex.php
tests/data/ColumnIndex.php
<?php declare(strict_types=1); return [ [ 'A', 1, ], [ 'Z', 26, ], [ 'AA', 27, ], [ 'AB', 28, ], [ 'AZ', 52, ], [ 'BA', 53, ], [ 'BZ', 78, ], [ 'CA', 79, ], [ 'IV', 256, ], [ 'ZZ', 702, ], [ 'AAA', 703, ], [ 'BAA', 1379, ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellGetRangeBoundaries.php
tests/data/CellGetRangeBoundaries.php
<?php declare(strict_types=1); return [ 'Cell Range' => [ [ ['B', 4], ['E', 9], ], 'B4:E9', ], 'Single Cell' => [ [ ['B', 4], ['B', 4], ], 'B4', ], 'Column Range' => [ [ ['B', 1], ['C', 1048576], ], 'B:C', ], 'Single Column Range' => [ [ ['B', 1], ['B', 1048576], ], 'B:B', ], 'Row Range' => [ [ ['A', 2], ['XFD', 3], ], '2:3', ], 'Single Row Range' => [ [ ['A', 2], ['XFD', 2], ], '2:2', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellRangeDimension.php
tests/data/CellRangeDimension.php
<?php declare(strict_types=1); return [ [ [ 4, 6, ], 'B4:E9', ], [ [ 1, 1, ], 'B4', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/ColumnString.php
tests/data/ColumnString.php
<?php declare(strict_types=1); return [ [ 1, 'A', ], [ 26, 'Z', ], [ 27, 'AA', ], [ 28, 'AB', ], [ 52, 'AZ', ], [ 53, 'BA', ], [ 78, 'BZ', ], [ 79, 'CA', ], [ 256, 'IV', ], [ 702, 'ZZ', ], [ 703, 'AAA', ], [ 1379, 'BAA', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellCoordinates.php
tests/data/CellCoordinates.php
<?php declare(strict_types=1); return [ [ [ 'A', 1, ], 'A1', ], [ [ 'A', 12, ], 'A12', ], [ [ 'J', 1, ], 'J1', ], [ [ 'J', 20, ], 'J20', ], [ [ 'AI', 1, ], 'AI1', ], [ [ 'AI', 2012, ], 'AI2012', ], [ [ 'B', 3, ], 'B3', ], [ [ '$B', 3, ], '$B3', ], [ [ 'B', '$3', ], 'B$3', ], [ [ '$B', '$3', ], '$B$3', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/ReferenceHelperFormulaUpdatesMultipleSheet.php
tests/data/ReferenceHelperFormulaUpdatesMultipleSheet.php
<?php declare(strict_types=1); return [ [ "=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B1)-1))", 2, 2, "=IF('2020'!\$B3=\"\",\"-\",(('2020'!\$B3/'2019'!\$B3)-1))", ], [ "=IF('2020'!B$1=\"\",\"-\",(('2020'!B$1/'2019'!B$1)-1))", 2, 2, "=IF('2020'!D\$1=\"\",\"-\",(('2020'!D\$1/'2019'!D\$1)-1))", ], [ "=IF('2020'!Z$1=\"\",\"-\",(('2020'!Z$1/'2019'!Z$1)-1))", 2, 2, "=IF('2020'!AB\$1=\"\",\"-\",(('2020'!AB\$1/'2019'!AB\$1)-1))", ], [ '=SUM(A1:C3)', 2, 2, '=SUM(C3:E5)', ], [ '=SUM($A1:C3)', 2, 2, '=SUM($A3:E5)', ], [ '=SUM($A1:$A3)', 2, 2, '=SUM($A3:$A5)', ], [ '=SUM(A$1:C3)', 2, 2, '=SUM(C$1:E5)', ], [ '=SUM(A$1:C$3)', 2, 2, '=SUM(C$1:E$3)', ], [ '=SUM(A:C)', 2, 2, '=SUM(C:E)', ], [ '=SUM($A:C)', 2, 2, '=SUM($A:E)', ], [ '=SUM(A:$E)', 2, 2, '=SUM(C:$E)', ], [ '=SUM(1:3)', 2, 2, '=SUM(3:5)', ], [ '=SUM($1:3)', 2, 2, '=SUM($1:5)', ], [ '=SUM(1:$5)', 2, 2, '=SUM(3:$5)', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellRangeBoundaries.php
tests/data/CellRangeBoundaries.php
<?php declare(strict_types=1); return [ 'Cell Range' => [ [ [2, 4], [5, 9], ], 'B4:E9', ], 'Single Cell' => [ [ [2, 4], [2, 4], ], 'B4', ], 'Column Range' => [ [ [2, 1], [3, 1048576], ], 'B:C', ], 'Single Column Range' => [ [ [2, 1], [2, 1048576], ], 'B:B', ], 'Row Range' => [ [ [1, 2], [16384, 3], ], '2:3', ], 'Single Row Range' => [ [ [1, 2], [16384, 2], ], '2:2', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellAbsoluteCoordinate.php
tests/data/CellAbsoluteCoordinate.php
<?php declare(strict_types=1); return [ [ '$A$1', 'A1', ], [ '$A$12', 'A12', ], [ '$J$1', 'J1', ], [ '$J$20', 'J20', ], [ '$AI$1', 'AI1', ], [ '$AI$2012', 'AI2012', ], [ '\'Worksheet1\'!$AI$256', '\'Worksheet1\'!AI256', ], [ 'Worksheet1!$AI$256', 'Worksheet1!AI256', ], [ '\'Data Worksheet\'!$AI$256', '\'Data Worksheet\'!AI256', ], [ '\'Worksheet1\'!$AI$256', '\'Worksheet1\'!$AI256', ], [ '\'Work!sheet1!\'!$AI$256', '\'Work!sheet1!\'!AI$256', ], [ '\'Work!sheet1!\'!$AI$256', '\'Work!sheet1!\'!$AI$256', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/ReferenceHelperFormulaUpdates.php
tests/data/ReferenceHelperFormulaUpdates.php
<?php declare(strict_types=1); return [ [ '=IF(A$1=0,0,A1/A$1)', 1, 0, '2021', '=IF(B$1=0,0,B1/B$1)', ], [ '=IF($A1=0,0,A1/$A1)', 0, 1, '2021', '=IF($A2=0,0,A2/$A2)', ], [ '=SUM(C3:E5)', -2, -2, '2020', '=SUM(A1:C3)', ], 'column range' => [ '=SUM(B:C)', 2, 0, '2020', '=SUM(D:E)', ], 'column range with absolute' => [ '=SUM($B:C)', 2, 0, '2020', '=SUM($B:E)', ], 'row range' => [ '=SUM(2:3)', 0, 2, '2020', '=SUM(4:5)', ], 'row range with absolute' => [ '=SUM($2:3)', 0, 2, '2020', '=SUM($2:5)', ], [ '=SUM(2020!C3:E5,2019!C3:E5)', -2, -2, '2020', '=SUM(2020!A1:C3,2019!C3:E5)', ], [ '=SUM(2020!3:5,2019!3:5)', -2, -2, '2020', '=SUM(2020!1:3,2019!3:5)', ], [ '=SUM(2020!C:E,2019!C:E)', -2, -2, '2020', '=SUM(2020!A:C,2019!C:E)', ], [ "=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B1)-1))", 2, 2, '2019', "=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B3)-1))", ], [ "=IF('2020'!B$1=\"\",\"-\",(('2020'!B$1/'2019'!B$1)-1))", 2, 2, '2019', "=IF('2020'!B\$1=\"\",\"-\",(('2020'!B\$1/'2019'!D\$1)-1))", ], [ "=IF('2020'!Z$1=\"\",\"-\",(('2020'!Z$1/'2019'!Z$1)-1))", 2, 2, '2019', "=IF('2020'!Z\$1=\"\",\"-\",(('2020'!Z\$1/'2019'!AB\$1)-1))", ], [ "=IF('2020'!\$B1=\"\",\"-\",(('2020'!\$B1/'2019'!\$B1)-1))", 2, 2, '2020', "=IF('2020'!\$B3=\"\",\"-\",(('2020'!\$B3/'2019'!\$B1)-1))", ], [ "=IF('2020'!B$1=\"\",\"-\",(('2020'!B$1/'2019'!B$1)-1))", 2, 2, '2020', "=IF('2020'!D\$1=\"\",\"-\",(('2020'!D\$1/'2019'!B\$1)-1))", ], [ "=IF('2020'!Z$1=\"\",\"-\",(('2020'!Z$1/'2019'!Z$1)-1))", 2, 2, '2020', "=IF('2020'!AB\$1=\"\",\"-\",(('2020'!AB\$1/'2019'!Z\$1)-1))", ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/CellSplitRange.php
tests/data/CellSplitRange.php
<?php declare(strict_types=1); return [ [ [ [ 'B4', 'E9', ], ], 'B4:E9', ], [ [ 'B4', ], 'B4', ], [ [ [ 'B4', 'E9', ], [ 'H2', 'O11', ], ], 'B4:E9,H2:O11', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/Style/NumberFormatDates.php
tests/data/Style/NumberFormatDates.php
<?php declare(strict_types=1); return [ [ '19-12-1960 01:30:00', 22269.0625, 'dd-mm-yyyy hh:mm:ss', ], 'Oasis uses upper-case' => [ '12/19/1960 01:30:00', 22269.0625, 'MM/DD/YYYY HH:MM:SS', ], 'plaintext escaped with backslash' => [ '1960-12-19T01:30:00', 22269.0625, 'yyyy-mm-dd\Thh:mm:ss', ], 'plaintext in quotes' => [ '1960-12-19T01:30:00 Z', 22269.0625, 'yyyy-mm-dd"T"hh:mm:ss \Z', ], 'quoted formatting characters' => [ 'y-m-d 1960-12-19 h:m:s 01:30:00', 22269.0625, '"y-m-d" yyyy-mm-dd "h:m:s" hh:mm:ss', ], 'quoted formatting non-ascii characters' => [ '§1960-12-19', 22269.0625, '"§"yyyy-mm-dd', ], 'fractional/decimal time' => [ '2023/02/28 0:00:00.000', 44985, 'yyyy/mm/dd\ h:mm:ss.000', ], [ '2023/02/28 07:35:02.400', 44985.316, 'yyyy/mm/dd\ hh:mm:ss.000', ], [ '2023/02/28 07:35:13.067', 44985.316123456, 'yyyy/mm/dd\ hh:mm:ss.000', ], [ '2023/02/28 07:35:13.07', 44985.316123456, 'yyyy/mm/dd\ hh:mm:ss.00', ], [ '2023/02/28 07:35:13.1', 44985.316123456, 'yyyy/mm/dd\ hh:mm:ss.0', ], [ '07:35:00 AM', 43270.315972222, 'hh:mm:ss\ AM/PM', ], [ '02:29:00 PM', 43270.603472222, 'hh:mm:ss\ AM/PM', ], [ '8/20/2018', 43332, '[$-409]m/d/yyyy', ], [ '8/20/2018', 43332, '[$-1010409]m/d/yyyy', ], [ '27:15', 1.1354166666667, '[h]:mm', ], [ '19331018', 12345.6789, '[DBNum4][$-804]yyyymmdd;@', ], // Technically should be 19331018 [ '19331018', 12345.6789, '[DBNum3][$-zh-CN]yyyymmdd;@', ], 'hour with leading 0 and minute' => [ '03:36', 1.15, 'hh:mm', ], 'hour without leading 0 and minute' => [ '3:36', 1.15, 'h:mm', ], 'hour truncated not rounded' => [ '27', 1.15, '[hh]', ], 'interval hour > 10 so no need for leading 0 and minute' => [ '27:36', 1.15, '[hh]:mm', ], 'interval hour > 10 no leading 0 and minute' => [ '27:36', 1.15, '[h]:mm', ], 'interval hour with leading 0 and minute' => [ '03:36', 0.15, '[hh]:mm', ], 'interval hour no leading 0 and minute' => [ '3:36', 0.15, '[h]:mm', ], 'interval hours > 100 and minutes no need for leading 0' => [ '123:36', 5.15, '[hh]:mm', ], 'interval hours > 100 and minutes no leading 0' => [ '123:36', 5.15, '[h]:mm', ], 'interval minutes > 10 no need for leading 0' => [ '1656', 1.15, '[mm]', ], 'interval minutes > 10 no leading 0' => [ '1656', 1.15, '[m]', ], 'interval minutes < 10 leading 0' => [ '07', 0.005, '[mm]', ], 'interval minutes < 10 no leading 0' => [ '7', 0.005, '[m]', ], 'interval minutes and seconds' => [ '07:12', 0.005, '[mm]:ss', ], 'interval seconds' => [ '432', 0.005, '[ss]', ], 'interval seconds rounded up leading 0' => [ '09', 0.0001, '[ss]', ], 'interval seconds rounded up no leading 0' => [ '9', 0.0001, '[s]', ], 'interval seconds rounded down' => [ '6', 0.00007, '[s]', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/Style/NumberFormat.php
tests/data/Style/NumberFormat.php
<?php declare(strict_types=1); use PhpOffice\PhpSpreadsheet\Style\NumberFormat; // value, format, result return [ [ '0.0', 0.0, '0.0', ], [ '0', 0.0, '0', ], [ '0.0', 0, '0.0', ], [ '0', 0, '0', ], [ '000', 0, '##0', ], [ '12.00', 12, '#.0#', ], [ '0.1', 0.10000000000000001, '0.0', ], [ '0', 0.10000000000000001, '0', ], [ '5.556', 5.5555000000000003, '0.###', ], [ '5.556', 5.5555000000000003, '0.0##', ], [ '5.556', 5.5555000000000003, '0.00#', ], [ '12 345.67', 12345.67, '#\ ##0.00', ], [ '1234 567.00', 1234567.00, '#\ ##0.00', ], [ '5.556', 5.5555000000000003, '0.000', ], [ '5.5555', 5.5555000000000003, '0.0000', ], [ '12,345.68', 12345.678900000001, '#,##0.00', ], [ '12,345.679', 12345.678900000001, '#,##0.000', ], [ '12.34 kg', 12.34, '0.00 "kg"', ], [ 'kg 12.34', 12.34, '"kg" 0.00', ], [ '12.34 kg.', 12.34, '0.00 "kg."', ], [ 'kg. 12.34', 12.34, '"kg." 0.00', ], [ '£ 12,345.68', 12345.678900000001, '£ #,##0.00', ], [ '$ 12,345.679', 12345.678900000001, '$ #,##0.000', ], [ '12,345.679 €', 12345.678900000001, '#,##0.000\ [$€-1]', ], [ '12,345.679 $', 12345.678900000001, '#,##0.000\ [$]', ], 'Spacing Character' => [ '826.00 €', 826, '#,##0.00 __€', ], [ '5.68', 5.6788999999999996, '#,##0.00', ], [ '12,000', 12000, '#,###', ], [ '12', 12000, '#,', ], // Scaling test [ '12.2', 12200000, '0.0,,', ], // Percentage [ '12%', 0.12, '0%', ], [ '8%', 0.080000000000000002, '0%', ], [ '80%', 0.80000000000000004, '0%', ], [ '280%', 2.7999999999999998, '0%', ], [ '$125.74 Surplus', 125.73999999999999, '$0.00" Surplus";$-0.00" Shortage"', ], [ '$-125.74 Shortage', -125.73999999999999, '$0.00" Surplus";$-0.00" Shortage"', ], [ '$125.74 Shortage', -125.73999999999999, '$0.00" Surplus";$0.00" Shortage"', ], [ '12%', 0.123, '0%', ], [ '-9.1%', -0.091, '0.0%', ], [ '-99.1%', -0.991, '0.0%', ], [ '-9.10%', -0.091, '0.00%', ], [ '-99.10%', -0.991, '0.00%', ], [ '10%', 0.1, '0%', ], [ '10.0%', 0.1, '0.0%', ], [ '-12%', -0.123, '0%', ], [ '12.3 %', 0.123, '0.?? %', ], [ '12.35 %', 0.12345, '0.?? %', ], [ '12.345 %', 0.12345, '0.00?? %', ], [ '12.3457 %', 0.123456789, '0.00?? %', ], [ '-12.3 %', -0.123, '0.?? %', ], [ '12.30 %age', 0.123, '0.00 %"age"', ], [ '-12.30 %age', -0.123, '0.00 %"age"', ], [ '12.30%', 0.123, '0.00%;(0.00%)', ], [ '(12.30%)', -0.123, '0.00%;(0.00%)', ], [ '12.30% ', 0.123, '0.00%_;( 0.00% )', ], [ '( 12.30% )', -0.123, '_(0.00%_;( 0.00% )', ], // Complex formats [ '(001) 2-3456-789', 123456789, '(000) 0-0000-000', ], [ '0 (+00) 0123 45 67 89', 123456789, '0 (+00) 0000 00 00 00', ], [ '002-01-0035-7', 20100357, '000-00-0000-0', ], [ '002-01-00.35-7', 20100.357, '000-00-00.00-0', ], [ '002.01.0035.7', 20100357, '000\.00\.0000\.0', ], [ '002.01.00.35.7', 20100.357, '000\.00\.00.00\.0', ], [ '002.01.00.35.70', 20100.357, '000\.00\.00.00\.00', ], [ '12345:67:89', 123456789, '0000:00:00', ], [ '-12345:67:89', -123456789, '0000:00:00', ], [ '12345:67.89', 1234567.8899999999, '0000:00.00', ], [ '-12345:67.89', -1234567.8899999999, '0000:00.00', ], [ '18.952', 18.952, '[$-409]General', ], [ '9.98', 9.98, '[$-409]#,##0.00;-#,##0.00', ], [ '18.952', 18.952, '[$-1010409]General', ], [ '9.98', 9.98, '[$-1010409]#,##0.00;-#,##0.00', ], [ ' $ 23.06 ', 23.0597, '_("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)', ], [ ' € (13.03)', -13.0316, '_("€"* #,##0.00_);_("€"* \(#,##0.00\);_("€"* "-"??_);_(@_)', ], [ ' € 11.70 ', 11.7, '_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-', ], [ '-€ 12.14 ', -12.14, '_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-', ], [ ' € - ', 0, '_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-', ], [ 'test', 'test', '_-€* #,##0.00_-;"-€"* #,##0.00_-;_-€* -??_-;_-@_-', ], // String masks (ie. @) [ 'World', 'World', '@', ], [ 'Hello World', 'World', 'Hello @', ], [ 'Hello World', 'World', '"Hello "@', ], [ 'Meet me @ The Boathouse @ 16:30', 'The Boathouse', '"Meet me @ "@" @ 16:30"', ], // Named colours // Simple color [ '12345', 12345, '[Green]General', ], [ '12345', 12345, '[GrEeN]General', ], [ '-70', -70, '#,##0;[Red]-#,##0', ], [ '-12,345', -12345, '#,##0;[Red]-#,##0', ], // Multiple colors [ '12345', 12345, '[Blue]0;[Red]0-', ], [ '12345-', -12345, '[BLUE]0;[red]0-', ], [ '12345-', -12345, '[blue]0;[RED]0-', ], // Multiple colors with text substitution [ 'Positive', 12, '[Green]"Positive";[Red]"Negative";[Blue]"Zero"', ], [ 'Zero', 0, '[Green]"Positive";[Red]"Negative";[Blue]"Zero"', ], [ 'Negative', -2, '[Green]"Positive";[Red]"Negative";[Blue]"Zero"', ], // Colour palette index [ '+710', 710, '[color 10]+#,##0;[color 12]-#,##0', ], [ '-710', -710, '[color 10]+#,##0;[color 12]-#,##0', ], // Colour palette index [ '+710', 710, '[color10]+#,##0;[color12]-#,##0', ], [ '-710', -710, '[color10]+#,##0;[color12]-#,##0', ], [ '-710', -710, '[color01]+#,##0;[color02]-#,##0', ], [ '-710', -710, '[color08]+#,##0;[color09]-#,##0', ], [ '-710', -710, '[color55]+#,##0;[color56]-#,##0', ], // Value break points [ '<=3500 red', 3500, '[Green][=17]"=17 green";[Red][<=3500]"<=3500 red";[Blue]"Zero"', ], [ '=17 green', 17, '[Green][=17]"=17 green";[Red][<=3500]"<=3500 red";[Blue]"Zero"', ], [ '<>25 green', 17, '[Green][<>25]"<>25 green";[Red]"else red"', ], [ 'else red', 25, '[Green][<>25]"<>25 green";[Red]"else red"', ], // Leading/trailing quotes in mask [ '$12.34 ', 12.34, '$#,##0.00_;[RED]"($"#,##0.00")"', ], [ '($12.34)', -12.34, '$#,##0.00_;[RED]"($"#,##0.00")"', ], [ 'pfx. 25.00', 25, '"pfx." 0.00;"pfx." -0.00;"pfx." 0.00;', ], [ 'pfx. 25.20', 25.2, '"pfx." 0.00;"pfx." -0.00;"pfx." 0.00;', ], [ 'pfx. -25.20', -25.2, '"pfx." 0.00;"pfx." -0.00;"pfx." 0.00;', ], [ 'pfx. 25.26', 25.255555555555555, '"pfx." 0.00;"pfx." -0.00;"pfx." 0.00;', ], [ '1', '1.000', NumberFormat::FORMAT_NUMBER, ], [ '-1', '-1.000', NumberFormat::FORMAT_NUMBER, ], [ '1', '1', NumberFormat::FORMAT_NUMBER, ], [ '-1', '-1', NumberFormat::FORMAT_NUMBER, ], [ '0', '0', NumberFormat::FORMAT_NUMBER, ], [ '0', '-0', NumberFormat::FORMAT_NUMBER, ], [ '1', '1.1', NumberFormat::FORMAT_NUMBER, ], [ '1', '1.4', NumberFormat::FORMAT_NUMBER, ], [ '2', '1.5', NumberFormat::FORMAT_NUMBER, ], [ '2', '1.9', NumberFormat::FORMAT_NUMBER, ], [ '1.0', '1.000', NumberFormat::FORMAT_NUMBER_0, ], [ '-1.0', '-1.000', NumberFormat::FORMAT_NUMBER_0, ], [ '1.0', '1', NumberFormat::FORMAT_NUMBER_0, ], [ '-1.0', '-1', NumberFormat::FORMAT_NUMBER_0, ], [ '1.0', '1', NumberFormat::FORMAT_NUMBER_0, ], [ '0.0', '0', NumberFormat::FORMAT_NUMBER_0, ], [ '0.0', '-0', NumberFormat::FORMAT_NUMBER_0, ], [ '1.1', '1.11', NumberFormat::FORMAT_NUMBER_0, ], [ '1.1', '1.14', NumberFormat::FORMAT_NUMBER_0, ], [ '1.2', '1.15', NumberFormat::FORMAT_NUMBER_0, ], [ '1.2', '1.19', NumberFormat::FORMAT_NUMBER_0, ], [ '0.00', '0', NumberFormat::FORMAT_NUMBER_00, ], [ '1.00', '1', NumberFormat::FORMAT_NUMBER_00, ], [ '1.11', '1.111', NumberFormat::FORMAT_NUMBER_00, ], [ '1.11', '1.114', NumberFormat::FORMAT_NUMBER_00, ], [ '1.12', '1.115', NumberFormat::FORMAT_NUMBER_00, ], [ '1.12', '1.119', NumberFormat::FORMAT_NUMBER_00, ], [ '0.00', '-0', NumberFormat::FORMAT_NUMBER_00, ], [ '-1.00', '-1', NumberFormat::FORMAT_NUMBER_00, ], [ '-1.11', '-1.111', NumberFormat::FORMAT_NUMBER_00, ], [ '-1.11', '-1.114', NumberFormat::FORMAT_NUMBER_00, ], [ '-1.12', '-1.115', NumberFormat::FORMAT_NUMBER_00, ], [ '-1.12', '-1.119', NumberFormat::FORMAT_NUMBER_00, ], [ '0.00', '0', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '1,000.00', '1000', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '1,111.11', '1111.111', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '1,111.11', '1111.114', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '1,111.12', '1111.115', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '1,111.12', '1111.119', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '0.00', '-0', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '-1,111.00', '-1111', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '-1,111.11', '-1111.111', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '-1,111.11', '-1111.114', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '-1,111.12', '-1111.115', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '-1,111.12', '-1111.119', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED1, ], [ '0.00 ', '0', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '1,000.00 ', '1000', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '1,111.11 ', '1111.111', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '1,111.11 ', '1111.114', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '1,111.12 ', '1111.115', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '1,111.12 ', '1111.119', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '0.00 ', '-0', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '-1,111.00 ', '-1111', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '-1,111.11 ', '-1111.111', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '-1,111.11 ', '-1111.114', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '-1,111.12 ', '-1111.115', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '-1,111.12 ', '-1111.119', NumberFormat::FORMAT_NUMBER_COMMA_SEPARATED2, ], [ '0%', '0', NumberFormat::FORMAT_PERCENTAGE, ], [ '1%', '0.01', NumberFormat::FORMAT_PERCENTAGE, ], [ '1%', '0.011', NumberFormat::FORMAT_PERCENTAGE, ], [ '1%', '0.014', NumberFormat::FORMAT_PERCENTAGE, ], [ '2%', '0.015', NumberFormat::FORMAT_PERCENTAGE, ], [ '2%', '0.019', NumberFormat::FORMAT_PERCENTAGE, ], [ '0%', '-0', NumberFormat::FORMAT_PERCENTAGE, ], [ '-1%', '-0.01', NumberFormat::FORMAT_PERCENTAGE, ], [ '-1%', '-0.011', NumberFormat::FORMAT_PERCENTAGE, ], [ '-1%', '-0.014', NumberFormat::FORMAT_PERCENTAGE, ], [ '-2%', '-0.015', NumberFormat::FORMAT_PERCENTAGE, ], [ '-2%', '-0.019', NumberFormat::FORMAT_PERCENTAGE, ], [ '0.0%', '0', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '1.0%', '0.01', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '1.1%', '0.011', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '1.1%', '0.0114', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '1.2%', '0.0115', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '1.2%', '0.0119', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '0.0%', '-0', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '-1.0%', '-0.01', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '-1.1%', '-0.011', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '-1.1%', '-0.0114', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '-1.2%', '-0.0115', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '-1.2%', '-0.0119', NumberFormat::FORMAT_PERCENTAGE_0, ], [ '0.00%', '0', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '1.00%', '0.01', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '1.11%', '0.0111', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '1.11%', '0.01114', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '1.12%', '0.01115', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '1.12%', '0.01119', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '0.00%', '-0', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '-1.00%', '-0.01', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '-1.11%', '-0.0111', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '-1.11%', '-0.01114', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '-1.12%', '-0.01115', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '-1.12%', '-0.01119', NumberFormat::FORMAT_PERCENTAGE_00, ], [ '$0.00 ', '0', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,000.00 ', '1000', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,111.11 ', '1111.111', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,111.11 ', '1111.114', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,111.12 ', '1111.115', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,111.12 ', '1111.119', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$0.00 ', '-0', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.00 ', '-1111', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.11 ', '-1111.111', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.11 ', '-1111.114', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.12 ', '-1111.115', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.12 ', '-1111.119', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$0 ', '0', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,000 ', '1000', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,111 ', '1111.1', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,111 ', '1111.4', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,112 ', '1111.5', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,112 ', '1111.9', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$0 ', '-0', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,111 ', '-1111', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,111 ', '-1111.1', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,111 ', '-1111.4', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,112 ', '-1111.5', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,112 ', '-1111.9', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$0.00 ', '0', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,000.00 ', '1000', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,111.11 ', '1111.111', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,111.11 ', '1111.114', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,111.12 ', '1111.115', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$1,111.12 ', '1111.119', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$0.00 ', '-0', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.00 ', '-1111', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.11 ', '-1111.111', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.11 ', '-1111.114', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.12 ', '-1111.115', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$-1,111.12 ', '-1111.119', NumberFormat::FORMAT_CURRENCY_USD, ], [ '$0 ', '0', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,000 ', '1000', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,111 ', '1111.1', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,111 ', '1111.4', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,112 ', '1111.5', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$1,112 ', '1111.9', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$0 ', '-0', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,111 ', '-1111', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,111 ', '-1111.1', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,111 ', '-1111.4', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,112 ', '-1111.5', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '$-1,112 ', '-1111.9', NumberFormat::FORMAT_CURRENCY_USD_INTEGER, ], [ '0.00 €', '0', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '1,000.00 €', '1000', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '1,111.11 €', '1111.111', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '1,111.11 €', '1111.114', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '1,111.12 €', '1111.115', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '1,111.12 €', '1111.119', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '0.00 €', '-0', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '-1,111.00 €', '-1111', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '-1,111.11 €', '-1111.111', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '-1,111.11 €', '-1111.114', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '-1,111.12 €', '-1111.115', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '-1,111.12 €', '-1111.119', NumberFormat::FORMAT_CURRENCY_EUR, ], [ '0 €', '0', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '1,000 €', '1000', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '1,111 €', '1111.1', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '1,111 €', '1111.4', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '1,112 €', '1111.5', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '1,112 €', '1111.9', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '0 €', '-0', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '-1,111 €', '-1111', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '-1,111 €', '-1111.1', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '-1,111 €', '-1111.4', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '-1,112 €', '-1111.5', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ '-1,112 €', '-1111.9', NumberFormat::FORMAT_CURRENCY_EUR_INTEGER, ], [ ' $ - ', '0', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ 1,000.00 ', '1000', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ 1,111.11 ', '1111.111', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ 1,111.11 ', '1111.114', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ 1,111.12 ', '1111.115', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ 1,111.12 ', '1111.119', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ - ', '-0', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ (1,111.00)', '-1111', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ (1,111.11)', '-1111.111', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ (1,111.11)', '-1111.114', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ (1,111.12)', '-1111.115', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' $ (1,111.12)', '-1111.119', NumberFormat::FORMAT_ACCOUNTING_USD, ], [ ' € - ', '0', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € 1,000.00 ', '1000', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € 1,111.11 ', '1111.111', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € 1,111.11 ', '1111.114', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € 1,111.12 ', '1111.115', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € 1,111.12 ', '1111.119', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € - ', '-0', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € (1,111.00)', '-1111', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € (1,111.11)', '-1111.111', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € (1,111.11)', '-1111.114', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € (1,111.12)', '-1111.115', NumberFormat::FORMAT_ACCOUNTING_EUR, ], [ ' € (1,111.12)', '-1111.119', NumberFormat::FORMAT_ACCOUNTING_EUR, ], 'issue 1929' => ['(79.3%)', -0.793, '#,##0.0%;(#,##0.0%)'], 'percent without leading 0' => ['6.2%', 0.062, '##.0%'], 'percent with leading 0' => ['06.2%', 0.062, '00.0%'], 'percent lead0 no decimal' => ['06%', 0.062, '00%'], 'percent nolead0 no decimal' => ['6%', 0.062, '##%'], 'scientific small complex mask discard all decimals' => ['0 000.0', 1e-17, '0 000.0'], 'scientific small complex mask keep some decimals' => ['-0 000.000027', -2.7e-5, '0 000.000000'], 'scientific small complex mask keep some decimals trailing zero' => ['-0 000.000040', -4e-5, '0 000.000000'], 'scientific large complex mask' => ['92' . str_repeat('0', 13) . ' 000.0', 9.2e17, '0 000.0'], 'scientific very large complex mask PhpSpreadsheet does not match Excel' => ['1' . str_repeat('0', 18), 1e18, '0 000.0'], 'scientific even larger complex mask PhpSpreadsheet does not match Excel' => ['43' . str_repeat('0', 89), 4.3e90, '0 000.0'], 'scientific many decimal positions' => ['000 0.000 01', 1e-5, '000 0.000 00'], 'round with scientific notation' => ['000 0.000 02', 1.6e-5, '000 0.000 00'], 'round with no decimals' => ['009 8', 97.7, '000 0'], 'round to 1 decimal' => ['009 7.2', 97.15, '000 0.0'], 'truncate with no decimals' => ['009 7', 97.3, '000 0'], 'truncate to 1 decimal' => ['009 7.1', 97.13, '000 0.0'], 'scientific many decimal positions truncated' => ['000 0.000 00', 1e-7, '000 0.000 00'], 'scientific very many decimal positions truncated' => ['000 0.000 00', 1e-17, '000 0.000 00'], [ '€ 1,111.12 ', '1111.119', '[$€-nl_NL]_(#,##0.00_);[$€-nl_NL] (#,##0.00)', ], [ '€ (1,111.12)', '-1111.119', '[$€-nl_NL]_(#,##0.00_);[$€-nl_NL] (#,##0.00)', ], [ '€ 1,111.12 ', '1111.119', '[$€-en_US]_(#,##0.00_);[$€-en_US] (#,##0.00)', ], [ '-1.2E+4', -12345.6789, '0.0E+00', ], [ '-1.23E+4', -12345.6789, '0.00E+00', ], [ '-1.235E+4', -12345.6789, '0.000E+00', ], [ 'Product SKU #12345', 12345, '"Product SKU #"0', ], [ 'Product SKU #12-345', 12345, '"Product SKU #"00-000', ], [ '€12,345.74 Surplus for Product #12-345', 12345.74, '[$€]#,##0.00" Surplus for Product #12-345";$-#,##0.00" Shortage for Product #12-345"', ], // Scaling [ '12,000', 12000, '#,###', ], [ '12', 12000, '#,', ], [ '0', 120, '#,', ], [ '0.12', 120, '#,.00', ], [ '12k', 12000, '#,k', ], [ '12.2', 12200000, '0.0,,', ], [ '12.2 M', 12200000, '0.0,, M', ], [ '1,025.13', 1025132.36, '#,###,.##', ], [ '.05', 50, '#.00,', ], [ '50.05', 50050, '#.00,', ], [ '555.50', 555500, '#.00,', ], [ '.56', 555500, '#.00,,', ], // decimal placement [ ' 44.398', 44.398, '???.???', ], [ '102.65 ', 102.65, '???.???', ], [ ' 2.8 ', 2.8, '???.???', ], [ ' 3', 2.8, '???', ], [ '12,345', 12345, '?,???', ], [ '123', 123, '?,???', ], [ '$.50', 0.5, '$?.00', ], [ 'Part Cost $.50', 0.5, 'Part Cost $?.00', ], // Empty Section [ '', -12345.6789, '#,##0.00;', ], [ '', -12345.6789, '#,##0.00;;"---"', ], 'issue 4124' => ['1 HUF', 1, '#,##0_-[$HUF]'], 'issue 4242 General with dollar sign' => [ 'General $200 - 200', // expected result 'General $200 - 200', // cell contents NumberFormat::FORMAT_GENERAL, // cell style ], 'issue 4242 Text with dollar sign' => [ 'Text $200 - 200', 'Text $200 - 200', NumberFormat::FORMAT_TEXT, ], 'issue 4242 Text with quotes, format without' => [ '"Hello" she said and "Hello" I replied', '"Hello" she said and "Hello" I replied', NumberFormat::FORMAT_TEXT, ], 'issue 4242 Format with quotes, text without' => [ 'Text: $200 - 200', '$200 - 200', '"Text: "' . NumberFormat::FORMAT_TEXT, ], 'issue 4242 single quote mark' => [ '"', '"', '@', ], 'issue 4242 dollar sign' => [ '$100', '$100', '@', ], 'issue 4242 repeat unquoted at signs' => [ 'xy xy xy', 'xy', '@ @ @', ], 'issue 4242 quotes in format and text' => [ 'Text: "Hooray" for me', '"Hooray" for me', '"Text: "' . NumberFormat::FORMAT_TEXT, ], 'issue 4242 escaped quote in format' => [ '"Hello"', 'Hello', '\"@\"', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/Style/NumberFormatFractions.php
tests/data/Style/NumberFormatFractions.php
<?php declare(strict_types=1); // value, format, result return [ // Fraction [ '5 1/4', 5.25, '# ???/???', ], [ '5 2/8', 5.25, '# ???/8', ], [ '5 4/16', 5.25, '# ???/16', ], [ '5 1/4', 5.25, '# ##0/000', ], [ '5 1/4', 5.25, '# ##0/###', ], [ '5 3/10', 5.2999999999999998, '# ???/???', ], // Vulgar Fraction [ '21/4', 5.25, '???/???', ], [ '0 3/4', 0.75, '0??/???', ], [ '3/4', 0.75, '#??/???', ], [ ' 3/4', 0.75, '? ??/???', ], [ ' 3/4', '0.75000', '? ??/???', ], [ '5 1/16', 5.0625, '? ??/???', ], [ '- 5/8', -0.625, '? ??/???', ], [ '0', 0, '? ??/???', ], [ '0', '0.000', '? ??/???', ], [ '-16', '-016.0', '? ??/???', ], // Fixed base Fraction [ '5 1/2', 5.25, '# ???/2', ], [ '5 1/4', 5.25, '# ???/4', ], [ '5 2/8', 5.25, '# ???/8', ], [ '5 3/10', 5.25, '# ???/10', ], [ '5 25/100', 5.25, '# ???/100', ], [ '525/100', 5.25, '??/100', ], [ '525/100', 5.25, '???/100', ], [ '2 2/3', 2.65, '# ???/3', ], [ '2 3/4', 2.65, '# ???/4', ], [ '2 4/6', 2.65, '# ???/6', ], [ '2 8/12', 2.65, '# ???/12', ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/Style/Color/ColorGetBlue.php
tests/data/Style/Color/ColorGetBlue.php
<?php declare(strict_types=1); return [ // RGBA (hex) [ 'CC', 'FFAABBCC', ], // RGBA (decimal) [ 204, 'FFAABBCC', false, ], // RGB (hex) [ 'CC', 'AABBCC', ], // RGB (decimal) [ 204, 'AABBCC', false, ], [ '00', 'FFFF00', ], [ 0, 'FFFF00', false, ], 'invalid hex' => ['00', 'AABBDX'], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/Style/Color/ColorGetGreen.php
tests/data/Style/Color/ColorGetGreen.php
<?php declare(strict_types=1); return [ // RGBA (hex) [ 'BB', 'FFAABBCC', ], // RGBA (decimal) [ 187, 'FFAABBCC', false, ], // RGB (hex) [ 'BB', 'AABBCC', ], // RGB (decimal) [ 187, 'AABBCC', false, ], [ '00', 'FF00FF', ], [ 0, 'FF00FF', false, ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false
PHPOffice/PhpSpreadsheet
https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/data/Style/Color/ColorGetRed.php
tests/data/Style/Color/ColorGetRed.php
<?php declare(strict_types=1); return [ // RGBA (hex) [ 'AA', 'FFAABBCC', ], // RGBA (decimal) [ 170, 'FFAABBCC', false, ], // RGB (hex) [ 'AA', 'AABBCC', ], // RGB (decimal) [ 170, 'AABBCC', false, ], [ '00', '00FFFF', ], [ 0, '00FFFF', false, ], ];
php
MIT
e33834b4ea2a02088becbb41fb8954d915b46b12
2026-01-04T15:02:44.305364Z
false