Hi,

getting:
PHP Fatal error: Call to a member function detach() on a non-object in /home/user/www/site/sites/all/libraries/PHPExcel/Classes/PHPExcel/CachedObjectStorage/MemoryGZip.php on line 47

code to export xls:

  module_load_include('inc', 'phpexcel', 'phpexcel');
  $export = array('1' => 'id1','2' => 'id2');
  $headers['export'] = array_keys($export);
  $data['export'][] = array_values($export);
  $path = 'sites/default/files/export.xls';
  $options = array('format' => 'xls');
  if (phpexcel_export($headers, $data, $path, $options)) {
    drupal_set_message(t('exported'));
  }  

using Github downloaded lib, v 1.7.9

Comments

wadmiraal’s picture

Status: Active » Postponed (maintainer needs more info)

Have you checked the return value ? The return value is no longer a boolean from 3.x onward, but an integer. Each integer corresponds to an error. I have to document each value, but you can check the phpexcel.inc file for now, and check the constants defined at the start of the file.

wizardfish’s picture

same problem here, and can't see return value as it doesn't make it that far.

tried alechko's code and getting same error.

wadmiraal’s picture

I tried the exact code above and it works just fine.

What version of the module are you using ?

Can you try commenting out this block of code from the phpexcel.inc file (at line 75):

// Can we use Memcache ?
$memcache = variable_get('phpexcel_memcache', FALSE);
	
if (empty($memcache) || !$cache_method = PHPExcel_CachedObjectStorageFactory::cache_to_memcache) {
  $cache_method = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
		
  $cache_settings = array();
}
else {
  $cache_settings = array('memcacheServer'  => $memcache);
}
  
PHPExcel_Settings::setCacheStorageMethod($cache_method, $cache_settings);

This sets an internal caching mechanism for better performance. It might be related.

It might be a PHP extension that's missing. But that would surprise me, as this module has been running smoothly on all kinds of servers - including shared hosts.

wizardfish’s picture

Thanks very much for the timely reply wadmiraal. Blocking out that code worked.

I'm using PHPExcel 7.x-3.2
libraries 1.7.9 from Github
and PHP 5.3 on WAMPSERVER 2.0

wadmiraal’s picture

Ok.

On the latest version, there's a new default caching mechanism. It might remove that error. This is the default behavior of PHPExcel (library). If the error remains, it might be related to the PHPExcel Library (and not the module).

There's also a new admin page (admin/config/system/phpexcel), where you can specify what caching mechanism you want to use. See #1777560: Expose PHPExcel caching options.

Does updating to the new version help ?

wadmiraal’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.