OSDN Git Service

Добавлены некоторые тесты сайта. Доавлен, но не подключён модуль импорта из .xls...
[invent/invent.git] / vendor / phpoffice / phpexcel / Documentation / Examples / Calculations / DateTime / TIMEVALUE.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>TIMEVALUE</h1>
20 <h2>Converts a time in the form of text to a serial number.</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(     '3:15', '13:15',        '15:15:15',     '3:15 AM',      '3:15 PM',      '5PM',  '9:15AM',       '13:15AM'
36                                   );
37 $testDateCount = count($testDates);
38
39 for($row = 1; $row <= $testDateCount; ++$row) {
40         $worksheet->setCellValue('A'.$row, $testDates[$row-1]);
41         $worksheet->setCellValue('B'.$row, '=TIMEVALUE(A'.$row.')');
42         $worksheet->setCellValue('C'.$row, '=B'.$row);
43 }
44
45 $worksheet->getStyle('C1:C'.$testDateCount)
46           ->getNumberFormat()
47           ->setFormatCode('hh:mm:ss');
48
49
50 echo '<hr />';
51
52
53 // Test the formulae
54 ?>
55 <table border="1" cellspacing="0">
56         <tr>
57                 <th>Time String</th>
58                 <th>Formula</th>
59                 <th>Excel TimeStamp</th>
60                 <th>Formatted TimeStamp</th>
61         </tr>
62         <?php
63         for ($row = 1; $row <= $testDateCount; ++$row) {
64                 echo '<tr>';
65                     echo '<td>' , $worksheet->getCell('A'.$row)->getFormattedValue() , '</td>';
66                         echo '<td>' , $worksheet->getCell('B'.$row)->getValue() , '</td>';
67                         echo '<td>' , $worksheet->getCell('B'.$row)->getFormattedValue() , '</td>';
68                         echo '<td>' , $worksheet->getCell('C'.$row)->getFormattedValue() , '</td>';
69                 echo '</tr>';
70         }
71         ?>
72 </table>