PHP和下载Excel工作表 [英] PHP and Download Excel Sheet

查看:100
本文介绍了PHP和下载Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php中下载Excel工作表时遇到了问题(代码在下面).我有一个日期字段,但是在数据库中,日期为"YYYY-MM-DD"格式,因此我将该格式转换为"d/m/Y".

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".

然后下载并打开Excel工作表,到目前为止工作表还可以.当我们使用格式刷"工具(在剪切并复制"按钮下方找到)时,日期会将日期格式转换为一些数字,有时还会转换为一些有趣的字符.

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.

代码在下面

$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";

推荐答案

默认情况下,MS excel会选择系统日期时间格式的日期格式. 因此,将您的系统日期时间更改为YMD格式,以避免在日期字段中出现奇怪的字符和数字.

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.

这篇关于PHP和下载Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆