yii框架phpexcel
生活随笔
收集整理的這篇文章主要介紹了
yii框架phpexcel
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//控制器調(diào)用 $id=\Yii::$app->request->get('id');
????????$arr=\Yii::$app->exam->createCommand("select?*?from?`order`?INNER?JOIN?movie?on?`order`.movie_id=movie.id?where?`order`.id?in?($id)")->queryAll();
????????$strTable?='<table?width="500"?border="1">';
????????$strTable?.=?'<tr>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="150px">訂單</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">姓名</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">電話</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">預(yù)約時(shí)間</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">預(yù)約座位</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">預(yù)約電影</td>';
????????$strTable?.=?'</tr>';
????????foreach($arr?as?$key=>$val)
????????{
????????????$strTable?.=?'<tr>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['order_no'].'?</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['username'].'?</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['tel'].'</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['start_time'].'?</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['seatnum'].'?</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['name'].'?</td>';
????????????$strTable?.=?'</tr>';
????????}
????????$strTable?.='</table>';
????????//echo?'123';
????????$reportObj?=?new?PHPExcel();
????????$reportObj->setFileName('demo');
????????$reportObj->toDownload($strTable); //model里引用 <?php
namespace frontend\models;
//include $_SERVER['D3OCUMENT_ROOT'].'/PHPExcel/EXCEL/PHPExcel.php';
// include 'E:\www\WWW\advanced\common\widgets\PHPExcel\EXCEL\PHPExcel\Writer\Excel2007.php';
use yii\base\Model;
/**
?* This is the model class for table "country".
?*
?* @property string $code
?* @property string $name
?* @property integer $population
?*/
class PHPExcel extends Model
{
??? //文件名
??? private $fileName = 'user';
??? //構(gòu)造函數(shù)
??? public function __construct($fileName = '')
??? {
??????? $this->setFileName($fileName);
??? }
??? //設(shè)置要導(dǎo)出的文件名
??? public function setFileName($fileName)
??? {
??????? $this->fileName = $fileName;
??? }
??? //開始下載
??? public function toDownload($strTable)
??? {
??????? header("Content-type: application/vnd.ms-excel");
??????? header("Content-Type: application/force-download");
??????? header("Content-Disposition: attachment; filename=".$this->fileName."_".date('Y-m-d').".xls");
??????? header('Expires:0');
??????? header('Pragma:public');
??????? echo '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.$strTable.'</html>';
??? }
}
????????$arr=\Yii::$app->exam->createCommand("select?*?from?`order`?INNER?JOIN?movie?on?`order`.movie_id=movie.id?where?`order`.id?in?($id)")->queryAll();
????????$strTable?='<table?width="500"?border="1">';
????????$strTable?.=?'<tr>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="150px">訂單</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">姓名</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">電話</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">預(yù)約時(shí)間</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">預(yù)約座位</td>';
????????$strTable?.=?'<td?style="text-align:center;font-size:12px;"?width="*">預(yù)約電影</td>';
????????$strTable?.=?'</tr>';
????????foreach($arr?as?$key=>$val)
????????{
????????????$strTable?.=?'<tr>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['order_no'].'?</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['username'].'?</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['tel'].'</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['start_time'].'?</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['seatnum'].'?</td>';
????????????$strTable?.=?'<td?style="text-align:center;font-size:12px;">'.$val['name'].'?</td>';
????????????$strTable?.=?'</tr>';
????????}
????????$strTable?.='</table>';
????????//echo?'123';
????????$reportObj?=?new?PHPExcel();
????????$reportObj->setFileName('demo');
????????$reportObj->toDownload($strTable); //model里引用 <?php
namespace frontend\models;
//include $_SERVER['D3OCUMENT_ROOT'].'/PHPExcel/EXCEL/PHPExcel.php';
// include 'E:\www\WWW\advanced\common\widgets\PHPExcel\EXCEL\PHPExcel\Writer\Excel2007.php';
use yii\base\Model;
/**
?* This is the model class for table "country".
?*
?* @property string $code
?* @property string $name
?* @property integer $population
?*/
class PHPExcel extends Model
{
??? //文件名
??? private $fileName = 'user';
??? //構(gòu)造函數(shù)
??? public function __construct($fileName = '')
??? {
??????? $this->setFileName($fileName);
??? }
??? //設(shè)置要導(dǎo)出的文件名
??? public function setFileName($fileName)
??? {
??????? $this->fileName = $fileName;
??? }
??? //開始下載
??? public function toDownload($strTable)
??? {
??????? header("Content-type: application/vnd.ms-excel");
??????? header("Content-Type: application/force-download");
??????? header("Content-Disposition: attachment; filename=".$this->fileName."_".date('Y-m-d').".xls");
??????? header('Expires:0');
??????? header('Pragma:public');
??????? echo '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.$strTable.'</html>';
??? }
}
轉(zhuǎn)載于:https://www.cnblogs.com/zhanghuilong/p/6481010.html
總結(jié)
以上是生活随笔為你收集整理的yii框架phpexcel的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [vim]高亮查找匹配
- 下一篇: 动态规划算法php,php算法学习之动态