Home >Backend Development >PHP Tutorial >Solution to php export cvs xls xlsx

Solution to php export cvs xls xlsx

巴扎黑
巴扎黑Original
2017-07-24 10:36:582657browse
/**
 * 导出日志
 */
public function excel() {
   setlocale(LC_ALL, 'en_US.UTF-8');
   $filename = date('YmdHis') . ".csv";
   header("Content-type:text/csv");
   header("Content-Disposition:attachment;filename=" . $filename);
   header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
   header('Expires:0');
   header('Pragma:public');

   $db = Db::name($this->table)->order('id desc');
   $excelinfo = parent::_excel($db);
   $result = "标题,地址,作者,添加时间"."\n";
   foreach ($excelinfo as $v_excelinfo){
      $result.=replaces_string($v_excelinfo['article_title']).','.
         replaces_string($v_excelinfo['url']).','.
         replaces_string($v_excelinfo['article_author']).','.
         replaces_string($v_excelinfo['article_publish_time'])."\n";
   }
   echo $result;return;
}

The above is the detailed content of Solution to php export cvs xls xlsx. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn