mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 12:38:33 +00:00
7d0f2ad706
Writer/Xlsx/Chart hard-codes a lot of output values. While nobody has reported a problem involving these, it makes sense to me to copy those values over from what Xlsx/Reader/Chart read, rather than hard-coding them. This involves adding some new properties to Chart and Layout, all, naturally, initialized to the values that we have been hard-coding. - Chart\date1904 - Chart\lang - Chart\pageMargins - Chart\pageSetup - Layout\bodyPr With one exception, I have not investigated any of the new properties in depth. That may come in time. The one I did look at is `date1904`. Chances are that it should match the equivalent spreadsheet setting, but it won't matter if there are no dates on your chart, and it often won't matter even if you do. It may well matter if you are using a `date axis`. While looking into that, it became apparent that some Shared Date conversions need to be a bit more flexible, specifying an optional `calendar` parameter rather than relying on the Spreadsheet `calendar` (which is not accessible while processing the chart) or the Shared\Date `calendar` (which is accessible).
43 lines
1.9 KiB
PHP
43 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Chart;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Chart\Chart;
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as XlsxWriter;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class CopyXmlTest extends TestCase
|
|
{
|
|
public function testCopyXml(): void
|
|
{
|
|
$infile = 'samples/templates/32readwriteRadarChart4.xlsx';
|
|
$reader = new XlsxReader();
|
|
$reader->setIncludeCharts(true);
|
|
$spreadsheet = $reader->load($infile);
|
|
$sheet = $spreadsheet->getSheetByNameOrThrow('Charts');
|
|
$charts = $sheet->getChartCollection();
|
|
self::assertCount(1, $charts);
|
|
$chart = $charts[0] ?? null;
|
|
self::assertInstanceOf(Chart::class, $chart);
|
|
|
|
$writer = new XlsxWriter($spreadsheet);
|
|
$writer->setIncludeCharts(true);
|
|
$writer = new XlsxWriter($spreadsheet);
|
|
$writer->setIncludeCharts(true);
|
|
$writerChart = new XlsxWriter\Chart($writer);
|
|
$data = $writerChart->writeChart($chart);
|
|
//echo $data;
|
|
self::assertStringContainsString('<c:date1904 val="0"/>', $data, 'From input even though same as default');
|
|
self::assertStringContainsString('<c:lang val="en-US"/>', $data, 'From input, different from default');
|
|
self::assertStringNotContainsString('view3D', $data, 'No empty view3D tag');
|
|
self::assertStringContainsString('<a:bodyPr vertOverflow="overflow" horzOverflow="overflow" wrap="square" lIns="38100" tIns="19050" rIns="38100" bIns="19050" anchor="ctr">', $data, 'A couple of extra attributes');
|
|
self::assertStringContainsString('<c:pageMargins b="0.75" l="0.25" r="0.25" t="0.75" header="0.3" footer="0.3"/>', $data, 'Some different values plus re-shuffling');
|
|
self::assertStringContainsString('<c:pageSetup paperSize="9" orientation="portrait"/>', $data, 'An extra attribute');
|
|
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|