Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: Access a multi-sheet spreadsheet

$
0
0
Hi,

I need to extract information from a Excel spreadsheet, including background colour, font colour, border and content.

The file is around 5 or 6 Meg.

This is my code:
 $storagename=$_SERVER["DOCUMENT_ROOT"].'/spreadsheets/sites/default/files/spread1.xlsx';
  // This is the file path to be uploaded.
  if (file_exists($storagename)) {
    $bgcolor=array();
    $inputFileType = PHPExcel_IOFactory::identify($storagename);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);
    // Get names of worksheets in the file.
    $worksheetNames = $objReader->listWorksheetNames($storagename);
    // Print worksheet names.
    foreach ($worksheetNames as $sheetName) {
      echo '<h3>'.$sheetName.'</h3>';
      
      $objReader = PHPExcel_IOFactory::createReader('Excel2007');
      $objReader->setLoadSheetsOnly($sheetName);
      $objPHPExcel = $objReader->load($storagename);
      $objWorksheet = $objPHPExcel->getActiveSheet();
      $rownumber=0;
      foreach ($objWorksheet->getRowIterator() as $row){
        $cellIterator = $row->getCellIterator();
        $rownumber++;
        $colwidths=array();
        foreach ($cellIterator as $cell) {
          $cellcolumn=$cell->getColumn();
          $cellindex=PHPExcel_Cell::columnIndexFromString($cellcolumn);
          if (!array_key_exists($cellcolumn,$colwidths)) {
            $colwidths[$cellcolumn]= $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($cellcolumn)->getWidth();
          }
          echo '; '.$cellcolumn.$rownumber.'='.$colwidths[$cellcolumn].', #'.$bgcolor[$cellindex.'_'.$rownumber];
        }
        echo '<hr/>';
      }
    }
  }else {
    die('File not found.<hr/>');
  }
The spreadsheet has the following sheet names:
"Definitions", "SAQA", "DPSA", "PSETA", "PALAMA", "FASSET", "QCTO", "CHE (Summary)"

The first sheet has 17 columns and 40 rows.
The second sheet has 26 columns and 64 rows.
The third sheet has 6 columns and 39 rows.

The first two sheets are processed correctly.
The sheetnames "Definitions" and "SAQA" are echoed as expected. However, my /var/log/apache2/error.log file has the following error:

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 88 bytes) in /var/www/spreadsheets/sites/all/libs/Classes/PHPExcel/Style.php on line 120.

I've researched the error and I believe that the way to address this is to read a few lines at a time.

However, the spreadsheet worksheets don't seem to be overly large.

Should I be looking elsewhere?

Viewing all articles
Browse latest Browse all 2707

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>