我正在使用PHPExcel生成要下载的电子表格。
<?php
$objPHPExcel = new PHPExcel();
$emailReport = 'tmp/company.xls';
// Remove previous file if it exists.
$testdel=unlink($emailReport);
if(!$testdel){
echo "Unable to remove previous Spreadsheet<hr/>";
}
echo '<a href="'.$emailReport.'" class="dbutton">Download Spreadsheet</a><hr/>';
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1,'Old Value');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($emailReport);
?>
一切都很好。
电子表格已创建,并将文本保存在单元格A1中。
But if I change the php file, perhaps by changing $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1,'Old Value');
to $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1,'New, Improved Value');
I'm expecting the new spreadsheet to contain "New, Improved Value" in cell A1, but when I click the link to download it, the version of the spreadsheet that is downloaded contains the old value.
但是,当我使用FTP下载文件时,该文件确实已更新。
大概浏览器将文件保存在缓存中?
如何确保下载了正确的版本?
感谢您的建议。
我决定将时间添加到文件名中,以使浏览器不会引用缓存的版本。
很难弄清发生了什么,以及为什么未呈现电子表格中的更改。
You can invalidate your cache by using
header()
. Example:在文件的第一行。但是我认为这不会在您的示例中起作用。它仅在将文件提供下载的页面上有效。这意味着,在您的情况下,您必须制作一个页面来获取xls文件的内容,并将其直接输出到具有正确标题的浏览器。
您是否尝试过清除浏览器的缓存(Ctrl + shift + Del)并再次下载文件?还是以p0rn咳嗽私人模式启动浏览器并再次下载文件?