PHP Excel Reader读取xlsx文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35447746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Excel Reader to read xlsx file
提问by amln_ndh
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.
我找到了有关如何使用 PHPExcelReader 在 PHP 中读取 Excel 文件数据的代码。它在这里说它支持 xls 和 xlsx 文件。但是,在查看 xlsx 文件时,它说该文件不可读。它仅在查看 xls 文件时有效。我可以在我的代码中添加任何内容以使其对 xlsx 文件也可读吗?我也试过在网上搜索答案,但它仍然可读。请帮帮我谢谢。
<?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)));
}
}
回答by Cheketo
I think that the reason why you can't read .xslx files is because you don't have the PHP extension 'php_zip' enabled.
我认为您无法读取 .xslx 文件的原因是您没有启用PHP 扩展“ php_zip”。
回答by jlemley
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
看起来课程网站将 PHPExcel 包装在他们自己的课程包中。我建议在此处获取官方副本和最新版本:https: //github.com/PHPOffice/PHPExcel
Click on the wiki tab for documentation, or visit: https://phpexcel.codeplex.com
单击 wiki 选项卡获取文档,或访问:https: //phpexcel.codeplex.com
By the way, xlsx files require PHP extension php_zip. Check out the Getting Started document for other requirements.
顺便说一下,xlsx 文件需要 PHP 扩展名 php_zip。查看入门文档以了解其他要求。
I use PHPExcel to read and write xlsx files. There is a bit of a learning curve, but you can get it.
我使用 PHPExcel 来读写 xlsx 文件。有一点学习曲线,但你可以得到它。