-
Notifications
You must be signed in to change notification settings - Fork 1
/
dates_and_times01.php
34 lines (26 loc) · 1.03 KB
/
dates_and_times01.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
<?php
/**
* @see http://libxlsxwriter.github.io/dates_and_times01_8c-example.html
* @noinspection PhpUnhandledExceptionInspection
*/
use FFILibXlsxWriter\FFILibXlsxWriter;
use FFILibXlsxWriter\Workbook;
require_once __DIR__ . '/../vendor/autoload.php';
FFILibXlsxWriter::init();
$workbook = new Workbook(__DIR__ . '/output/dates_and_times01.xlsx');
$worksheet = $workbook->addWorksheet();
/* A number to display as a date. */
$number = 41333.5;
/* Add a format with date formatting. */
$format = $workbook->addFormat();
$format->setNumFormat("mmm d yyyy hh:mm AM/PM");
/* Widen the first column to make the text clearer. */
$worksheet->setColumn([0, 0], 20, null);
/* Write the number without formatting. */
$worksheet->writeNumber([0, 0], $number, null); // 41333.5
/* Write the number with formatting. Note: the worksheet_write_datetime()
* function is preferable for writing dates and times. This is for
* demonstration purposes only.
*/
$worksheet->writeNumber([1, 0], $number, $format); // Feb 28 2013 12:00 PM
$workbook->close();