我找到了有关如何使用 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)));
}
}
Run Code Online (Sandbox Code Playgroud)
看起来课程网站将 PHPExcel 包装在他们自己的课程包中。我建议在这里获取官方副本和最新版本:https ://github.com/PHPOffice/PHPExcel
单击 wiki 选项卡获取文档,或访问: https: //phpexcel.codeplex.com
顺便说一句,xlsx 文件需要 PHP 扩展名 php_zip。查看入门文档了解其他要求。
我使用 PHPExcel 来读取和写入 xlsx 文件。有一点学习曲线,但你可以得到它。