简体   繁体   中英

PHP Excel Reader to read xlsx file

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)));
  }
}

我认为您无法读取.xslx文件的原因是因为您没有启用PHP扩展“ php_zip ”。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM