From 8f3640e44c08b5ad7da4fb6e5e48c53a613ca434 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Mon, 29 Oct 2012 23:48:29 +0000 Subject: [PATCH] Change reader exceptions to PHPExcel_Reader_Exception --- Classes/PHPExcel/Calculation/DateTime.php | 2 +- Classes/PHPExcel/Cell/AdvancedValueBinder.php | 4 +- Classes/PHPExcel/Reader/CSV.php | 18 ++--- Classes/PHPExcel/Reader/Excel2003XML.php | 22 +++--- Classes/PHPExcel/Reader/Excel2007.php | 18 ++--- Classes/PHPExcel/Reader/Excel5.php | 67 +++++++++--------- Classes/PHPExcel/Reader/Exception.php | 52 ++++++++++++++ Classes/PHPExcel/Reader/Gnumeric.php | 20 +++--- Classes/PHPExcel/Reader/HTML.php | 18 ++--- Classes/PHPExcel/Reader/IReader.php | 2 +- Classes/PHPExcel/Reader/OOCalc.php | 20 +++--- Classes/PHPExcel/Reader/SYLK.php | 18 ++--- Classes/PHPExcel/Shared/Date.php | 11 +-- Classes/PHPExcel/Shared/OLERead.php | 6 +- Classes/PHPExcel/Worksheet.php | 2 +- .../Examples/Reader/exampleReader16.php | 2 +- ...umentation - Reading Spreadsheet Files.doc | Bin 167936 -> 167936 bytes changelog.txt | 8 ++- 18 files changed, 167 insertions(+), 123 deletions(-) create mode 100644 Classes/PHPExcel/Reader/Exception.php diff --git a/Classes/PHPExcel/Calculation/DateTime.php b/Classes/PHPExcel/Calculation/DateTime.php index ebc9359d..a24df5c0 100644 --- a/Classes/PHPExcel/Calculation/DateTime.php +++ b/Classes/PHPExcel/Calculation/DateTime.php @@ -92,7 +92,7 @@ class PHPExcel_Calculation_DateTime { (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC)) { return PHPExcel_Calculation_Functions::VALUE(); } - if ((is_object($dateValue)) && ($dateValue instanceof PHPExcel_Shared_Date::$dateTimeObjectType)) { + if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) { $dateValue = PHPExcel_Shared_Date::PHPToExcel($dateValue); } else { $saveReturnDateType = PHPExcel_Calculation_Functions::getReturnDateType(); diff --git a/Classes/PHPExcel/Cell/AdvancedValueBinder.php b/Classes/PHPExcel/Cell/AdvancedValueBinder.php index 50a07f96..add0a57f 100644 --- a/Classes/PHPExcel/Cell/AdvancedValueBinder.php +++ b/Classes/PHPExcel/Cell/AdvancedValueBinder.php @@ -113,8 +113,8 @@ class PHPExcel_Cell_AdvancedValueBinder extends PHPExcel_Cell_DefaultValueBinder // Check for currency $currencyCode = PHPExcel_Shared_String::getCurrencyCode(); - $decimalSeparator = PHPExcel_Shared_String::getDecimalSeparator(); - $thousandsSeparator = PHPExcel_Shared_String::getThousandsSeparator(); + $decimalSeparator = PHPExcel_Shared_String::getDecimalSeparator(); + $thousandsSeparator = PHPExcel_Shared_String::getThousandsSeparator(); if (preg_match('/^'.preg_quote($currencyCode).' *(\d{1,3}('.preg_quote($thousandsSeparator).'\d{3})*|(\d+))('.preg_quote($decimalSeparator).'\d{2})?$/', $value)) { // Convert value to number $value = (float) trim(str_replace(array($currencyCode, $thousandsSeparator, $decimalSeparator), array('', '', '.'), $value)); diff --git a/Classes/PHPExcel/Reader/CSV.php b/Classes/PHPExcel/Reader/CSV.php index 8553a8b4..e8685294 100644 --- a/Classes/PHPExcel/Reader/CSV.php +++ b/Classes/PHPExcel/Reader/CSV.php @@ -124,13 +124,13 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader * @access public * @param string $pFileName * @return boolean - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function canRead($pFilename) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } return true; @@ -190,19 +190,19 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader * * @access public * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Open file $fileHandle = fopen($pFilename, 'r'); if ($fileHandle === false) { - throw new Exception("Could not open file " . $pFilename . " for reading."); + throw new PHPExcel_Reader_Exception("Could not open file " . $pFilename . " for reading."); } // Skip BOM, if any @@ -262,7 +262,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader * @access public * @param string $pFilename * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename) { @@ -281,13 +281,13 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader * @param string $pFilename * @param PHPExcel $objPHPExcel * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Create new PHPExcel @@ -302,7 +302,7 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader // Open file $fileHandle = fopen($pFilename, 'r'); if ($fileHandle === false) { - throw new Exception("Could not open file $pFilename for reading."); + throw new PHPExcel_Reader_Exception("Could not open file $pFilename for reading."); } // Skip BOM, if any diff --git a/Classes/PHPExcel/Reader/Excel2003XML.php b/Classes/PHPExcel/Reader/Excel2003XML.php index 4f6cfea5..60d51a4b 100644 --- a/Classes/PHPExcel/Reader/Excel2003XML.php +++ b/Classes/PHPExcel/Reader/Excel2003XML.php @@ -174,7 +174,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader * * @param string $pFileName * @return boolean - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function canRead($pFilename) { @@ -196,7 +196,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Read sample data (first 2 KB will do) @@ -227,16 +227,16 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } if (!$this->canRead($pFilename)) { - throw new Exception($pFilename . " is an Invalid Spreadsheet file."); + throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file."); } $worksheetNames = array(); @@ -258,13 +258,13 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $worksheetInfo = array(); @@ -330,7 +330,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader * * @param string $pFilename * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename) { @@ -392,7 +392,7 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader * @param string $pFilename * @param PHPExcel $objPHPExcel * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) { @@ -427,11 +427,11 @@ class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } if (!$this->canRead($pFilename)) { - throw new Exception($pFilename . " is an Invalid Spreadsheet file."); + throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file."); } $xml = simplexml_load_file($pFilename); diff --git a/Classes/PHPExcel/Reader/Excel2007.php b/Classes/PHPExcel/Reader/Excel2007.php index 8d45cc79..d296e921 100644 --- a/Classes/PHPExcel/Reader/Excel2007.php +++ b/Classes/PHPExcel/Reader/Excel2007.php @@ -226,18 +226,18 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader * * @param string $pFileName * @return boolean - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function canRead($pFilename) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Check if zip class exists if (!class_exists('ZipArchive',FALSE)) { - throw new Exception("ZipArchive library is not enabled"); + throw new PHPExcel_Reader_Exception("ZipArchive library is not enabled"); } $xl = false; @@ -269,13 +269,13 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $worksheetInfo = array(); @@ -439,13 +439,13 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $worksheetNames = array(); @@ -478,13 +478,13 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader * Loads PHPExcel from file * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Initialisations diff --git a/Classes/PHPExcel/Reader/Excel5.php b/Classes/PHPExcel/Reader/Excel5.php index 165eca2b..2c51014c 100644 --- a/Classes/PHPExcel/Reader/Excel5.php +++ b/Classes/PHPExcel/Reader/Excel5.php @@ -510,13 +510,13 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader * * @param string $pFileName * @return boolean - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function canRead($pFilename) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } try { @@ -526,8 +526,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader // get excel data $res = $ole->read($pFilename); return true; - - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { return false; } } @@ -537,13 +536,13 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $worksheetNames = array(); @@ -586,13 +585,13 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $worksheetInfo = array(); @@ -681,7 +680,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader * * @param string $pFilename * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename) { @@ -1648,7 +1647,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader case self::XLS_WorkbookGlobals: $version = self::_GetInt2d($recordData, 0); if (($version != self::XLS_BIFF8) && ($version != self::XLS_BIFF7)) { - throw new Exception('Cannot read this Excel file. Version is too old.'); + throw new PHPExcel_Reader_Exception('Cannot read this Excel file. Version is too old.'); } $this->_version = $version; break; @@ -1689,7 +1688,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader // move stream pointer to next record $this->_pos += 4 + $length; - throw new Exception('Cannot read encrypted file'); + throw new PHPExcel_Reader_Exception('Cannot read encrypted file'); } @@ -2635,7 +2634,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader try { $formula = $this->_getFormulaFromStructure($formulaStructure); - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { $formula = ''; } @@ -3777,12 +3776,12 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader // add cell value. If we can read formula, populate with formula, otherwise just used cached value try { if ($this->_version != self::XLS_BIFF8) { - throw new Exception('Not BIFF8. Can only read BIFF8 formulas'); + throw new PHPExcel_Reader_Exception('Not BIFF8. Can only read BIFF8 formulas'); } $formula = $this->_getFormulaFromStructure($formulaStructure); // get formula in human language $cell->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA); - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { $cell->setValueExplicit($value, $dataType); } } else { @@ -4299,7 +4298,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader // offset: 0; size: 8; cell range address of all cells containing this hyperlink try { $cellRange = $this->_readBIFF8CellRangeAddressFixed($recordData, 0, 8); - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { return; } @@ -4583,7 +4582,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader if ($type == PHPExcel_Cell_DataValidation::TYPE_LIST) { $formula1 = str_replace(chr(0), ',', $formula1); } - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { return; } $offset += $sz1; @@ -4600,7 +4599,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader $formula2 = pack('v', $sz2) . $formula2; // prepend the length try { $formula2 = $this->_getFormulaFromStructure($formula2); - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { return; } $offset += $sz2; @@ -4812,7 +4811,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader for ($i = 0; $i < $cref; ++$i) { try { $cellRange = $this->_readBIFF8CellRangeAddressFixed(substr($recordData, 27 + 8 * $i, 8)); - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { return; } $cellRanges[] = $cellRange; @@ -5244,7 +5243,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader * @param string Formula data * @param string $baseCell Base cell, only needed when formula contains tRefN tokens, e.g. with shared formulas * @return array - * @throws Exception + * @throws PHPExcel_Reader_Exception */ private function _getNextToken($formulaData, $baseCell = 'A1') { @@ -5345,7 +5344,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader $spacetype = 'type5'; break; default: - throw new Exception('Unrecognized space type in tAttrSpace token'); + throw new PHPExcel_Reader_Exception('Unrecognized space type in tAttrSpace token'); break; } // offset: 3; size: 1; number of inserted spaces/carriage returns @@ -5354,7 +5353,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader $data = array('spacetype' => $spacetype, 'spacecount' => $spacecount); break; default: - throw new Exception('Unrecognized attribute flag in tAttr token'); + throw new PHPExcel_Reader_Exception('Unrecognized attribute flag in tAttr token'); break; } break; @@ -5559,7 +5558,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader case 360: $function = 'PHONETIC'; $args = 1; break; case 368: $function = 'BAHTTEXT'; $args = 1; break; default: - throw new Exception('Unrecognized function in formula'); + throw new PHPExcel_Reader_Exception('Unrecognized function in formula'); break; } $data = array('function' => $function, 'args' => $args); @@ -5663,7 +5662,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader case 366: $function = 'STDEVA'; break; case 367: $function = 'VARA'; break; default: - throw new Exception('Unrecognized function in formula'); + throw new PHPExcel_Reader_Exception('Unrecognized function in formula'); break; } $data = array('function' => $function, 'args' => $args); @@ -5764,7 +5763,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader $cellAddress = $this->_readBIFF8CellAddress(substr($formulaData, 3, 4)); $data = "$sheetRange!$cellAddress"; - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { // deleted sheet reference $data = '#REF!'; } @@ -5783,7 +5782,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader $cellRangeAddress = $this->_readBIFF8CellRangeAddress(substr($formulaData, 3, 8)); $data = "$sheetRange!$cellRangeAddress"; - } catch (Exception $e) { + } catch (PHPExcel_Reader_Exception $e) { // deleted sheet reference $data = '#REF!'; } @@ -5791,7 +5790,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader break; // Unknown cases // don't know how to deal with default: - throw new Exception('Unrecognized token ' . sprintf('%02X', $id) . ' in formula'); + throw new PHPExcel_Reader_Exception('Unrecognized token ' . sprintf('%02X', $id) . ' in formula'); break; } @@ -5885,7 +5884,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader * * @param string $subData * @return string - * @throws Exception + * @throws PHPExcel_Reader_Exception */ private function _readBIFF5CellRangeAddressFixed($subData) { @@ -5903,7 +5902,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader // check values if ($fr > $lr || $fc > $lc) { - throw new Exception('Not a cell range address'); + throw new PHPExcel_Reader_Exception('Not a cell range address'); } // column index to letter @@ -5924,7 +5923,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader * * @param string $subData * @return string - * @throws Exception + * @throws PHPExcel_Reader_Exception */ private function _readBIFF8CellRangeAddressFixed($subData) { @@ -5942,7 +5941,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader // check values if ($fr > $lr || $fc > $lc) { - throw new Exception('Not a cell range address'); + throw new PHPExcel_Reader_Exception('Not a cell range address'); } // column index to letter @@ -6152,11 +6151,11 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader * Get a sheet range like Sheet1:Sheet3 from REF index * Note: If there is only one sheet in the range, one gets e.g Sheet1 * It can also happen that the REF structure uses the -1 (FFFF) code to indicate deleted sheets, - * in which case an exception is thrown + * in which case an PHPExcel_Reader_Exception is thrown * * @param int $index * @return string|false - * @throws Exception + * @throws PHPExcel_Reader_Exception */ private function _readSheetRangeByRefIndex($index) { @@ -6168,7 +6167,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader case 'internal': // check if we have a deleted 3d reference if ($this->_ref[$index]['firstSheetIndex'] == 0xFFFF or $this->_ref[$index]['lastSheetIndex'] == 0xFFFF) { - throw new Exception('Deleted sheet reference'); + throw new PHPExcel_Reader_Exception('Deleted sheet reference'); } // we have normal sheet range (collapsed or uncollapsed) @@ -6198,7 +6197,7 @@ class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader default: // TODO: external sheet support - throw new Exception('Excel5 reader only supports internal sheets in fomulas'); + throw new PHPExcel_Reader_Exception('Excel5 reader only supports internal sheets in fomulas'); break; } } diff --git a/Classes/PHPExcel/Reader/Exception.php b/Classes/PHPExcel/Reader/Exception.php new file mode 100644 index 00000000..8180dce9 --- /dev/null +++ b/Classes/PHPExcel/Reader/Exception.php @@ -0,0 +1,52 @@ +line = $line; + $e->file = $file; + throw $e; + } +} diff --git a/Classes/PHPExcel/Reader/Gnumeric.php b/Classes/PHPExcel/Reader/Gnumeric.php index 355e71cd..3f1e4532 100644 --- a/Classes/PHPExcel/Reader/Gnumeric.php +++ b/Classes/PHPExcel/Reader/Gnumeric.php @@ -191,18 +191,18 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader * * @param string $pFileName * @return boolean - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function canRead($pFilename) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Check if gzlib functions are available if (!function_exists('gzread')) { - throw new Exception("gzlib library is not enabled"); + throw new PHPExcel_Reader_Exception("gzlib library is not enabled"); } // Read signature data (first 3 bytes) @@ -222,13 +222,13 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $gFileData = $this->_gzfileGetContents($pFilename); @@ -286,7 +286,7 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader * * @param string $pFilename * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename) { @@ -302,13 +302,13 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $gFileData = $this->_gzfileGetContents($pFilename); @@ -334,13 +334,13 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader * @param string $pFilename * @param PHPExcel $objPHPExcel * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $timezoneObj = new DateTimeZone('Europe/London'); diff --git a/Classes/PHPExcel/Reader/HTML.php b/Classes/PHPExcel/Reader/HTML.php index 0bb7ec1a..1d1c4e3a 100644 --- a/Classes/PHPExcel/Reader/HTML.php +++ b/Classes/PHPExcel/Reader/HTML.php @@ -120,13 +120,13 @@ class PHPExcel_Reader_HTML implements PHPExcel_Reader_IReader * * @param string $pFileName * @return boolean - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function canRead($pFilename) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Read sample data (first 2 KB will do) @@ -147,7 +147,7 @@ class PHPExcel_Reader_HTML implements PHPExcel_Reader_IReader * * @param string $pFilename * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename) { @@ -243,7 +243,7 @@ class PHPExcel_Reader_HTML implements PHPExcel_Reader_IReader private function _processDomElement(DOMNode $element, $sheet, &$row, &$column, &$cellContent){ foreach($element->childNodes as $child){ - if ($child instanceOf DOMText) { + if ($child instanceof DOMText) { $domText = preg_replace('/\s+/',' ',trim($child->nodeValue)); if (is_string($cellContent)) { // simply append the text if the cell content is a plain text string @@ -252,7 +252,7 @@ class PHPExcel_Reader_HTML implements PHPExcel_Reader_IReader // but if we have a rich text run instead, we need to append it correctly // TODO } - } elseif($child instanceOf DOMElement) { + } elseif($child instanceof DOMElement) { echo 'DOM ELEMENT: ' , strtoupper($child->nodeName) , '
'; $attributeArray = array(); @@ -438,17 +438,17 @@ class PHPExcel_Reader_HTML implements PHPExcel_Reader_IReader * @param string $pFilename * @param PHPExcel $objPHPExcel * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } if (!is_file($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! The given file is not a regular file."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! The given file is not a regular file."); } // Create new PHPExcel @@ -462,7 +462,7 @@ class PHPExcel_Reader_HTML implements PHPExcel_Reader_IReader // Load the HTML file into the DOM object $loaded = $dom->loadHTMLFile($pFilename); if ($loaded === false) { - throw new Exception('Failed to load ',$pFilename,' as a DOM Document'); + throw new PHPExcel_Reader_Exception('Failed to load ',$pFilename,' as a DOM Document'); } // Discard white space diff --git a/Classes/PHPExcel/Reader/IReader.php b/Classes/PHPExcel/Reader/IReader.php index e36495e8..c26f1d40 100644 --- a/Classes/PHPExcel/Reader/IReader.php +++ b/Classes/PHPExcel/Reader/IReader.php @@ -47,7 +47,7 @@ interface PHPExcel_Reader_IReader * Loads PHPExcel from file * * @param string $pFileName - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename); } diff --git a/Classes/PHPExcel/Reader/OOCalc.php b/Classes/PHPExcel/Reader/OOCalc.php index ab3023ed..f504e40c 100644 --- a/Classes/PHPExcel/Reader/OOCalc.php +++ b/Classes/PHPExcel/Reader/OOCalc.php @@ -180,18 +180,18 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader * * @param string $pFileName * @return boolean - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function canRead($pFilename) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Check if zip class exists if (!class_exists('ZipArchive',FALSE)) { - throw new Exception("ZipArchive library is not enabled"); + throw new PHPExcel_Reader_Exception("ZipArchive library is not enabled"); } // Load file @@ -219,13 +219,13 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $worksheetNames = array(); @@ -256,7 +256,7 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader * * @param string $pFilename * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename) { @@ -284,13 +284,13 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $worksheetInfo = array(); @@ -358,13 +358,13 @@ class PHPExcel_Reader_OOCalc implements PHPExcel_Reader_IReader * @param string $pFilename * @param PHPExcel $objPHPExcel * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } $timezoneObj = new DateTimeZone('Europe/London'); diff --git a/Classes/PHPExcel/Reader/SYLK.php b/Classes/PHPExcel/Reader/SYLK.php index 6aae7528..4b5d892b 100644 --- a/Classes/PHPExcel/Reader/SYLK.php +++ b/Classes/PHPExcel/Reader/SYLK.php @@ -93,13 +93,13 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader * * @param string $pFileName * @return boolean - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function canRead($pFilename) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Read sample data (first 2 KB will do) @@ -171,19 +171,19 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * * @param string $pFilename - * @throws Exception + * @throws PHPExcel_Reader_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."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Open file $fileHandle = fopen($pFilename, 'r'); if ($fileHandle === false) { - throw new Exception("Could not open file " . $pFilename . " for reading."); + throw new PHPExcel_Reader_Exception("Could not open file " . $pFilename . " for reading."); } $worksheetInfo = array(); @@ -244,7 +244,7 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader * * @param string $pFilename * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function load($pFilename) { @@ -262,13 +262,13 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader * @param string $pFilename * @param PHPExcel $objPHPExcel * @return PHPExcel - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel) { // Check if file exists if (!file_exists($pFilename)) { - throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); + throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist."); } // Create new PHPExcel @@ -283,7 +283,7 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader // Open file $fileHandle = fopen($pFilename, 'r'); if ($fileHandle === false) { - throw new Exception("Could not open file $pFilename for reading."); + throw new PHPExcel_Reader_Exception("Could not open file $pFilename for reading."); } // Loop through file diff --git a/Classes/PHPExcel/Shared/Date.php b/Classes/PHPExcel/Shared/Date.php index 1507d588..6043bd37 100644 --- a/Classes/PHPExcel/Shared/Date.php +++ b/Classes/PHPExcel/Shared/Date.php @@ -69,15 +69,6 @@ class PHPExcel_Shared_Date */ private static $ExcelBaseDate = self::CALENDAR_WINDOWS_1900; - /* - * Object type for PHP Date/Time values - * - * @private - * @var string - */ - public static $dateTimeObjectType = 'DateTime'; - - /** * Set the Excel calendar (Windows 1900 or Mac 1904) * @@ -172,7 +163,7 @@ class PHPExcel_Shared_Date $saveTimeZone = date_default_timezone_get(); date_default_timezone_set('UTC'); $retValue = FALSE; - if ((is_object($dateValue)) && ($dateValue instanceof self::$dateTimeObjectType)) { + if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) { $retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'), $dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s') ); diff --git a/Classes/PHPExcel/Shared/OLERead.php b/Classes/PHPExcel/Shared/OLERead.php index 5e72ccfb..be672b18 100644 --- a/Classes/PHPExcel/Shared/OLERead.php +++ b/Classes/PHPExcel/Shared/OLERead.php @@ -70,13 +70,13 @@ class PHPExcel_Shared_OLERead { * Read the file * * @param $sFileName string Filename - * @throws Exception + * @throws PHPExcel_Reader_Exception */ public function read($sFileName) { // Check if file exists and is readable if(!is_readable($sFileName)) { - throw new Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable."); + throw new PHPExcel_Reader_Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable."); } // Get the file data @@ -84,7 +84,7 @@ class PHPExcel_Shared_OLERead { // Check OLE identifier if (substr($this->data, 0, 8) != self::IDENTIFIER_OLE) { - throw new Exception('The filename ' . $sFileName . ' is not recognised as an OLE file'); + throw new PHPExcel_Reader_Exception('The filename ' . $sFileName . ' is not recognised as an OLE file'); } // Total number of sectors used for the SAT diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 00f68fd5..8964dff5 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -2782,7 +2782,7 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable } elseif ($key == '_drawingCollection') { $newCollection = clone $this->_drawingCollection; $this->_drawingCollection = $newCollection; - } elseif (($key == '_autoFilter') && (is_a($this->_autoFilter,'PHPExcel_Worksheet_AutoFilter'))) { + } elseif (($key == '_autoFilter') && ($this->_autoFilter instanceof PHPExcel_Worksheet_AutoFilter)) { $newAutoFilter = clone $this->_autoFilter; $this->_autoFilter = $newAutoFilter; $this->_autoFilter->setParent($this); diff --git a/Documentation/Examples/Reader/exampleReader16.php b/Documentation/Examples/Reader/exampleReader16.php index 0542006a..62d82ea9 100644 --- a/Documentation/Examples/Reader/exampleReader16.php +++ b/Documentation/Examples/Reader/exampleReader16.php @@ -30,7 +30,7 @@ $inputFileName = './sampleData/example_1.xls'; echo 'Loading file ',pathinfo($inputFileName,PATHINFO_BASENAME),' using IOFactory to identify the format
'; try { $objPHPExcel = PHPExcel_IOFactory::load($inputFileName); -} catch(Exception $e) { +} catch(PHPExcel_Reader_Exception $e) { die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); } diff --git a/Documentation/PHPExcel User Documentation - Reading Spreadsheet Files.doc b/Documentation/PHPExcel User Documentation - Reading Spreadsheet Files.doc index 206f2f22d04e4bcb905c62eac58bb586f9474965..221f44bad45fbf02ca6b0cb64d8cac8868580b9b 100644 GIT binary patch delta 3098 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 cik==97Z;tFWHDQ3TjG