There is a professional excel processing class in php. We can use it to add, delete or process related data in excel. If we just want to generate excel, we can use the following method simply and quickly.
If you don’t want to read the data, we can just use the following code. You only need to export the relevant data to the excel table. Such a simple operation does not require the use of those class libraries. Just use the header method directly: header("Content-type:application/vnd.ms-excel");
The code is as follows
|
Copy code
|
||||||||
代码如下 | 复制代码 | ||||||||
|
header(‘Content-Disposition: attachment;filename="yingcai.xls”‘);
?>
header("Content-Type: application/msword");
Username
代码如下
复制代码
header("Content-Disposition: attachment; filename=doc.doc"); Password
The code is as follows | Copy code | ||||
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment; filename=user information table.xls");
require_once('./class.db.php');
$db = new DB('localhost', 'app_vmovies', 'root', '123456');
$sql = 'select * from `user` order by `id` desc';
$ret = $db->get_results($sql);
//The output content is as follows:
echo "ID"."t";
echo "nickname"."t";
echo "gender"."t";
echo "OpenId"."t";
echo "Platform"."t";
echo "Registration Date"."t";
echo "n";
$len = count($ret);
for ( $i = 0; $i < $len; $i++ ) {
echo $ret[$i]["id"]."t";
echo $ret[$i]["nickname"]."t";
echo $ret[$i]["gender"]."t";
echo $ret[$i]["openid"]."t";
echo $ret[$i]["pf"]."t";
echo $ret[$i]["regdate"]."t";
echo "n";
}
If the program is encoded in UTF-8, you need to use the iconv function to transcode it, otherwise it will be garbled and garbled.
The other word format import is similar, just specify the header:
|