尝试从url加载.xlsx文件,但它会出现错误,如
Fatal error: Uncaught InvalidArgumentException: File
"http://localhost/test/csvfile/samplesms.xlsx" does not exist. in
D:\wamp\www\test\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Shared\File.php on line 137
加载下面的文件,
$filename = "http://localhost/test/csvfile/samplesms.xlsx";
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
$reader->setReadDataOnly(TRUE);
$spreadsheet = $reader->load($filename);
文件已在指定位置。
答案 0 :(得分:1)
在phpoffice / spreadsheet中不支持从URL加载。
答案 1 :(得分:0)
您可以使用 php_get_content 或 curl 加载文件内容,并将其临时保存在本地,然后加载文件的本地版本
$filename = "http://localhost/test/csvfile/samplesms.xlsx";
$file=file_get_content($filename);
file_put_content('tempfile.xlsx',$file);
$inputFileName = 'tempfile.xlsx';
/** Load $inputFileName to a Spreadsheet Object **/
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($inputFileName);