Hi gan…
i phpexcel to export result set to xls file, my problem is why the .xls file just export to document root of my server not directly download to user pc…
public function actionExportToXls(){
$model = new Province();
$label = $model->attributeNames();
$data = $model->findAll();
$this->render('exportToXLS',array(
'data' => $data,
'label' =>$label,
));
$xls = Yii::app()->excel;
$xls->getActiveSheet()->setCellValue('A1',$label[0]);
$xls->getActiveSheet()->setCellValue('B1',$label[1]);
$xls->getActiveSheet()->setCellValue('C1',$label[2]);
$i = 2;
foreach($data as $record){
$xls->getActiveSheet()->setCellValue('A'.$i,$record->province_id);
$xls->getActiveSheet()->setCellValue('B'.$i,$record->province_name);
$xls->getActiveSheet()->setCellValue('C'.$i,$record->province_abbr_code);
$i++;
}
$xls->getActiveSheet()->getColumnDimension('A')->setWidth(24);
$xls->getActiveSheet()->getColumnDimension('B')->setWidth(24);
$xls->getActiveSheet()->getColumnDimension('C')->setWidth(24);
$filename = 'Test2.xlsx';
$xls->saveExcel2007($xls,$filename);
}
i add it header like this
header('Content-type: application/ms-excel;' );
header('Content-Disposition: inline; attachment; filename='.$filename.'');
works to download but become a corrupt file…
where’s the wrong…