小编Ari*_*erg的帖子

使用PhpSpreadsheet在PHP中阅读XLS

我有使用PhpSpreadsheet读取XLS文件(不是xlsx)的要求,但遇到了麻烦。我试过了(正如文档所说,但是...)

require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;

$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load("lista.xls");
$worksheet = $spreadsheet->getActiveSheet();

echo '<table>' . PHP_EOL;
foreach ($worksheet->getRowIterator() as $row) {
    echo '<tr>' . PHP_EOL;
    $cellIterator = $row->getCellIterator();
    $cellIterator->setIterateOnlyExistingCells(FALSE); // This loops through all cells,
                                                       //    even if a cell value is not set.
                                                       // By default, only cells that have a value
                                                       //    set will be iterated.
    foreach ($cellIterator as $cell) {
        echo '<td>' .
             $cell->getValue() .
             '</td>' . PHP_EOL;
    }
    echo '</tr>' . PHP_EOL;
}
echo '</table>' . PHP_EOL; …
Run Code Online (Sandbox Code Playgroud)

php excel xls phpspreadsheet

4
推荐指数
2
解决办法
6470
查看次数

标签 统计

excel ×1

php ×1

phpspreadsheet ×1

xls ×1