问题
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