-
Notifications
You must be signed in to change notification settings - Fork 1
/
hyperlinks.php
49 lines (36 loc) · 1.83 KB
/
hyperlinks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* @see http://libxlsxwriter.github.io/hyperlinks_8c-example.html
* @noinspection PhpUnhandledExceptionInspection
*/
use FFILibXlsxWriter\FFILibXlsxWriter;
use FFILibXlsxWriter\Enums\Color;
use FFILibXlsxWriter\Enums\Underline;
use FFILibXlsxWriter\Workbook;
require_once __DIR__ . '/../vendor/autoload.php';
FFILibXlsxWriter::init();
$workbook = new Workbook(__DIR__ . '/output/hyperlinks.xlsx');
$worksheet = $workbook->addWorksheet();
/* Get the default url format (used in the overwriting examples below). */
$urlFormat = $workbook->getDefaultUrlFormat();
/* Create a user defined link format. */
$redFormat = $workbook->addFormat();
$redFormat->setUnderline(Underline::SINGLE);
$redFormat->setFontColor(Color::RED);
/* Widen the first column to make the text clearer. */
$worksheet->setColumn([0, 0], 30, null);
/* Write a hyperlink. A default blue underline will be used if the format is null. */
$worksheet->writeUrl([0, 0], 'https://github.com/kluevandrew/php-ffi-libxlsxwriter', null);
/* Write a hyperlink but overwrite the displayed string. Note, we need to
* specify the format for the string to match the default hyperlink. */
$worksheet->writeUrl([2, 0], "https://github.com/kluevandrew/php-ffi-libxlsxwriter", null);
$worksheet->writeString([2, 0], "Read the documentation.", $urlFormat);
/* Write a hyperlink with a different format. */
$worksheet->writeUrl([4, 0], "https://github.com/kluevandrew/php-ffi-libxlsxwriter", $redFormat);
/* Write a mail hyperlink. */
$worksheet->writeUrl([6, 0], "mailto:kluev.andrew@gmail.com", null);
/* Write a mail hyperlink and overwrite the displayed string. We again
* specify the format for the string to match the default hyperlink. */
$worksheet->writeUrl([8, 0], "mailto:kluev.andrew@gmail.com", null);
$worksheet->writeString([8, 0], "Drop me a line.", $urlFormat);
$workbook->close();