Update Excel function samples for Date/Time functions
This commit is contained in:
parent
ad2d3df2f7
commit
3884aa7477
|
|
@ -4,7 +4,11 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/../../Header.php';
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
$helper->log('Returns the serial number of a particular date.');
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'DATE';
|
||||||
|
$description = 'Returns the Excel serial number of a particular date';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Create new PhpSpreadsheet object
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
@ -27,15 +31,15 @@ for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
}
|
}
|
||||||
$worksheet->getStyle('E1:E' . $testDateCount)
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
->getNumberFormat()
|
->getNumberFormat()
|
||||||
->setFormatCode('yyyy-mmm-dd');
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
// Test the formulae
|
// Test the formulae
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
$helper->log('Year: ' . $worksheet->getCell('A' . $row)->getFormattedValue());
|
$helper->log("(A{$row}) Year: " . $worksheet->getCell('A' . $row)->getFormattedValue());
|
||||||
$helper->log('Month: ' . $worksheet->getCell('B' . $row)->getFormattedValue());
|
$helper->log("(B{$row}) Month: " . $worksheet->getCell('B' . $row)->getFormattedValue());
|
||||||
$helper->log('Day: ' . $worksheet->getCell('C' . $row)->getFormattedValue());
|
$helper->log("(C{$row}) Day: " . $worksheet->getCell('C' . $row)->getFormattedValue());
|
||||||
$helper->log('Formula: ' . $worksheet->getCell('D' . $row)->getValue());
|
$helper->log('Formula: ' . $worksheet->getCell('D' . $row)->getValue());
|
||||||
$helper->log('Excel DateStamp: ' . $worksheet->getCell('D' . $row)->getFormattedValue());
|
$helper->log('Excel DateStamp: ' . $worksheet->getCell('D' . $row)->getCalculatedValue());
|
||||||
$helper->log('Formatted DateStamp: ' . $worksheet->getCell('E' . $row)->getFormattedValue());
|
$helper->log('Formatted DateStamp: ' . $worksheet->getCell('E' . $row)->getFormattedValue());
|
||||||
$helper->log('');
|
$helper->log('');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'DATEDIF';
|
||||||
|
$description = 'Calculates the number of days, months, or years between two dates';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 1, 1],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1960, 12, 19],
|
||||||
|
[1999, 12, 31],
|
||||||
|
[2000, 1, 1],
|
||||||
|
[2019, 2, 14],
|
||||||
|
[2020, 7, 4],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=TODAY()');
|
||||||
|
$worksheet->setCellValue('G' . $row, '=DATEDIF(D' . $row . ', F' . $row . ', "Y")');
|
||||||
|
$worksheet->setCellValue('H' . $row, '=DATEDIF(D' . $row . ', F' . $row . ', "M")');
|
||||||
|
$worksheet->setCellValue('I' . $row, '=DATEDIF(D' . $row . ', F' . $row . ', "D")');
|
||||||
|
$worksheet->setCellValue('J' . $row, '=DATEDIF(D' . $row . ', F' . $row . ', "MD")');
|
||||||
|
$worksheet->setCellValue('K' . $row, '=DATEDIF(D' . $row . ', F' . $row . ', "YM")');
|
||||||
|
$worksheet->setCellValue('L' . $row, '=DATEDIF(D' . $row . ', F' . $row . ', "YD")');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:F' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'Between: %s and %s',
|
||||||
|
$worksheet->getCell('E' . $row)->getFormattedValue(),
|
||||||
|
$worksheet->getCell('F' . $row)->getFormattedValue()
|
||||||
|
));
|
||||||
|
$helper->log('In years ("Y"): ' . $worksheet->getCell('G' . $row)->getCalculatedValue());
|
||||||
|
$helper->log('In months ("M"): ' . $worksheet->getCell('H' . $row)->getCalculatedValue());
|
||||||
|
$helper->log('In days ("D"): ' . $worksheet->getCell('I' . $row)->getCalculatedValue());
|
||||||
|
$helper->log('In days ignoring months and years ("MD"): ' . $worksheet->getCell('J' . $row)->getCalculatedValue());
|
||||||
|
$helper->log('In months ignoring days and years ("YM"): ' . $worksheet->getCell('K' . $row)->getCalculatedValue());
|
||||||
|
$helper->log('In days ignoring years ("YD"): ' . $worksheet->getCell('L' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,11 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/../../Header.php';
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
$helper->log('Converts a date in the form of text to a serial number.');
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'DATEVALUE';
|
||||||
|
$description = 'Converts a date in the form of text to an Excel serial number';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Create new PhpSpreadsheet object
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
@ -13,8 +17,8 @@ $worksheet = $spreadsheet->getActiveSheet();
|
||||||
// Add some data
|
// Add some data
|
||||||
$testDates = ['26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012',
|
$testDates = ['26 March 2012', '29 Feb 2012', 'April 1, 2012', '25/12/2012',
|
||||||
'2012-Oct-31', '5th November', 'January 1st', 'April 2012',
|
'2012-Oct-31', '5th November', 'January 1st', 'April 2012',
|
||||||
'17-03', '03-2012', '29 Feb 2011', '03-05-07',
|
'17-03', '03-17', '03-2012', '29 Feb 2011', '03-05-07',
|
||||||
'03-MAY-07', '03-13-07',
|
'03-MAY-07', '03-13-07', '13-03-07', '03/13/07', '13/03/07',
|
||||||
];
|
];
|
||||||
$testDateCount = count($testDates);
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
|
@ -26,14 +30,14 @@ for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
|
||||||
$worksheet->getStyle('C1:C' . $testDateCount)
|
$worksheet->getStyle('C1:C' . $testDateCount)
|
||||||
->getNumberFormat()
|
->getNumberFormat()
|
||||||
->setFormatCode('yyyy-mmm-dd');
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
// Test the formulae
|
// Test the formulae
|
||||||
$helper->log('<strong>Warning: </strong>The PhpSpreadsheet DATEVALUE() function accepts a wider range of date formats than MS Excel DATEFORMAT() function.');
|
$helper->log('<strong>Warning: </strong>The PhpSpreadsheet DATEVALUE() function accepts a wider range of date formats than MS Excel DATEFORMAT() function.');
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
$helper->log('Date String: ' . $worksheet->getCell('A' . $row)->getFormattedValue());
|
$helper->log("(A{$row}) Date String: " . $worksheet->getCell('A' . $row)->getFormattedValue());
|
||||||
$helper->log('Formula: ' . $worksheet->getCell('B' . $row)->getValue());
|
$helper->log('Formula: ' . $worksheet->getCell('B' . $row)->getValue());
|
||||||
$helper->log('Excel DateStamp: ' . $worksheet->getCell('B' . $row)->getFormattedValue());
|
$helper->log('Excel DateStamp: ' . $worksheet->getCell('B' . $row)->getCalculatedValue());
|
||||||
$helper->log('Formatted DateStamp' . $worksheet->getCell('C' . $row)->getFormattedValue());
|
$helper->log('Formatted DateStamp: ' . $worksheet->getCell('C' . $row)->getFormattedValue());
|
||||||
$helper->log('');
|
$helper->log('');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'DAY';
|
||||||
|
$description = 'Returns the day of a date, an integer ranging from 1 to 31';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 2, 14],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1964, 4, 29],
|
||||||
|
[1999, 5, 18],
|
||||||
|
[2000, 6, 21],
|
||||||
|
[2019, 7, 4],
|
||||||
|
[2020, 8, 31],
|
||||||
|
[1956, 9, 10],
|
||||||
|
[2010, 10, 10],
|
||||||
|
[1982, 11, 30],
|
||||||
|
[1960, 12, 19],
|
||||||
|
['=YEAR(TODAY())', '=MONTH(TODAY())', '=DAY(TODAY())'],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=DAY(D' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log('Day is: ' . $worksheet->getCell('F' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'DAYS';
|
||||||
|
$description = 'Returns the number of days between two dates';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 1, 1],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1960, 12, 19],
|
||||||
|
[1999, 12, 31],
|
||||||
|
[2000, 1, 1],
|
||||||
|
[2019, 2, 14],
|
||||||
|
[2020, 7, 4],
|
||||||
|
[2029, 12, 31],
|
||||||
|
[2525, 1, 1],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=TODAY()');
|
||||||
|
$worksheet->setCellValue('G' . $row, '=DAYS(D' . $row . ', F' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:F' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'Between: %s and %s',
|
||||||
|
$worksheet->getCell('E' . $row)->getFormattedValue(),
|
||||||
|
$worksheet->getCell('F' . $row)->getFormattedValue()
|
||||||
|
));
|
||||||
|
$helper->log('Days: ' . $worksheet->getCell('G' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'DAYS360';
|
||||||
|
$description = 'Returns the number of days between two dates based on a 360-day year';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 1, 1],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1960, 12, 19],
|
||||||
|
[1999, 12, 31],
|
||||||
|
[2000, 1, 1],
|
||||||
|
[2019, 2, 14],
|
||||||
|
[2020, 7, 4],
|
||||||
|
[2029, 12, 31],
|
||||||
|
[2525, 1, 1],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=DATE(2022,12,31)');
|
||||||
|
$worksheet->setCellValue('G' . $row, '=DAYS360(D' . $row . ', F' . $row . ', FALSE)');
|
||||||
|
$worksheet->setCellValue('H' . $row, '=DAYS360(D' . $row . ', F' . $row . ', TRUE)');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:F' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'Between: %s and %s',
|
||||||
|
$worksheet->getCell('E' . $row)->getFormattedValue(),
|
||||||
|
$worksheet->getCell('F' . $row)->getFormattedValue()
|
||||||
|
));
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'Days: %d (US) %d (European)',
|
||||||
|
$worksheet->getCell('G' . $row)->getCalculatedValue(),
|
||||||
|
$worksheet->getCell('H' . $row)->getCalculatedValue()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'EDATE';
|
||||||
|
$description = 'Returns the serial number that represents the date that is the indicated number of months before or after a specified date';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
$months = range(-12, 12);
|
||||||
|
$testDateCount = count($months);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('A' . $row, '=DATE(2020,12,31)');
|
||||||
|
$worksheet->setCellValue('B' . $row, '=A' . $row);
|
||||||
|
$worksheet->setCellValue('C' . $row, $months[$row - 1]);
|
||||||
|
$worksheet->setCellValue('D' . $row, '=EDATE(B' . $row . ', C' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('B1:B' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
$worksheet->getStyle('D1:D' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'%s and %d months is %d (%s)',
|
||||||
|
$worksheet->getCell('B' . $row)->getFormattedValue(),
|
||||||
|
$worksheet->getCell('C' . $row)->getFormattedValue(),
|
||||||
|
$worksheet->getCell('D' . $row)->getCalculatedValue(),
|
||||||
|
$worksheet->getCell('D' . $row)->getFormattedValue()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'EOMONTH';
|
||||||
|
$description = 'Returns the serial number for the last day of the month that is the indicated number of months before or after start_date';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
$months = range(-12, 12);
|
||||||
|
$testDateCount = count($months);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('A' . $row, '=DATE(2020,1,1)');
|
||||||
|
$worksheet->setCellValue('B' . $row, '=A' . $row);
|
||||||
|
$worksheet->setCellValue('C' . $row, $months[$row - 1]);
|
||||||
|
$worksheet->setCellValue('D' . $row, '=EOMONTH(B' . $row . ', C' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('B1:B' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
$worksheet->getStyle('D1:D' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'%s and %d months is %d (%s)',
|
||||||
|
$worksheet->getCell('B' . $row)->getFormattedValue(),
|
||||||
|
$worksheet->getCell('C' . $row)->getFormattedValue(),
|
||||||
|
$worksheet->getCell('D' . $row)->getCalculatedValue(),
|
||||||
|
$worksheet->getCell('D' . $row)->getFormattedValue()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'HOUR';
|
||||||
|
$description = 'Returns the hour of a time value. The hour is given as an integer, ranging from 0 (12:00 AM) to 23 (11:00 PM)';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testTimes = [
|
||||||
|
[0, 6, 0],
|
||||||
|
[1, 12, 15],
|
||||||
|
[3, 30, 12],
|
||||||
|
[5, 17, 31],
|
||||||
|
[8, 15, 45],
|
||||||
|
[12, 45, 11],
|
||||||
|
[14, 0, 30],
|
||||||
|
[17, 55, 50],
|
||||||
|
[19, 21, 8],
|
||||||
|
[21, 10, 10],
|
||||||
|
[23, 59, 59],
|
||||||
|
];
|
||||||
|
$testTimeCount = count($testTimes);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testTimes, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testTimeCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=HOUR(D' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testTimeCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('hh:mm:ss');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testTimeCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log('Hour is: ' . $worksheet->getCell('F' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'ISOWEEKNUM';
|
||||||
|
$description = 'Returns number of the ISO week number of the year for a given date. (ISO-8601)';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 2, 14],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1964, 4, 29],
|
||||||
|
[1999, 5, 18],
|
||||||
|
[2000, 6, 21],
|
||||||
|
[2019, 7, 4],
|
||||||
|
[2020, 8, 31],
|
||||||
|
[1956, 9, 10],
|
||||||
|
[2010, 10, 10],
|
||||||
|
[1982, 11, 30],
|
||||||
|
[1960, 12, 19],
|
||||||
|
['=YEAR(TODAY())', '=MONTH(TODAY())', '=DAY(TODAY())'],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=ISOWEEKNUM(D' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log('ISO Week number is: ' . $worksheet->getCell('F' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'MINUTE';
|
||||||
|
$description = 'Returns the minute of a time value. The minute is given as an integer, ranging from 0 to 59';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testTimes = [
|
||||||
|
[0, 6, 0],
|
||||||
|
[1, 12, 15],
|
||||||
|
[3, 30, 12],
|
||||||
|
[5, 17, 31],
|
||||||
|
[8, 15, 45],
|
||||||
|
[12, 45, 11],
|
||||||
|
[14, 0, 30],
|
||||||
|
[17, 55, 50],
|
||||||
|
[19, 21, 8],
|
||||||
|
[21, 10, 10],
|
||||||
|
[23, 59, 59],
|
||||||
|
];
|
||||||
|
$testTimeCount = count($testTimes);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testTimes, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testTimeCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=MINUTE(D' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testTimeCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('hh:mm:ss');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testTimeCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log('Minute is: ' . $worksheet->getCell('F' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'MONTH';
|
||||||
|
$description = 'Returns the month of a date, an integer ranging from 1 to 12';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 2, 14],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1964, 4, 29],
|
||||||
|
[1999, 5, 18],
|
||||||
|
[2000, 6, 21],
|
||||||
|
[2019, 7, 4],
|
||||||
|
[2020, 8, 31],
|
||||||
|
[1956, 9, 10],
|
||||||
|
[2010, 10, 10],
|
||||||
|
[1982, 11, 30],
|
||||||
|
[1960, 12, 19],
|
||||||
|
['=YEAR(TODAY())', '=MONTH(TODAY())', '=DAY(TODAY())'],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=MONTH(D' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log('Month is: ' . $worksheet->getCell('F' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'NOW';
|
||||||
|
$description = 'Returns the serial number of the current date and time';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
$worksheet->setCellValue('A1', '=NOW()');
|
||||||
|
$worksheet->getStyle('A1')
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd hh:mm:ss');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'Today is %f (%s)',
|
||||||
|
$worksheet->getCell('A1')->getCalculatedValue(),
|
||||||
|
$worksheet->getCell('A1')->getFormattedValue()
|
||||||
|
));
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'SECOND';
|
||||||
|
$description = 'Returns the second of a time value. The second is given as an integer, ranging from 0 to 59';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testTimes = [
|
||||||
|
[0, 6, 0],
|
||||||
|
[1, 12, 15],
|
||||||
|
[3, 30, 12],
|
||||||
|
[5, 17, 31],
|
||||||
|
[8, 15, 45],
|
||||||
|
[12, 45, 11],
|
||||||
|
[14, 0, 30],
|
||||||
|
[17, 55, 50],
|
||||||
|
[19, 21, 8],
|
||||||
|
[21, 10, 10],
|
||||||
|
[23, 59, 59],
|
||||||
|
];
|
||||||
|
$testTimeCount = count($testTimes);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testTimes, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testTimeCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=SECOND(D' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testTimeCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('hh:mm:ss');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testTimeCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log('Second is: ' . $worksheet->getCell('F' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,11 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/../../Header.php';
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
$helper->log('Returns the serial number of a particular time.');
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'TIME';
|
||||||
|
$description = 'Returns the Excel serial number of a particular time';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Create new PhpSpreadsheet object
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
@ -29,11 +33,11 @@ $worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
|
||||||
// Test the formulae
|
// Test the formulae
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
$helper->log('Hour: ' . $worksheet->getCell('A' . $row)->getFormattedValue());
|
$helper->log("(A{$row}) Hour: " . $worksheet->getCell('A' . $row)->getFormattedValue());
|
||||||
$helper->log('Minute: ' . $worksheet->getCell('B' . $row)->getFormattedValue());
|
$helper->log("(B{$row}) Minute: " . $worksheet->getCell('B' . $row)->getFormattedValue());
|
||||||
$helper->log('Second: ' . $worksheet->getCell('C' . $row)->getFormattedValue());
|
$helper->log("(C{$row}) Second: " . $worksheet->getCell('C' . $row)->getFormattedValue());
|
||||||
$helper->log('Formula: ' . $worksheet->getCell('D' . $row)->getValue());
|
$helper->log('Formula: ' . $worksheet->getCell('D' . $row)->getValue());
|
||||||
$helper->log('Excel TimeStamp: ' . $worksheet->getCell('D' . $row)->getFormattedValue());
|
$helper->log('Excel TimeStamp: ' . $worksheet->getCell('D' . $row)->getCalculatedValue());
|
||||||
$helper->log('Formatted TimeStamp: ' . $worksheet->getCell('E' . $row)->getFormattedValue());
|
$helper->log('Formatted TimeStamp: ' . $worksheet->getCell('E' . $row)->getFormattedValue());
|
||||||
$helper->log('');
|
$helper->log('');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,11 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
require __DIR__ . '/../../Header.php';
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
$helper->log('Converts a time in the form of text to a serial number.');
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'DATEVALUE';
|
||||||
|
$description = 'Converts a time in the form of text to an Excel serial number';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
// Create new PhpSpreadsheet object
|
// Create new PhpSpreadsheet object
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
|
|
@ -27,7 +31,7 @@ $worksheet->getStyle('C1:C' . $testDateCount)
|
||||||
|
|
||||||
// Test the formulae
|
// Test the formulae
|
||||||
for ($row = 1; $row <= $testDateCount; ++$row) {
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
$helper->log('Time String: ' . $worksheet->getCell('A' . $row)->getFormattedValue());
|
$helper->log("(A{$row}) Time String: " . $worksheet->getCell('A' . $row)->getFormattedValue());
|
||||||
$helper->log('Formula: ' . $worksheet->getCell('B' . $row)->getValue());
|
$helper->log('Formula: ' . $worksheet->getCell('B' . $row)->getValue());
|
||||||
$helper->log('Excel TimeStamp: ' . $worksheet->getCell('B' . $row)->getFormattedValue());
|
$helper->log('Excel TimeStamp: ' . $worksheet->getCell('B' . $row)->getFormattedValue());
|
||||||
$helper->log('Formatted TimeStamp: ' . $worksheet->getCell('C' . $row)->getFormattedValue());
|
$helper->log('Formatted TimeStamp: ' . $worksheet->getCell('C' . $row)->getFormattedValue());
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'TODAY';
|
||||||
|
$description = 'Returns the serial number of the current date';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
$worksheet->setCellValue('A1', '=TODAY()');
|
||||||
|
$worksheet->getStyle('A1')
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'Today is %d (%s)',
|
||||||
|
$worksheet->getCell('A1')->getCalculatedValue(),
|
||||||
|
$worksheet->getCell('A1')->getFormattedValue()
|
||||||
|
));
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'WEEKDAY';
|
||||||
|
$description = 'Returns the day of the week corresponding to a date';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 2, 14],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1964, 4, 29],
|
||||||
|
[1999, 5, 18],
|
||||||
|
[2000, 6, 21],
|
||||||
|
[2019, 7, 4],
|
||||||
|
[2020, 8, 31],
|
||||||
|
[1956, 9, 10],
|
||||||
|
[2010, 10, 10],
|
||||||
|
[1982, 11, 30],
|
||||||
|
[1960, 12, 19],
|
||||||
|
['=YEAR(TODAY())', '=MONTH(TODAY())', '=DAY(TODAY())'],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=WEEKDAY(D' . $row . ')');
|
||||||
|
$worksheet->setCellValue('G' . $row, '=WEEKDAY(D' . $row . ', 2)');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'Weekday is: %d (1-7 = Sun-Sat)',
|
||||||
|
$worksheet->getCell('F' . $row)->getCalculatedValue()
|
||||||
|
));
|
||||||
|
$helper->log(sprintf(
|
||||||
|
'Weekday is: %d (1-7 = Mon-Sun)',
|
||||||
|
$worksheet->getCell('G' . $row)->getCalculatedValue()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'WEEKNUM';
|
||||||
|
$description = 'Returns the week number of a specific date';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 2, 14],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1964, 4, 29],
|
||||||
|
[1999, 5, 18],
|
||||||
|
[2000, 6, 21],
|
||||||
|
[2019, 7, 4],
|
||||||
|
[2020, 8, 31],
|
||||||
|
[1956, 9, 10],
|
||||||
|
[2010, 10, 10],
|
||||||
|
[1982, 11, 30],
|
||||||
|
[1960, 12, 19],
|
||||||
|
['=YEAR(TODAY())', '=MONTH(TODAY())', '=DAY(TODAY())'],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=WEEKNUM(D' . $row . ')');
|
||||||
|
$worksheet->setCellValue('G' . $row, '=WEEKNUM(D' . $row . ', 21)');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log('System 1 Week number is: ' . $worksheet->getCell('F' . $row)->getCalculatedValue());
|
||||||
|
$helper->log('System 2 (ISO-8601) Week number is: ' . $worksheet->getCell('G' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../Header.php';
|
||||||
|
|
||||||
|
$category = 'Date/Time';
|
||||||
|
$functionName = 'YEAR';
|
||||||
|
$description = 'Returns the year of a date, an integer ranging from 1900 to 9999';
|
||||||
|
|
||||||
|
$helper->titles($category, $functionName, $description);
|
||||||
|
|
||||||
|
// Create new PhpSpreadsheet object
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$worksheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
|
// Add some data
|
||||||
|
$testDates = [
|
||||||
|
[1900, 1, 1],
|
||||||
|
[1904, 2, 14],
|
||||||
|
[1936, 3, 17],
|
||||||
|
[1964, 4, 29],
|
||||||
|
[1999, 5, 18],
|
||||||
|
[2000, 6, 21],
|
||||||
|
[2019, 7, 4],
|
||||||
|
[2020, 8, 31],
|
||||||
|
[1956, 9, 10],
|
||||||
|
[2010, 10, 10],
|
||||||
|
[1982, 11, 30],
|
||||||
|
[1960, 12, 19],
|
||||||
|
['=YEAR(TODAY())', '=MONTH(TODAY())', '=DAY(TODAY())'],
|
||||||
|
];
|
||||||
|
$testDateCount = count($testDates);
|
||||||
|
|
||||||
|
$worksheet->fromArray($testDates, null, 'A1', true);
|
||||||
|
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$worksheet->setCellValue('D' . $row, '=DATE(A' . $row . ',B' . $row . ',C' . $row . ')');
|
||||||
|
$worksheet->setCellValue('E' . $row, '=D' . $row);
|
||||||
|
$worksheet->setCellValue('F' . $row, '=YEAR(D' . $row . ')');
|
||||||
|
}
|
||||||
|
$worksheet->getStyle('E1:E' . $testDateCount)
|
||||||
|
->getNumberFormat()
|
||||||
|
->setFormatCode('yyyy-mm-dd');
|
||||||
|
|
||||||
|
// Test the formulae
|
||||||
|
for ($row = 1; $row <= $testDateCount; ++$row) {
|
||||||
|
$helper->log(sprintf('(E%d): %s', $row, $worksheet->getCell('E' . $row)->getFormattedValue()));
|
||||||
|
$helper->log('Year is: ' . $worksheet->getCell('F' . $row)->getCalculatedValue());
|
||||||
|
}
|
||||||
|
|
@ -187,8 +187,8 @@ class Sample
|
||||||
{
|
{
|
||||||
$this->log(sprintf('%s Functions:', $category));
|
$this->log(sprintf('%s Functions:', $category));
|
||||||
$description === null
|
$description === null
|
||||||
? $this->log(sprintf('%s()', rtrim($functionName, '()')))
|
? $this->log(sprintf('Function: %s()', rtrim($functionName, '()')))
|
||||||
: $this->log(sprintf('%s() - %s.', rtrim($functionName, '()'), rtrim($description, '.')));
|
: $this->log(sprintf('Function: %s() - %s.', rtrim($functionName, '()'), rtrim($description, '.')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function displayGrid(array $matrix): void
|
public function displayGrid(array $matrix): void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue