1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as ReaderXlsx; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx as WriterXlsx; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class XlsxTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Test load Xlsx file without cell reference. |
15
|
|
|
*/ |
16
|
|
|
public function testLoadXlsxWithoutCellReference() |
17
|
|
|
{ |
18
|
|
|
$filename = './data/Reader/XLSX/without_cell_reference.xlsx'; |
19
|
|
|
$reader = new ReaderXlsx(); |
20
|
|
|
$reader->load($filename); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
View Code Duplication |
public function testFreezePane() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet'); |
26
|
|
|
|
27
|
|
|
$cellSplit = 'B2'; |
28
|
|
|
$topLeftCell = 'E5'; |
29
|
|
|
|
30
|
|
|
$spreadsheet = new Spreadsheet(); |
31
|
|
|
$active = $spreadsheet->getActiveSheet(); |
32
|
|
|
$active->freezePane($cellSplit, $topLeftCell); |
33
|
|
|
|
34
|
|
|
$writer = new WriterXlsx($spreadsheet); |
35
|
|
|
$writer->save($filename); |
|
|
|
|
36
|
|
|
|
37
|
|
|
// Read written file |
38
|
|
|
$reader = new ReaderXlsx(); |
39
|
|
|
$reloadedSpreadsheet = $reader->load($filename); |
|
|
|
|
40
|
|
|
$reloadedActive = $reloadedSpreadsheet->getActiveSheet(); |
41
|
|
|
$actualCellSplit = $reloadedActive->getFreezePane(); |
42
|
|
|
$actualTopLeftCell = $reloadedActive->getTopLeftCell(); |
43
|
|
|
|
44
|
|
|
self::assertSame($cellSplit, $actualCellSplit, 'should be able to set freeze pane'); |
45
|
|
|
self::assertSame($topLeftCell, $actualTopLeftCell, 'should be able to set the top left cell'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.