1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\Csv; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Csv; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
class HyperlinkTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function testVariableColumns(): void |
14
|
|
|
{ |
15
|
|
|
$spreadsheet = new Spreadsheet(); |
16
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
17
|
|
|
$sheet->setCellValue('A1', 3); |
18
|
|
|
$sheet->setCellValue('B1', 4); |
19
|
|
|
$sheet->setCellValue('C1', 5); |
20
|
|
|
$sheet->setCellValue('A2', 6); |
21
|
|
|
$sheet->setCellValue('B2', 'hyperlink'); |
22
|
|
|
$sheet->getCell('B2')->getHyperlink() |
23
|
|
|
->setUrl('http://www.example.com'); |
24
|
|
|
$sheet->setCellValue('C2', 8); |
25
|
|
|
|
26
|
|
|
$fh = fopen('php://memory', 'r+b'); |
27
|
|
|
self::assertNotFalse($fh); |
28
|
|
|
$writer = new Csv($spreadsheet); |
29
|
|
|
self::assertFalse($writer->getPreferHyperlinkToLabel()); |
30
|
|
|
$writer->setEnclosureRequired(false)->setLineEnding("\n"); |
31
|
|
|
$writer->save($fh); |
32
|
|
|
rewind($fh); |
33
|
|
|
self::assertSame( |
34
|
|
|
"3,4,5\n6,hyperlink,8\n", |
35
|
|
|
stream_get_contents($fh) |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
rewind($fh); |
39
|
|
|
$writer->setPreferHyperlinkToLabel(true); |
40
|
|
|
$writer->save($fh); |
41
|
|
|
rewind($fh); |
42
|
|
|
self::assertSame( |
43
|
|
|
"3,4,5\n6,http://www.example.com,8\n", |
44
|
|
|
stream_get_contents($fh) |
45
|
|
|
); |
46
|
|
|
fclose($fh); |
47
|
|
|
$spreadsheet->disconnectWorksheets(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|