简体   繁体   English

使用PHP从URL打开XLS-File并将其保存在变量中

[英]Open XLS-File from URL with PHP and save it in variable

There is a report, which a server automatically creates in my Intranet. 有一个报告,服务器会在我的Intranet中自动创建。

I can access it and download it via an url like this: 我可以通过如下网址访问并下载它:

http://www1.intranet.com/reportingtool.asp?settings=var&export = ok

I want to use it with PHPExcel. 我想将其与PHPExcel一起使用。

$objPHPExcel = PHPExcel_IOFactory::load("file.xls");

When I swop file.xls with the url it doesn't work. 当我用网址 切换file.xls时,它不起作用。

Which alternative way can I use to avoid the step by manually downloading the excel-file and writing the file-name in the code? 我可以使用哪种替代方法来避免此步骤,方法是手动下载excel文件并在代码中写入文件名?

You can't... 你不能

To parse the xls file, PHPExcel needs to be able to move the file pointer backward and forward through the file as it reads data from the OLE streams; 为了解析xls文件,PHPExcel必须能够在从OLE流读取数据时在文件中前后移动文件指针。 which isn't an option with a file retrieved via url, only with a file that is physically available on the server filesystem. 通过url检索的文件不是选项,而只有服务器文件系统上物理可用的文件才是选择。

Workaround (downloading to a temporary file): 解决方法(下载到临时文件):

$url = 'http://www1.intranet.com/reportingtool.asp?settings=var&export=ok';
$tmpfname = tempnam(sys_get_temp_dir());
file_put_contents(
    $tmpfname,
    file_get_contents($url)
);
$objPHPExcel = PHPExcel_IOFactory::load($tmpfname);

though you'll probably need to manually delete $tmpfname afterwards 尽管您之后可能需要手动删除$ tmpfname

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM