Issue
I've downloaded PHPExcel 1.7.5 Production.
I would like to use setReadDataOnly() and enableMemoryOptimization() as discussed in their forum here and in stackoverflow questions.
However when I use them, I get a Call to undefined method
error.
Is there another version or some plugin or library that I have not installed? What do I have to do to access these methods?
$objPHPExcel = PHPExcel_IOFactory::load("data/".$file_name);
$objPHPExcel->setReadDataOnly(true); //Call to undefined method
$objPHPExcel->enableMemoryOptimization(); //Call to undefined method
Solution
You've already identified why setReadDataOnly() isn't working.
enableMemoryOptimization() is not a valid method for any class within PHPExcel. If you wish to optimise memory, you enable one of the cell cacheing methods before loading any file or instantiating a new PHPExcel object.
$inputFileType = 'Excel2007';
$inputFileName = 'testBook.xlsx';
$r = PHPExcel_CachedObjectStorageFactory::initialize(PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp);
if (!$r) {
die('Unable to set cell cacheing');
}
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
EDIT
The thread on enableMemoryOptimization() that you link to in your question is from a user who wanted this built into PHPExcel in a way that broke most of the class's functionality, while improving performance for his specific use case (at the expense of most other users); and which would have resulted in two incompatible methods for manipulating data within the library. As such, I rejected it.
Answered By - Mark Baker Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.