I have a large excel file (two worksheets of ~4000 rows and columns out to AF). The excel table is formatted terribly, and I have no control over it. There are hundreds of blank columns going all the way out to XFC.
How can I have PHPExcel choose which columns it reads/writes based on the code, below? I tried using what the documentation said, but it obviously isn't working.
Code:
<?php
require('./Classes/PHPExcel/IOFactory.php');
ini_set('max_execution_time', 800);
ini_set('memory_limit', 200M);
$inputFileType = 'Excel2007';
$inputFileName = $_FILES['uploaded']['tmp_name'];
//٧٧ this is what documentation suggested ٧٧//
class MyReadFilter implements PHPExcel_Reader_IReadFilter {
public function readCell($column, $row, $worksheetName = '') {
// Read columns from 'A' to 'AF'
if ($column >= '0' && $column <= '32'){
return true;
}
return false;
}
}
//^^this is what documentation suggested^^//
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcelReader = $objReader->load($inputFileName);
$loadedSheetNames = $objPHPExcelReader->getSheetNames();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcelReader, 'CSV');
foreach($loadedSheetNames as $sheetIndex => $loadedSheetName) {
$objWriter->setSheetIndex($sheetIndex);
$objWriter->save('abc.csv');}
$files = fopen('abc.csv', 'r');
while (($line = fgetcsv($files)) !== FALSE) {
$csv_array[] = array_combine(range(1, count($line)), array_values($line));
}
?>