我试图创建一个将我的数据库的一部分导出为可读excel文件的功能。一切正常,但每次打开下载的文件时,我都会收到以下错误:
The file format and extension of [filename] don't match. The file could be corrupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?
代码:
//Get site location
$siteLocation = Db::getInstance()->queryResults('SELECT place FROM site WHERE site_number=?', array($siteNumber));
// The function header by sending raw excel
header("Content-type: application/vnd-ms-excel");
$documentName = 'Content-Disposition: attachment; filename='. $siteNumber . ' ' . $siteLocation[0]->place .'.xls';
// Defines the name of the export file (siteNumber + site Location)
header($documentName);
// Add data table
include 'exceldata.php';
如何修复Excel对已编译的Excel文件的信任问题?
聚苯乙烯。点击“是”'该文件打开正常,我不会收到与其他文件相同的消息。
提前致谢!
答案 0 :(得分:0)
$documentName = 'Content-Disposition: attachment; filename='. $siteNumber .
' ' . $siteLocation[0]->place .'.xlsx'; // try other extension here
试试吗?希望它有效。