Problem with an xls' file --> Fatal error: Call to a member function setTime() on a non-object

Topics: Developer Forum, Project Management Forum, User Forum
Oct 11, 2012 at 10:07 PM
Edited Oct 11, 2012 at 10:09 PM

Hi,

I have a strange problem with the exemple PHPExcel's files and a specific excel's file.

 

It return this error : 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

PHPExcel Reader Example #04

Simple File Reader using the PHPExcel_IOFactory to Identify a Reader to Use

File NewStock.xls has been identified as an Excel5 file
Loading file NewStock.xls using IOFactory with the identified reader type



Fatal error: Call to a member function setTime() on a non-object in /Applications/MAMP/htdocs/soapmagento/Classes/PHPExcel/Shared/Date.php on line 158

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 

This xls file has some macros, but i have deleting the macros and save, but no success... I was trying with Openoffice and Excel...

If i test with some others xls' files i cant' repeat the problem... I really don't understand and i can't use a other xls' file because it come from my wholesaler...

 

Do you have any idea or solution ?

 

Thank you so much !

Oct 11, 2012 at 10:33 PM

I have more information... 

I found that the problem come from a column... The cells' column's values start with an apostrophe. If i delete this colmun there isn't any problem...

How can i do ? Because i don't want to lost time each day to download the file and delete the column before update my db...

 

Thanks! 

Oct 12, 2012 at 7:10 PM

The apostrophe indicates that the cell's value is a string.

If you are using the getValue() method to retrieve the cell's content then try using getFormattedValue() instead. That might sidestep the issue although it doesn't really solve it.

- Christopher Mullins

Oct 15, 2012 at 5:20 PM

Thanks for your answer.

 

But it's not working...

 

Here is my code :

<?php

error_reporting(E_ALL);
set_time_limit(0);

date_default_timezone_set('Europe/London');

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>PHPExcel Reader Example #01</title>

</head>
<body>

<h1>PHPExcel Reader Example #01</h1>
<h2>Simple File Reader using PHPExcel_IOFactory::load()</h2>
<?php

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';



//var_dump($sheetData);


class MyReadFilter implements PHPExcel_Reader_IReadFilter
{

	public function readCell($column, $row, $worksheetName = '') {
		
		// Read title row and rows 20 - 30
		if ($row > 1) {
			return true;
		}
			return false;
	}
}

$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadFilter( new MyReadFilter() );
$objPHPExcel = $objReader->load("../../../NewStock.xls");
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);

//var_dump($sheetData);

?>

<?php
$objReader = new PHPExcel_Reader_Excel5();
$objReader->setReadDataOnly(true);

$objPHPExcel = $objReader->load("sampleData/example1.xls");
$objWorksheet = $objPHPExcel->getActiveSheet();

echo '<table>' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
  echo '<tr>' . "\n";
		
  $cellIterator = $row->getCellIterator();
  $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
                                                     // even if it is not set.
                                                     // By default, only cells
                                                     // that are set will be
                                                     // iterated.
  foreach ($cellIterator as $cell) {
    echo '<td>' . $cell->getFormattedValue() . '</td>' . "\n";
  }
  
  echo '</tr>' . "\n";
}
echo '</table>' . "\n";

//var_dump($objWorksheet);
//echo "test".$cell();
//var_dump($cell->getFormattedValue(2));
?>

<body>
</html>

 

What i did wrong ?

 

Thanks !