PHP and Download Excel Sheet

谁都会走 提交于 2020-01-06 15:41:26

问题


I am facing a problem when I download a excel sheet in php(code is below). I have a date field but in database date is in "YYYY-MM-DD" format, I convert this format to "d/m/Y".

Then download and open a excel sheet, sheet is fine till now. When we use "Format Painter" tool(find just below cut and copy button), date will convert date format to some number and sometimes to some funny character.

How to use "Format Painter" - First select non-date column and then press "Format Painter" button, then click on date field column, it will convert some dates to number.

Code is below

$filename = "Report_name.xls";

if ( $html == "" ) 
{
    echo "<br>ERROR: No input provided";
    exit;
}
@header ("Content-type: application/x-msexcel");
@header("Content-Disposition: attachment; filename=$filename");
@header("Expires: 0");
print "$header\n$html";

回答1:


By default MS excel picks date format of your system date-time format. So change your system date-time to YMD format to avoid strange characters and numbers in date field.



来源:https://stackoverflow.com/questions/14396199/php-and-download-excel-sheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!