mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-25 20:18:21 +00:00
075cecd268
See issue #2203. An undotted i uncrossed t. When using namespaces, need to call attributes() to access the attributes before trying to access them directly. Failure to do so in castToFormula caused problem for shared formulas. Surprisingly, this didn't show up in unit tests. Perhaps sharing the same formula between two cells isn't common. It did show up in Chart Samples. I've added a test. I was really inclined to merge this right away. Not to worry - I can control myself. It should be moved fairly quickly nevertheless.
42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Reader\IReader;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SharedFormulaTest extends TestCase
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
private static $testbook = 'samples/templates/32readwriteAreaChart1.xlsx';
|
|
|
|
public function testPreliminaries(): void
|
|
{
|
|
$file = 'zip://';
|
|
$file .= self::$testbook;
|
|
$file .= '#xl/worksheets/sheet1.xml';
|
|
$data = file_get_contents($file);
|
|
// confirm that file contains shared formula
|
|
if ($data === false) {
|
|
self::fail('Unable to read file');
|
|
} else {
|
|
self::assertStringContainsString('<c r="D6"><f t="shared" ca="1" si="0"/>', $data);
|
|
self::assertStringContainsString('<c r="E6"><f t="shared" ca="1" si="0"/>', $data);
|
|
}
|
|
}
|
|
|
|
public function testLoadSheetsXlsxChart(): void
|
|
{
|
|
$filename = self::$testbook;
|
|
$reader = IOFactory::createReader('Xlsx');
|
|
$spreadsheet = $reader->load($filename, IReader::LOAD_WITH_CHARTS);
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
self::assertSame('=(RANDBETWEEN(-50,250)+100)*10', $sheet->getCell('D6')->getValue());
|
|
self::assertSame('=(RANDBETWEEN(-50,250)+100)*10', $sheet->getCell('E6')->getValue());
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|