TIME.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  3. require __DIR__ . '/../../Header.php';
  4. $helper->log('Returns the serial number of a particular time.');
  5. // Create new PhpSpreadsheet object
  6. $spreadsheet = new Spreadsheet();
  7. $worksheet = $spreadsheet->getActiveSheet();
  8. // Add some data
  9. $testDates = [[3, 15], [13, 15], [15, 15, 15], [3, 15, 30],
  10. [15, 15, 15], [5], [9, 15, 0], [9, 15, -1],
  11. [13, -14, -15], [0, 0, -1],
  12. ];
  13. $testDateCount = count($testDates);
  14. $worksheet->fromArray($testDates, null, 'A1', true);
  15. for ($row = 1; $row <= $testDateCount; ++$row) {
  16. $worksheet->setCellValue('D' . $row, '=TIME(A' . $row . ',B' . $row . ',C' . $row . ')');
  17. $worksheet->setCellValue('E' . $row, '=D' . $row);
  18. }
  19. $worksheet->getStyle('E1:E' . $testDateCount)
  20. ->getNumberFormat()
  21. ->setFormatCode('hh:mm:ss');
  22. // Test the formulae
  23. for ($row = 1; $row <= $testDateCount; ++$row) {
  24. $helper->log('Hour: ' . $worksheet->getCell('A' . $row)->getFormattedValue());
  25. $helper->log('Minute: ' . $worksheet->getCell('B' . $row)->getFormattedValue());
  26. $helper->log('Second: ' . $worksheet->getCell('C' . $row)->getFormattedValue());
  27. $helper->log('Formula: ' . $worksheet->getCell('D' . $row)->getValue());
  28. $helper->log('Excel TimeStamp: ' . $worksheet->getCell('D' . $row)->getFormattedValue());
  29. $helper->log('Formatted TimeStamp: ' . $worksheet->getCell('E' . $row)->getFormattedValue());
  30. $helper->log('');
  31. }