For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.2 KiB

  1. <?php
  2. error_reporting(E_ALL);
  3. set_time_limit(0);
  4. date_default_timezone_set('Europe/London');
  5. ?>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <title>PHPExcel Calculation Examples</title>
  10. </head>
  11. <body>
  12. <h1>DATE</h1>
  13. <h2>Returns the serial number of a particular date.</h2>
  14. <?php
  15. /** Include path **/
  16. set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
  17. /** Include PHPExcel */
  18. include 'PHPExcel.php';
  19. // Create new PHPExcel object
  20. $objPHPExcel = new PHPExcel();
  21. $worksheet = $objPHPExcel->getActiveSheet();
  22. // Add some data
  23. $testDates = array( array(2012,3,26), array(2012,2,29), array(2012,4,1), array(2012,12,25),
  24. array(2012,10,31), array(2012,11,5), array(2012,1,1), array(2012,3,17),
  25. array(2011,2,29), array(7,5,3), array(2012,13,1), array(2012,11,45),
  26. array(2012,0,0), array(2012,1,0), array(2012,0,1),
  27. array(2012,-2,2), array(2012,2,-2), array(2012,-2,-2),
  28. );
  29. $testDateCount = count($testDates);
  30. $worksheet->fromArray($testDates,NULL,'A1',true);
  31. for ($row = 1; $row <= $testDateCount; ++$row) {
  32. $worksheet->setCellValue('D'.$row, '=DATE(A'.$row.',B'.$row.',C'.$row.')');
  33. $worksheet->setCellValue('E'.$row, '=D'.$row);
  34. }
  35. $worksheet->getStyle('E1:E'.$testDateCount)
  36. ->getNumberFormat()
  37. ->setFormatCode('yyyy-mmm-dd');
  38. echo '<hr />';
  39. // Test the formulae
  40. ?>
  41. <table border="1" cellspacing="0">
  42. <tr>
  43. <th colspan="3">Date Value</th>
  44. <th rowspan="2" valign="bottom">Formula</th>
  45. <th rowspan="2" valign="bottom">Excel DateStamp</th>
  46. <th rowspan="2" valign="bottom">Formatted DateStamp</th>
  47. </tr>
  48. <tr>
  49. <th>Year</th>
  50. <th>Month</th>
  51. <th>Day</th>
  52. <tr>
  53. <?php
  54. for ($row = 1; $row <= $testDateCount; ++$row) {
  55. echo '<tr>';
  56. echo '<td>' , $worksheet->getCell('A'.$row)->getFormattedValue() , '</td>';
  57. echo '<td>' , $worksheet->getCell('B'.$row)->getFormattedValue() , '</td>';
  58. echo '<td>' , $worksheet->getCell('C'.$row)->getFormattedValue() , '</td>';
  59. echo '<td>' , $worksheet->getCell('D'.$row)->getValue() , '</td>';
  60. echo '<td>' , $worksheet->getCell('D'.$row)->getFormattedValue() , '</td>';
  61. echo '<td>' , $worksheet->getCell('E'.$row)->getFormattedValue() , '</td>';
  62. echo '</tr>';
  63. }
  64. ?>
  65. </table>