ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
39dropdown.php
Go to the documentation of this file.
1<?php
29error_reporting(E_ALL);
30ini_set('display_errors', TRUE);
31ini_set('display_startup_errors', TRUE);
32date_default_timezone_set('Europe/London');
33
34define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
35
37require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
38
39
40// Create new PHPExcel object
41echo date('H:i:s') , " Create new PHPExcel object" , EOL;
43
44// Set document properties
45echo date('H:i:s') , " Set document properties" , EOL;
46$objPHPExcel->getProperties()
47 ->setCreator("PHPOffice")
48 ->setLastModifiedBy("PHPOffice")
49 ->setTitle("PHPExcel Test Document")
50 ->setSubject("PHPExcel Test Document")
51 ->setDescription("Test document for PHPExcel, generated using PHP classes.")
52 ->setKeywords("Office PHPExcel php")
53 ->setCategory("Test result file");
54
55
56function transpose($value) {
57 return array($value);
58}
59
60// Add some data
62$column = 'F';
63
64// Set data for dropdowns
65foreach(glob('./data/continents/*') as $key => $filename) {
66 $continent = pathinfo($filename, PATHINFO_FILENAME);
67 echo "Loading $continent", EOL;
68 $continent = str_replace(' ','_',$continent);
69 $countries = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
70 $countryCount = count($countries);
71
72 // Transpose $countries from a row to a column array
73 $countries = array_map('transpose', $countries);
74 $objPHPExcel->getActiveSheet()
75 ->fromArray($countries, null, $column . '1');
76 $objPHPExcel->addNamedRange(
78 $continent,
79 $objPHPExcel->getActiveSheet(), $column . '1:' . $column . $countryCount
80 )
81 );
82 $objPHPExcel->getActiveSheet()
83 ->getColumnDimension($column)
84 ->setVisible(false);
85
86 $objPHPExcel->getActiveSheet()
87 ->setCellValue($continentColumn . ($key+1), $continent);
88
89 ++$column;
90}
91
92// Hide the dropdown data
93$objPHPExcel->getActiveSheet()
94 ->getColumnDimension($continentColumn)
95 ->setVisible(false);
96
97$objPHPExcel->addNamedRange(
99 'Continents',
100 $objPHPExcel->getActiveSheet(), $continentColumn . '1:' . $continentColumn . ($key+1)
101 )
102);
103
104
105// Set selection cells
106$objPHPExcel->getActiveSheet()
107 ->setCellValue('A1', 'Continent:');
108$objPHPExcel->getActiveSheet()
109 ->setCellValue('B1', 'Select continent');
110$objPHPExcel->getActiveSheet()
111 ->setCellValue('B3', '=' . $column . 1);
112$objPHPExcel->getActiveSheet()
113 ->setCellValue('B3', 'Select country');
114$objPHPExcel->getActiveSheet()
115 ->getStyle('A1:A3')
116 ->getFont()->setBold(true);
117
118// Set linked validators
119$objValidation = $objPHPExcel->getActiveSheet()
120 ->getCell('B1')
121 ->getDataValidation();
124 ->setAllowBlank(false)
125 ->setShowInputMessage(true)
126 ->setShowErrorMessage(true)
127 ->setShowDropDown(true)
128 ->setErrorTitle('Input error')
129 ->setError('Continent is not in the list.')
130 ->setPromptTitle('Pick from the list')
131 ->setPrompt('Please pick a continent from the drop-down list.')
132 ->setFormula1('=Continents');
133
134$objPHPExcel->getActiveSheet()
135 ->setCellValue('A3', 'Country:');
136$objPHPExcel->getActiveSheet()
137 ->getStyle('A3')
138 ->getFont()->setBold(true);
139
140$objValidation = $objPHPExcel->getActiveSheet()
141 ->getCell('B3')
142 ->getDataValidation();
145 ->setAllowBlank(false)
146 ->setShowInputMessage(true)
147 ->setShowErrorMessage(true)
148 ->setShowDropDown(true)
149 ->setErrorTitle('Input error')
150 ->setError('Country is not in the list.')
151 ->setPromptTitle('Pick from the list')
152 ->setPrompt('Please pick a country from the drop-down list.')
153 ->setFormula1('=INDIRECT($B$1)');
154
155
156$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(12);
157$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
158
159
160// Set active sheet index to the first sheet, so Excel opens this as the first sheet
161$objPHPExcel->setActiveSheetIndex(0);
162
163// Save Excel 2007 file
164// This linked validation list method only seems to work for Excel2007, not for Excel5
165echo date('H:i:s') , " Write to Excel2007 format" , EOL;
167$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
168echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;
169
170// Echo memory peak usage
171echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;
172
173// Echo done
174echo date('H:i:s') , " Done writing files" , EOL;
175echo 'Files have been created in ' , getcwd() , EOL;
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
transpose($value)
Definition: 39dropdown.php:56
memory_get_peak_usage(true)/1024/1024)
Definition: 39dropdown.php:171
const EOL
Definition: 39dropdown.php:34
$objValidation
Definition: 39dropdown.php:119
$column
Definition: 39dropdown.php:62
$continentColumn
Definition: 39dropdown.php:61
$objWriter
Definition: 39dropdown.php:166
$objPHPExcel
Definition: 39dropdown.php:42
An exception for terminatinating execution or to throw for unit testing.
static createWriter(PHPExcel $phpExcel, $writerType='')
Create PHPExcel_Writer_IWriter.
Definition: IOFactory.php:132
$key
Definition: croninfo.php:18