|
@Mkersten
PHPExcel is written for a wide range of people who have different requirements when working with spreadsheets in PHP, which is why it tries to provide facilities for manipulating all aspects of cells. Cell Caching is just one mechanism that allows
us to make better use of restricted memory available to many user, but it is just one among many methods. You say that you don't need formatting information when reading your worksheets, so you could take advantage of the ReadDataOnly switch when loading a
workbook into a PHPExcel object:
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("test.xlsx");
When using this option, no formatting data is read from the workbook, so it won't use as much memory.
The only drawback with this is that the only method to distinguish between a number and a date/time in Excel is the formatting... so PHPExcel can't automatically determine if a cell contains a number or a date if this option is used. (One day,
I'll get round to modifying the loader logic to provide this date/number differentiation even when ReadDataOnly is used, but nobody has ever asked for it yet).
Other techniques are available within the loader for saving memory, such as reading in only the worksheets that you're interested in rather than every worksheet in the workbook, or only reading the cells you want from a worksheet using a read filter.
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setLoadSheetsOnly( array("Worksheet1", "Worksheet2") );
$objPHPExcel = $objReader->load("test.xlsx");
or
class MyReadFilter implements PHPExcel_Reader_IReadFilter
{
public function readCell($column, $row, $worksheetName = '') {
// Read title row and rows 20 - 30
if ($row == 1 || ($row >= 20 && $row <= 30)) {
return true;
}
return false;
}
}
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadFilter( new MyReadFilter() );
$objPHPExcel = $objReader->load("test.xlsx");
|