/
dates_and_times02.php
31 lines (24 loc) · 1009 Bytes
/
dates_and_times02.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
<?php
/**
* @see http://libxlsxwriter.github.io/dates_and_times02_8c-example.html
* @noinspection PhpUnhandledExceptionInspection
*/
use FFILibXlsxWriter\FFILibXlsxWriter;
use FFILibXlsxWriter\Structs\DateTime as XlsxDateTime;
use FFILibXlsxWriter\Workbook;
require_once __DIR__ . '/../vendor/autoload.php';
FFILibXlsxWriter::init();
$workbook = new Workbook(__DIR__ . '/output/dates_and_times02.xlsx');
$worksheet = $workbook->addWorksheet();
/* A datetime to display. */
$datetime = new XlsxDateTime(2013, 2, 28, 12, 0, 0.0);
/* 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 datetime without formatting. */
$worksheet->writeDatetime([0, 0], $datetime, null); // 41333.5
/* Write the datetime with formatting. */
$worksheet->writeDatetime([1, 0], $datetime, $format); // Feb 28 2013 12:00 PM
$workbook->close();