php输出excle表格样式,需要代码形式,一定重谢!!!急急急
发布网友
发布时间:2022-04-25 06:22
我来回答
共3个回答
热心网友
时间:2022-04-25 07:52
<?php
$list = array
(
'位置','单元','房间','学号','姓名','性别','专业'
);
//$file = fopen("contacts.csv","a");
header('Content-Type: application/vnd.ms-excel;charset=gb2312');
header('Content-Disposition: attachment;filename='.date("YmdHis").".csv");
header('Cache-Control: max-age=0');
// 打开PHP文件句柄,php://output 表示直接输出到浏览器
$fp = fopen('php://output', 'a');
foreach ($list as $key=>$val)
{
$list[$key] = $val;
}
fputcsv($fp,$list);
//explode(',',$line)
$con = mysql_connect("localhost","root","admin");
mysql_select_db("php_jquery_example");
$sql = "select event_id, event_title, event_desc,event_start, event_end from events";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result) ){
$list2 = array($row[0],$row[1],$row[2],$row[3],$row[4]);
foreach($list2 as $k=>$val){
$list2[$k] = $val;
}
fputcsv($fp,$list2);
unset($list2);
}
fclose($fp);
mysql_close();
?>
热心网友
时间:2022-04-25 09:10
把下面这些代码写入download.php 然后地址栏访问download.php
<?php
header('content-type:charset=utf-8');
header("Content-Type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=test.xls");
header("Pragma:no-cache");
header("Expires:0");
$content = '<table><tr><td style="color:red;text-indent: 2em;">撸主</td></tr>';
$content.= '<tr><td style="background:#ccc;text-indent: 2em;">请看</td></tr>';
$content.= '<tr><td style="text-indent: 2em;">例子</td></tr></table>';
echo $content;//$content 最外围必须使用table标签,这样里面的html样式才支持
?>
热心网友
时间:2022-04-25 10:44
<table width="350" height="127" border="1">
<tr>
<td rowspan="2">序号</td>
<td colspan="3">申请人</td>
</tr>
<tr>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>