/var/www/enzatesting.onesolution.hk/inc/phpexcel_1.7.7/PHPExcel/Reader/Excel2003XML.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/**
 * PHPExcel
 *
 * Copyright (c) 2006 - 2012 PHPExcel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPExcel
 * @package    PHPExcel_Reader
 * @copyright  Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 * @version    1.7.7, 2012-05-19
 */


/** PHPExcel root directory */
if (!defined('PHPEXCEL_ROOT')) {
    
/**
     * @ignore
     */
    
define('PHPEXCEL_ROOT'dirname(__FILE__) . '/../../');
    require(
PHPEXCEL_ROOT 'PHPExcel/Autoloader.php');
}

/**
 * PHPExcel_Reader_Excel2003XML
 *
 * @category   PHPExcel
 * @package    PHPExcel_Reader
 * @copyright  Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
 */
class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
{
    
/**
     * Read data only?
     *
     * @var boolean
     */
    
private $_readDataOnly false;

    
/**
     * Restict which sheets should be loaded?
     *
     * @var array
     */
    
private $_loadSheetsOnly null;

    
/**
     * Formats
     *
     * @var array
     */
    
private $_styles = array();

    
/**
     * PHPExcel_Reader_IReadFilter instance
     *
     * @var PHPExcel_Reader_IReadFilter
     */
    
private $_readFilter null;

    
/**
     * Character set used in the file
     *
     * @var string
     */
    
private $_charSet 'UTF-8';


    
/**
     * Create a new PHPExcel_Reader_Excel2003XML
     */
    
public function __construct() {
        
$this->_readFilter     = new PHPExcel_Reader_DefaultReadFilter();
    }


    
/**
     * Read data only?
     *
     * @return boolean
     */
    
public function getReadDataOnly() {
        return 
$this->_readDataOnly;
    }


    
/**
     * Set read data only
     *
     * @param boolean $pValue
     * @return PHPExcel_Reader_Excel2003XML
     */
    
public function setReadDataOnly($pValue false) {
        
$this->_readDataOnly $pValue;
        return 
$this;
    }


    
/**
     * Get which sheets to load
     *
     * @return mixed
     */
    
public function getLoadSheetsOnly()
    {
        return 
$this->_loadSheetsOnly;
    }


    
/**
     * Set which sheets to load
     *
     * @param mixed $value
     * @return PHPExcel_Reader_Excel2003XML
     */
    
public function setLoadSheetsOnly($value null)
    {
        
$this->_loadSheetsOnly is_array($value) ?
            
$value : array($value);
        return 
$this;
    }


    
/**
     * Set all sheets to load
     *
     * @return PHPExcel_Reader_Excel2003XML
     */
    
public function setLoadAllSheets()
    {
        
$this->_loadSheetsOnly null;
        return 
$this;
    }


    
/**
     * Read filter
     *
     * @return PHPExcel_Reader_IReadFilter
     */
    
public function getReadFilter() {
        return 
$this->_readFilter;
    }


    
/**
     * Set read filter
     *
     * @param PHPExcel_Reader_IReadFilter $pValue
     * @return PHPExcel_Reader_Excel2003XML
     */
    
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
        
$this->_readFilter $pValue;
        return 
$this;
    }


    
/**
     * Can the current PHPExcel_Reader_IReader read the file?
     *
     * @param     string         $pFileName
     * @return     boolean
     * @throws Exception
     */
    
public function canRead($pFilename)
    {

        
//    Office                    xmlns:o="urn:schemas-microsoft-com:office:office"
        //    Excel                    xmlns:x="urn:schemas-microsoft-com:office:excel"
        //    XML Spreadsheet            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
        //    Spreadsheet component    xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
        //    XML schema                 xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
        //    XML data type            xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
        //    MS-persist recordset    xmlns:rs="urn:schemas-microsoft-com:rowset"
        //    Rowset                    xmlns:z="#RowsetSchema"
        //

        
$signature = array(
                
'<?xml version="1.0"',
                
'<?mso-application progid="Excel.Sheet"?>'
            
);

        
// Check if file exists
        
if (!file_exists($pFilename)) {
            throw new 
Exception("Could not open " $pFilename " for reading! File does not exist.");
        }

        
// Read sample data (first 2 KB will do)
        
$fh fopen($pFilename'r');
        
$data fread($fh2048);
        
fclose($fh);

        
$valid true;
        foreach(
$signature as $match) {
            
// every part of the signature must be present
            
if (strpos($data$match) === false) {
                
$valid false;
                break;
            }
        }

        
//    Retrieve charset encoding
        
if(preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/um',$data,$matches)) {
            
$this->_charSet strtoupper($matches[1]);
        }
//        echo 'Character Set is ',$this->_charSet,'<br />';

        
return $valid;
    }


    
/**
     * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
     *
     * @param     string         $pFilename
     * @throws     Exception
     */
    
public function listWorksheetNames($pFilename)
    {
        
// Check if file exists
        
if (!file_exists($pFilename)) {
            throw new 
Exception("Could not open " $pFilename " for reading! File does not exist.");
        }
        if (!
$this->canRead($pFilename)) {
            throw new 
Exception($pFilename " is an Invalid Spreadsheet file.");
        }

        
$worksheetNames = array();

        
$xml simplexml_load_file($pFilename);
        
$namespaces $xml->getNamespaces(true);

        
$xml_ss $xml->children($namespaces['ss']);
        foreach(
$xml_ss->Worksheet as $worksheet) {
            
$worksheet_ss $worksheet->attributes($namespaces['ss']);
            
$worksheetNames[] = self::_convertStringEncoding((string) $worksheet_ss['Name'],$this->_charSet);
        }

        return 
$worksheetNames;
    }


    
/**
     * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
     *
     * @param   string     $pFilename
     * @throws   Exception
     */
    
public function listWorksheetInfo($pFilename)
    {
        
// Check if file exists
        
if (!file_exists($pFilename)) {
            throw new 
Exception("Could not open " $pFilename " for reading! File does not exist.");
        }

        
$worksheetInfo = array();

        
$xml simplexml_load_file($pFilename);
        
$namespaces $xml->getNamespaces(true);

        
$worksheetID 1;
        
$xml_ss $xml->children($namespaces['ss']);
        foreach(
$xml_ss->Worksheet as $worksheet) {
            
$worksheet_ss $worksheet->attributes($namespaces['ss']);

            
$tmpInfo = array();
            
$tmpInfo['worksheetName'] = '';
            
$tmpInfo['lastColumnLetter'] = 'A';
            
$tmpInfo['lastColumnIndex'] = 0;
            
$tmpInfo['totalRows'] = 0;
            
$tmpInfo['totalColumns'] = 0;

            if (isset(
$worksheet_