【问题标题】:Line break not happening in CSV file being generated by IE通过IE浏览器正在生成CSV文件中没有发生断行
【发布时间】:2010-12-24 09:18:13
【问题描述】:

我正在使用以下 PHP 代码生成 CSV 文件:

        header("Expires: 0");
        header("Cache-control: private");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Content-Description: File Transfer");
        header("Content-Type: text/csv");
        header("Content-disposition: attachment; filename=site_list.csv");

CSV 文件在所有浏览器中生成成功。但是 IE 生成的文件,用 MS Excel 打开时,会在一行中显示所有数据。

PS:

  • 其他浏览器(FF、Google Chrome)生成的文件运行良好。
  • 我使用“\n”换行。
  • 使用“\r\n”没有帮助

【问题讨论】:

    标签: php internet-explorer csv


    【解决方案1】:

    您是否尝试过使用\r\n 作为换行符?我知道某些版本的 IE 在回车方面存在一些奇怪的问题。

    【讨论】:

      【解决方案2】:

      添加 \r\n 并用双引号括起来

      'Line 1' . "\r\n" . 'Line 2'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-07-08
        • 1970-01-01
        • 2019-10-27
        • 2021-12-07
        • 2021-01-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多