OSDN Git Service

Добавлены некоторые тесты сайта. Доавлен, но не подключён модуль импорта из .xls...
[invent/invent.git] / vendor / phpoffice / phpexcel / Examples / 06largescale-with-cellcaching-sqlite3.php
1 <?php
2 /**
3  * PHPExcel
4  *
5  * Copyright (c) 2006 - 2015 PHPExcel
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20  *
21  * @category   PHPExcel
22  * @package    PHPExcel
23  * @copyright  Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
24  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
25  * @version    ##VERSION##, ##DATE##
26  */
27
28 /** Error reporting */
29 error_reporting(E_ALL);
30 ini_set('display_errors', TRUE);
31 ini_set('display_startup_errors', TRUE);
32
33 define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
34
35 date_default_timezone_set('Europe/London');
36
37 /** Include PHPExcel */
38 require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
39
40 $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite3;
41 if (PHPExcel_Settings::setCacheStorageMethod($cacheMethod)) {
42     echo date('H:i:s') , " Enable Cell Caching using " , $cacheMethod , " method" , EOL;
43 } else {
44     echo date('H:i:s') , " Unable to set Cell Caching using " , $cacheMethod , " method, reverting to memory" , EOL;
45 }
46
47
48 // Create new PHPExcel object
49 echo date('H:i:s') , " Create new PHPExcel object" , EOL;
50 $objPHPExcel = new PHPExcel();
51
52 // Set document properties
53 echo date('H:i:s') , " Set properties" , EOL;
54 $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
55                                                          ->setLastModifiedBy("Maarten Balliauw")
56                                                          ->setTitle("Office 2007 XLSX Test Document")
57                                                          ->setSubject("Office 2007 XLSX Test Document")
58                                                          ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
59                                                          ->setKeywords("office 2007 openxml php")
60                                                          ->setCategory("Test result file");
61
62
63 // Create a first sheet
64 echo date('H:i:s') , " Add data" , EOL;
65 $objPHPExcel->setActiveSheetIndex(0);
66 $objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname");
67 $objPHPExcel->getActiveSheet()->setCellValue('B1', "Lastname");
68 $objPHPExcel->getActiveSheet()->setCellValue('C1', "Phone");
69 $objPHPExcel->getActiveSheet()->setCellValue('D1', "Fax");
70 $objPHPExcel->getActiveSheet()->setCellValue('E1', "Is Client ?");
71
72
73 // Hide "Phone" and "fax" column
74 echo date('H:i:s') , " Hide 'Phone' and 'fax' columns" , EOL;
75 $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setVisible(false);
76 $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setVisible(false);
77
78
79 // Set outline levels
80 echo date('H:i:s') , " Set outline levels" , EOL;
81 $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setOutlineLevel(1)
82                                                        ->setVisible(false)
83                                                        ->setCollapsed(true);
84
85 // Freeze panes
86 echo date('H:i:s') , " Freeze panes" , EOL;
87 $objPHPExcel->getActiveSheet()->freezePane('A2');
88
89
90 // Rows to repeat at top
91 echo date('H:i:s') , " Rows to repeat at top" , EOL;
92 $objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1);
93
94
95 // Add data
96 for ($i = 2; $i <= 5000; $i++) {
97         $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, "FName $i")
98                                       ->setCellValue('B' . $i, "LName $i")
99                                       ->setCellValue('C' . $i, "PhoneNo $i")
100                                       ->setCellValue('D' . $i, "FaxNo $i")
101                                       ->setCellValue('E' . $i, true);
102 }
103
104
105 // Set active sheet index to the first sheet, so Excel opens this as the first sheet
106 $objPHPExcel->setActiveSheetIndex(0);
107
108
109 // Save Excel 2007 file
110 echo date('H:i:s') , " Write to Excel2007 format" , EOL;
111 $callStartTime = microtime(true);
112
113 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
114 $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
115 $callEndTime = microtime(true);
116 $callTime = $callEndTime - $callStartTime;
117
118 echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
119 echo 'Call time to write Workbook was ' , sprintf('%.4f',$callTime) , " seconds" , EOL;
120 // Echo memory usage
121 echo date('H:i:s') , ' Current memory usage: ' , (memory_get_usage(true) / 1024 / 1024) , " MB" , EOL;
122
123
124 // Echo memory peak usage
125 echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
126
127 // Echo done
128 echo date('H:i:s') , " Done writing file" , EOL;
129 echo 'File has been created in ' , getcwd() , EOL;