Files
PhpSpreadsheet/samples/DateTime2/TIMEVALUE.php
T
oleibman b3de003aa5 Reorganize Samples
The samples have become unwieldy when running them from a browser. In particular, the drop-down lists are fixed size with no scrolling, and many of them are now just too large. I have moved all the Calculation samples up a level, and broken several categories (Basic, Chart, DateTime, Engineering, Financial, and Reader) into several pieces.

Convert-Online (now found in the Engineering category) had a number of different problems which are now resolved. It is the only member with any significant code change.
2024-02-03 07:25:29 -08:00

40 lines
1.3 KiB
PHP

<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
require __DIR__ . '/../../Header.php';
$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
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
// Add some data
$testDates = ['3:15', '13:15', '15:15:15', '3:15 AM', '3:15 PM', '5PM', '9:15AM', '13:15AM',
];
$testDateCount = count($testDates);
for ($row = 1; $row <= $testDateCount; ++$row) {
$worksheet->setCellValue('A' . $row, $testDates[$row - 1]);
$worksheet->setCellValue('B' . $row, '=TIMEVALUE(A' . $row . ')');
$worksheet->setCellValue('C' . $row, '=B' . $row);
}
$worksheet->getStyle('C1:C' . $testDateCount)
->getNumberFormat()
->setFormatCode('hh:mm:ss');
// Test the formulae
for ($row = 1; $row <= $testDateCount; ++$row) {
$helper->log("(A{$row}) Time String: " . $worksheet->getCell('A' . $row)->getFormattedValue());
$helper->log('Formula: ' . $worksheet->getCell('B' . $row)->getValue());
$helper->log('Excel TimeStamp: ' . $worksheet->getCell('B' . $row)->getFormattedValue());
$helper->log('Formatted TimeStamp: ' . $worksheet->getCell('C' . $row)->getFormattedValue());
$helper->log('');
}