windows下 php 导出数据到EXCEL表中
来源:互联网 发布:仙掌游戏 倒闭 知乎 编辑:程序博客网 时间:2024/04/30 15:00
<?php
date_default_timezone_set('PRC'); //设置时间
$DB_Server = "localhost";
$DB_Username = "root";
$DB_Password = "123";
$DB_DBName = "user";
$DB_TBLName = $_REQUEST['tbname'];
$savename = date("YmjHis");
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect.");
//mysql_query("Set Names 'gbk'");
$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type;charset=utf-8");
header("Content-Disposition: attachment; filename=".$DB_TBLName.$savename.".$file_ending");
//header("Pragma: no-cache");
//iconv("utf-8", "gb2312","数据".$DB_TBLName.$savename);
$now_date = date("Y-m-j H:i:s");
$title = "数据库名\t$DB_DBName\t数据表\t$DB_TBLName\t备份日期\t$now_date";
$sql = "Select * from $DB_TBLName";
$ALT_Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database");
$result = @mysql_query($sql,$Connect) or die(mysql_error());
echo iconv("utf-8", "gb2312","$title\n");
$sep = "\t";
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i)."\t";
}
print("\n");
// $i = 0;
while($row = mysql_fetch_row($result)) {
$schema_insert = "";
for($j=0; $j< mysql_num_fields($result);$j++) {
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
else if ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
//$schema_insert = str_replace($sep."$", ",", $schema_insert);
$schema_insert .= "\t";
echo iconv("utf-8", "gb2312",$schema_insert);
//print(trim($schema_insert));
print "\n";
// $i++;
}
return (true);
?>
date_default_timezone_set('PRC'); //设置时间
$DB_Server = "localhost";
$DB_Username = "root";
$DB_Password = "123";
$DB_DBName = "user";
$DB_TBLName = $_REQUEST['tbname'];
$savename = date("YmjHis");
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect.");
//mysql_query("Set Names 'gbk'");
$file_type = "vnd.ms-excel";
$file_ending = "xls";
header("Content-Type: application/$file_type;charset=utf-8");
header("Content-Disposition: attachment; filename=".$DB_TBLName.$savename.".$file_ending");
//header("Pragma: no-cache");
//iconv("utf-8", "gb2312","数据".$DB_TBLName.$savename);
$now_date = date("Y-m-j H:i:s");
$title = "数据库名\t$DB_DBName\t数据表\t$DB_TBLName\t备份日期\t$now_date";
$sql = "Select * from $DB_TBLName";
$ALT_Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database");
$result = @mysql_query($sql,$Connect) or die(mysql_error());
echo iconv("utf-8", "gb2312","$title\n");
$sep = "\t";
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i)."\t";
}
print("\n");
// $i = 0;
while($row = mysql_fetch_row($result)) {
$schema_insert = "";
for($j=0; $j< mysql_num_fields($result);$j++) {
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
else if ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
//$schema_insert = str_replace($sep."$", ",", $schema_insert);
$schema_insert .= "\t";
echo iconv("utf-8", "gb2312",$schema_insert);
//print(trim($schema_insert));
print "\n";
// $i++;
}
return (true);
?>
- windows下 php 导出数据到EXCEL表中
- windows/linux下,把mysql数据库,sql导出表数据到excel中
- php 导出数据到 Excel
- PHP导出数据到Excel
- php 导出数据到excel
- 导出数据到excel中
- 导出数据到Excel中
- 导出数据到Excel中
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- php导出Mysql数据到Excel
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel文件
- PHP导出MySQL数据到Excel
- PHP导出MySQL数据到Excel文件
- [Ruby学习总结]Ruby中的类
- it笔试题目(技术)
- HTML5表单教程之input新增加的URL类型与email类型应用
- android数据库操作(一)
- 事情
- windows下 php 导出数据到EXCEL表中
- sourceinsight 语法不显示高亮 symble无法跳转 不解析
- Redis系统性介绍
- 黑马程序员——IO流
- href超链接,打开新标签页
- ASP.NET中DataTable与DataSet之间的转换
- CentOS-6安装使用mongodb
- 僵尸进程
- Weblogic12c (12.1.2) 兼容性问题汇总