2019-11-10 21:49:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Cell;
|
|
|
|
|
2020-01-03 22:29:53 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Exception;
|
2019-11-10 21:49:00 +00:00
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class CellTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider providerSetValueExplicit
|
|
|
|
*
|
|
|
|
* @param mixed $expected
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetValueExplicit($expected, $value, string $dataType): void
|
2019-11-10 21:49:00 +00:00
|
|
|
{
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
$cell = $spreadsheet->getActiveSheet()->getCell('A1');
|
|
|
|
$cell->setValueExplicit($value, $dataType);
|
|
|
|
|
|
|
|
self::assertSame($expected, $cell->getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerSetValueExplicit()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Cell/SetValueExplicit.php';
|
2019-11-10 21:49:00 +00:00
|
|
|
}
|
2020-01-03 22:29:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerSetValueExplicitException
|
|
|
|
*
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testSetValueExplicitException($value, string $dataType): void
|
2020-01-03 22:29:53 +00:00
|
|
|
{
|
|
|
|
$this->expectException(Exception::class);
|
|
|
|
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
$cell = $spreadsheet->getActiveSheet()->getCell('A1');
|
|
|
|
$cell->setValueExplicit($value, $dataType);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerSetValueExplicitException()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Cell/SetValueExplicitException.php';
|
2020-01-03 22:29:53 +00:00
|
|
|
}
|
2020-06-19 18:57:20 +00:00
|
|
|
|
|
|
|
public function testNoChangeToActiveSheet(): void
|
|
|
|
{
|
|
|
|
$spreadsheet = new Spreadsheet();
|
|
|
|
$sheet1 = $spreadsheet->getActiveSheet();
|
|
|
|
$sheet1->setTitle('Sheet 1');
|
|
|
|
$sheet3 = $spreadsheet->createSheet();
|
|
|
|
$sheet3->setTitle('Sheet 3');
|
|
|
|
$sheet1->setCellValue('C1', 123);
|
|
|
|
$sheet1->setCellValue('D1', 124);
|
|
|
|
$sheet3->setCellValue('A1', "='Sheet 1'!C1+'Sheet 1'!D1");
|
|
|
|
$sheet1->setCellValue('A1', "='Sheet 3'!A1");
|
|
|
|
$cell = 'A1';
|
|
|
|
$spreadsheet->setActiveSheetIndex(0);
|
|
|
|
self::assertEquals(0, $spreadsheet->getActiveSheetIndex());
|
|
|
|
$value = $spreadsheet->getActiveSheet()->getCell($cell)->getCalculatedValue();
|
|
|
|
self::assertEquals(0, $spreadsheet->getActiveSheetIndex());
|
|
|
|
self::assertEquals(247, $value);
|
|
|
|
}
|
2019-11-10 21:49:00 +00:00
|
|
|
}
|