PHP导出Excel表格

public function tui_export(){
if(empty($_GET[‘userid’])){
showmessage(‘参数传递错误’, ‘?m=weixin&c=recommend_list&a=index’,2000);
}
$table=“co_weixin_couponsas cp LEFT JOIN co_cacos as c ON cp.userid=c.userid”;
KaTeX parse error: Expected '}', got 'EOF' at end of input: …AND cp.userid={_GET[‘userid’]}";
i n f o s = infos= infos=this->coupons_db->select( w h e r e , ′ c p . ∗ , c . c c n a m e ′ , ′ ′ , ′ c p . c t i m e D E S C ′ , ′ ′ , ′ ′ , where,'cp.*,c.cc_name','','cp.c_time DESC','','', where,cp.,c.ccname,,cp.ctimeDESC,,,table);
if(empty($infos)){
showmessage(‘数据为空,不可导出!!!’,’?m=weixin&c=recommend_list&a=index’,1000);
}
d a t a = a r r a y ( ) ; f o r e a c h ( data = array(); foreach( data=array();foreach(infos as k = > k=> k=>v){
d a t a [ data[ data[k][‘cc_name’] = $v[‘cc_name’];
d a t a [ data[ data[k][‘money’] = $v[‘money’].“元”;
d a t a [ data[ data[k][‘c_time’] = date(“Y-m-d H:i:s”,$v[‘c_time’]);
d a t a [ data[ data[k][‘status’] = $v[‘status’]==2 ? “已发送红包” : “”;
}
t i t l e = a r r a y ( ′ 姓 名 ′ , ′ 红 包 金 额 ′ , ′ 创 建 时 间 ′ , ′ 状 态 ′ ) ; h e a d e r ( " C o n t e n t − t y p e : a p p l i c a t i o n / o c t e t − s t r e a m " ) ; h e a d e r ( " A c c e p t − R a n g e s : b y t e s " ) ; h e a d e r ( " C o n t e n t − t y p e : a p p l i c a t i o n / v n d . m s − e x c e l ; c h a r s e t = U T F − 8 " ) ; h e a d e r ( " C o n t e n t − D i s p o s i t i o n : a t t a c h m e n t ; f i l e n a m e = " . i c o n v ( " U T F − 8 " , " G B 2312 / / I G N O R E " , d a t e ( ′ Y − M − D ′ , t i m e ( ) ) . " 导 出 方 案 记 录 " ) . " . x l s " ) ; h e a d e r ( " P r a g m a : n o − c a c h e " ) ; h e a d e r ( " E x p i r e s : 0 " ) ; / / 导 出 x l s 开 始 i f ( ! e m p t y ( title=array('姓名','红包金额','创建时间','状态'); header("Content-type:application/octet-stream"); header("Accept-Ranges:bytes"); header("Content-type:application/vnd.ms-excel; charset=UTF-8"); header("Content-Disposition:attachment;filename=".iconv("UTF-8", "GB2312//IGNORE",date('Y-M-D',time())."导出方案记录").".xls"); header("Pragma: no-cache"); header("Expires: 0"); //导出xls 开始 if (!empty( title=array(,,,);header("Contenttype:application/octetstream");header("AcceptRanges:bytes");header("Contenttype:application/vnd.msexcel;charset=UTF8");header("ContentDisposition:attachment;filename=".iconv("UTF8","GB2312//IGNORE",date(YMD,time())."").".xls");header("Pragma:nocache");header("Expires:0");//xlsif(!empty(title)){
foreach ($title as $k => $v) {
t i t l e [ title[ title[k]=iconv(“UTF-8”, “GB2312//IGNORE”,$v);
}
$title= implode("\t", t i t l e ) ; e c h o " title); echo " title);echo"title\n";
}
if (!empty(KaTeX parse error: Expected '}', got 'EOF' at end of input: … foreach(refInfo as k e y = > key=> key=>val){
foreach ($val as $ck => $cv) {
r e f I n f o [ refInfo[ refInfo[key][$ck]=iconv(“UTF-8”, “GB2312//IGNORE”, $cv);
}
r e f I n f o [ refInfo[ refInfo[key]=implode("\t", r e f I n f o [ refInfo[ refInfo[key]);
}
echo implode("\n",$refInfo);
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 PHP 导出 Excel 表格的示例代码: ```php // 数据数组 $data = array( array('姓名', '年龄', '性别'), array('张三', 18, '男'), array('李四', 20, '女'), array('王五', 22, '男') ); // 创建 Excel 对象 $excel = new COM('Excel.Application'); $excel->visible = false; $excel->DisplayAlerts = 0; // 新建工作簿 $workbook = $excel->Workbooks->Add(); // 激活工作表 $worksheet = $workbook->Worksheets(1); // 将数据写入工作表 for ($i = 0; $i < count($data); $i++) { for ($j = 0; $j < count($data[$i]); $j++) { $worksheet->Cells($i+1, $j+1)->Value = $data[$i][$j]; } } // 设置单元格格式 $range = $worksheet->Range('A1:C1'); $range->Font->Bold = true; $range->Interior->ColorIndex = 36; $range->HorizontalAlignment = -4108; // 保存工作簿 $workbook->SaveAs('test.xlsx'); $workbook->Close(false); $excel->Quit(); ``` 这段代码会创建一个包含数据数组的 Excel 文件,并将其保存为 `test.xlsx`。你可以将这个文件作为响应发送给客户端,使其自动下载。 以下是使用 PHP 发送响应头的示例代码: ```php // 文件路径 $file = 'test.xlsx'; // 发送响应头 header('Content-Description: File Transfer'); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); // 读取文件并输出到客户端 readfile($file); ``` 将这段代码添加到前面的示例中,就可以将 Excel 文件作为响应发送给客户端了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值