Joomla导出Excel(.xls或.csv)

时间:2017-12-05 01:53:46

标签: php joomla phpexcel

如何从数据库导出Excel(.csv.xls)变量?从数据库中插入变量不起作用,例如$temp(它可以回显变量中的单个值)

  require_once(JPATH_LIBRARIES . '/phpexcel/library/PHPExcel.php');
  require_once(JPATH_LIBRARIES.'/phpexcel/library/PHPExcel/IOFactory.php');$query = "SELECT referreid,insert_date,datareference FROM `miqi_alpha_userpoints_details` WHERE `referreid`='$referrerid' AND `enabled`='1' ORDER BY `insert_date` DESC";
  $db->setQuery( $query );
  $results = $db-> loadAssocList();
  $temp = $results[0]['referreid'];
  $objPHPExcel = new PHPExcel();
  $objPHPExcel->getActiveSheet()->setCellValue('A1','123');
  $objPHPExcel->getActiveSheet()->setCellValue('B1',$temp);
  header('Content-Type: text/plain;charset=utf-8'); //mime type
  header('Content-Disposition: attachment;filename="abc.csv"'); //tell browser what's the file name
  header('Cache-Control: max-age=0'); //no cache
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
  $objWriter->save('php://output');
  exit;

0 个答案:

没有答案
相关问题