I wanna ask about exporting data which is displayed in Yii into Excel…
Let’s say i have this code
public function actionExcel()
{
$hasil[0]=array('propinsi'=>'propinsi',count('id_dokumen')=>'Antar',count('tgl_masuk')=>'Respon');
Yii::import('application.extensions.phpexcel.JPhpExcel');
$xls = new JPhpExcel('UTF-8', false, 'test');
$xls->addArray($hasil);
$xls->generateXML('report');
}
where in the other function, i’ve put this SQL in order to be viewed as an independent relation (table)…
public function actionTables()
{
$sql='SELECT b.propinsi, COUNT(a.id_dokumen) AS Antar, COUNT(a.tgl_masuk) AS Respon
FROM dokumen AS a , master_prop AS b
WHERE a.kode_prop = b.kode_prop
GROUP BY propinsi';
$dataProvider6=new CSqlDataProvider($sql,array(
'keyField' => 'Antar',
));
$this->render('tables',array(
'dataProvider6'=>$dataProvider6,
));
}
when i ran this, the excel file could be downloaded, but there’s no content inside, except the attributes (propinsi and Respon)… Could anyone help me? Thanks in Advance
public function actionExcel()
{
$sql='SELECT b.propinsi, COUNT(a.id_dokumen) AS Antar, COUNT(a.tgl_masuk) AS Respon
FROM dokumen AS a , master_prop AS b
WHERE a.kode_prop = b.kode_prop
GROUP BY propinsi';
if(isset($_GET['sql']))
{
$dataProvider6=new CSqlDataProvider($sql,array(
'keyField' => 'Antar',
));
$data = $dataProvider6->data;
foreach ($data as $sql)
{
$test[] = $sql;
}
Yii::import('application.extensions.phpexcel.JPhpExcel');
$xls = new JPhpExcel('UTF-8', false, 'test');
$xls->addArray($test);
$xls->generateXML('export');
}
}
but, when i ran this, the blank page is showed. Could you give me an advice? thanks