PHP 导入Excel
来源:互联网 发布:java获取当前时间戳 编辑:程序博客网 时间:2024/05/22 03:36
Following is an example about exporting data to excel:
here is the key code:
如果需要控制导出数据在excel中的样式,则只需要给数据套上table样式即可。
1.report_inq.php:
<script language="javascript">
function export_excel(){
var part =document.all.part.value;
var id =document.all.id.value;
window.open('export_excel.php?part='+part+'&id='+id);
}
</script>
<?php
function db_link()
{
$access_id = "root";
$db_name = "db_name";
@ $db = mysql_connect('localhost', $access_id, '831025') or
die("Could not connect to database. ");
mysql_query("SET NAMES 'GBK'");
mysql_select_db($db_name);
return $db;
}
$link = db_link();
$id = $_POST['id'];
$part = $_POST['part'];
echo '<form name="form1" action="" method="post" onsubmit="return check(this);">';
echo '<input type="text" name="id" size="8" maxlength="8" value="'.$id.'"></input>';
echo '<input type="text" name="part" size="8" maxlength="20" value="'.$part.'"></input>';
echo '<input type="submit" name="search" value="Search">';
echo '</form>';
if ($_POST['search'] == 'Search'){
$sql = "SELECT * FROM test_table WHERE id='".$id."' AND part='".$part."' ";
$res = mysql_query($sql);
//display something here
echo '<input type="button" name="export" onclick="export_excel();" value="Export" >';
}
?>
2.export_excel.php:
<?php
$id = $_GET['id'];
$part = $_GET['part'];
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=mrp_report.xls ");
header("Content-Transfer-Encoding: binary ");
echo '<table border=1>';
echo '<tr bgcolor="red">';
echo "<th>Date</th>
<th>Line</th>
<th>Req</th></tr>";
$sql = "SELECT * FROM test_table WHERE part='".$part."' AND id='".$id."' ";
$res = mysql_query($sql);
$num = mysql_num_rows($res);
if($num>0){
for($i=0;$i<$num;$i++){
$row = mysql_fetch_array($res);
echo '<tr><td>'.$row['date']."</td>";
echo '<td>'.$row['line']."</td>";
echo '<td>'.$row['req']."</td></tr>";
}
}
echo '</table>';
?>
- PHP 导入Excel
- PHP导出导入Excel
- PHP导入Excel
- PHP导入Excel
- php导入excel文件
- php 导入excel
- php导入Excel
- PHP 导入excel数据
- php excel导入
- PHP Excel 导入mysql
- PHP导入Excel文件
- php导入excel
- php导入excel数据
- PHP导入excel
- php 导入excel 方法
- php excel导入 导出
- PHP原生excel导入
- php excel 表格导入
- 网友票选的2007我最牛msn签名(选摘)
- Introduction to Programming in C/C with Vim
- 在Winform中,获取DataGrid当前选定行对应的数据
- linux 安装matlab
- ubuntu中修改网卡物理地址
- PHP 导入Excel
- 如何练出+7武器 非RMB玩家的经验总结
- 连接池proxool配置
- JAVA加密程序
- your eclipse on ubuntu is slow? come here
- perl里split的转义问题
- 单点登陆解决方案
- 挂在美国人口边的最酷口语
- firefox添加rtsp和mms协议