使用PhpSpreadsheet库来导入远程Excel表格
// 远程Excel文件URL
$url = 'https://example.com/remote-file.xlsx';
// 保存文件的本地路径
$localFilePath = public_path() . '\test.xls';
// 下载远程Excel文件并保存到本地
file_put_contents($localFilePath, file_get_contents($url), LOCK_EX);
// 加载本地Excel文件
$spreadsheet = IOFactory::load($localFilePath);
// 获取Excel文件中的工作表
$sheet = $spreadsheet->getActiveSheet();
// 遍历工作表的行和列来提取数据
foreach ($worksheet->getRowIterator() as $row) {
// 遍历单元格
foreach ($row->getCellIterator() as $cell) {
// 获取单元格的值
$value = $cell->getValue();
echo $value . ' ';
}
echo "\n";
}
if (file_exists($localFilePath)) {
unlink($localFilePath);
}