5

I found code on how to Read Excel File Data in PHP using PHPExcelReader. It says here that it supports both for xls and xlsx file. However when viewing for xlsx file it says that the file is not readable. It only work when viewing xls file. Is there anything I can add at my code to make it readable for xlsx file too? I've also tried searching for answers in the web but it is still readable. Please help me thank you.

<?php
$filename = "uploads/$filename";
$excel_file = $filename;
$sheet_data = '';         
$table_output = array();  

$max_rows = 0;        
$max_cols = 0;        
$force_nobr = 0;      

require_once 'excel_reader.php';       
$excel = new PhpExcelReader();
$excel->setOutputEncoding('UTF-8');    
$excel->read($excel_file);       
$nr_sheets = count($excel->sheets);       


function make_alpha_from_numbers($number) {
  $numeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if($number<strlen($numeric)) return $numeric[$number];
  else {
    $dev_by = floor($number/strlen($numeric));
    return make_alpha_from_numbers($dev_by-1) .    
    make_alpha_from_numbers($number-($dev_by*strlen($numeric)));
  }
}

2 Answers 2

2

I think that the reason why you can't read .xslx files is because you don't have the PHP extension 'php_zip' enabled.

Sign up to request clarification or add additional context in comments.

Comments

1

It looks like the coursesweb site wrapped PHPExcel in their own package for that course. I would recommend getting the official copy and latest version here: https://github.com/PHPOffice/PHPExcel

Click on the wiki tab for documentation, or visit: https://phpexcel.codeplex.com

By the way, xlsx files require PHP extension php_zip. Check out the Getting Started document for other requirements.

I use PHPExcel to read and write xlsx files. There is a bit of a learning curve, but you can get it.

1 Comment

PHPExcel has not be maintained for years and must not be used anymore. All users must migrate to its direct successor PhpSpreadsheet, or another alternative github.com/PHPOffice/PhpSpreadsheet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.