OSDN Git Service

Добавлены некоторые тесты сайта. Доавлен, но не подключён модуль импорта из .xls...
[invent/invent.git] / vendor / phpoffice / phpexcel / Documentation / Examples / Calculations / DateTime / DATE.php
1 <?php
2
3 error_reporting(E_ALL);
4 set_time_limit(0);
5
6 date_default_timezone_set('Europe/London');
7
8
9 ?>
10 <html>
11 <head>
12 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
13
14 <title>PHPExcel Calculation Examples</title>
15
16 </head>
17 <body>
18
19 <h1>DATE</h1>
20 <h2>Returns the serial number of a particular date.</h2>
21 <?php
22
23 /** Include path **/
24 set_include_path(get_include_path() . PATH_SEPARATOR . '../../../../Classes/');
25
26 /** Include PHPExcel */
27 include 'PHPExcel.php';
28
29
30 // Create new PHPExcel object
31 $objPHPExcel = new PHPExcel();
32 $worksheet = $objPHPExcel->getActiveSheet();
33
34 // Add some data
35 $testDates = array(     array(2012,3,26),       array(2012,2,29),       array(2012,4,1),        array(2012,12,25),
36                                         array(2012,10,31),      array(2012,11,5),       array(2012,1,1),        array(2012,3,17),
37                                         array(2011,2,29),       array(7,5,3),           array(2012,13,1),       array(2012,11,45),
38                                         array(2012,0,0),        array(2012,1,0),        array(2012,0,1),
39                                         array(2012,-2,2),       array(2012,2,-2),       array(2012,-2,-2),
40                                   );
41 $testDateCount = count($testDates);
42
43 $worksheet->fromArray($testDates,NULL,'A1',true);
44
45 for ($row = 1; $row <= $testDateCount; ++$row) {
46         $worksheet->setCellValue('D'.$row, '=DATE(A'.$row.',B'.$row.',C'.$row.')');
47         $worksheet->setCellValue('E'.$row, '=D'.$row);
48 }
49 $worksheet->getStyle('E1:E'.$testDateCount)
50           ->getNumberFormat()
51           ->setFormatCode('yyyy-mmm-dd');
52
53
54 echo '<hr />';
55
56
57 // Test the formulae
58 ?>
59 <table border="1" cellspacing="0">
60         <tr>
61                 <th colspan="3">Date Value</th>
62                 <th rowspan="2" valign="bottom">Formula</th>
63                 <th rowspan="2" valign="bottom">Excel DateStamp</th>
64                 <th rowspan="2" valign="bottom">Formatted DateStamp</th>
65         </tr>
66         <tr>
67                 <th>Year</th>
68                 <th>Month</th>
69                 <th>Day</th>
70         <tr>
71         <?php
72         for ($row = 1; $row <= $testDateCount; ++$row) {
73                 echo '<tr>';
74                     echo '<td>' , $worksheet->getCell('A'.$row)->getFormattedValue() , '</td>';
75                         echo '<td>' , $worksheet->getCell('B'.$row)->getFormattedValue() , '</td>';
76                         echo '<td>' , $worksheet->getCell('C'.$row)->getFormattedValue() , '</td>';
77                         echo '<td>' , $worksheet->getCell('D'.$row)->getValue() , '</td>';
78                         echo '<td>' , $worksheet->getCell('D'.$row)->getFormattedValue() , '</td>';
79                         echo '<td>' , $worksheet->getCell('E'.$row)->getFormattedValue() , '</td>';
80                 echo '</tr>';
81         }
82         ?>
83 </table>