【问题标题】:Save Mysql data in xls using php使用php将Mysql数据保存在xls中
【发布时间】:2014-12-02 22:05:36
【问题描述】:

我想使用 PHP 以 xls 格式导出数据。但不是下载信息,而是显示在我的网页中。

//connection to database
//building of all information -> ($righe)

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: esporta_utenti.xls");
print $righe;
exit();  

$righe 是我的元组

【问题讨论】:

  • 跟随正确的标题header('Content-Disposition: attachment; filename="esporta_utenti.xls"');
  • 它不起作用,脚本的行为方式相同
  • 你可以在header()之前输出一些东西。注释header之前的所有代码,你会做对的。
  • 对不起@JithinJose 但我不明白你在说什么。如果我在 header() 之前注释所有代码 $righe 将为空

标签: php mysql xls


【解决方案1】:
header('Pragma: public');   // required
header('Expires: 0');       // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file_name)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: '.$mime); // file mime type
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file_name));    // provide file size
header('Connection: close');
readfile($file_name);       // push it out
exit();

此代码最初发布在这里 http://davidwalsh.name/php-force-download 。并可以参考Code的详细解释。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多