Heim  >  Artikel  >  php教程  >  PHPExcel php execl下载或保存到本地

PHPExcel php execl下载或保存到本地

WBOY
WBOYOriginal
2016-06-13 10:50:071433Durchsuche

public static function saveExcel($objPHPExcel, $excelName,  $output) {
  $objWriter = PHPExcel_IOFactory::createWriter ( $objPHPExcel, 'Excel5' );
  if (! strpos ( $_SERVER ['HTTP_USER_AGENT'], 'Firefox' ))
   $excelName = urlencode ( $excelName );
  if ($output) {
   ob_end_clean ();
   header ( "Content-Type: application/force-download" );
   header ( "Content-Type: application/octet-stream" );
      header ( "Content-Type: application/download" );
   header ( "Content-Disposition: attachment; filename=" . $excelName . ".xls" );
   header ( "Content-Transfer-Encoding: binary" );
   header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
   header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" );
   header ( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
   header ( "Pragma: no-cache" );
   $objWriter->save ( 'php://output' );
  } else {
   $objWriter->save ( "Excel/" . $excelName . ".xls" );
   echo '';
  }
 }

 


摘自 lpdx111的专栏

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn