PHP从数组创建xls

我尝试从数组创建xls文件,并使用以下代码通过浏览器下载它:
$sheet = array(
    array(
      'a1 data','b1 data','c1 data','d1 data',)
  );

  $doc = new PHPExcel();
  $doc->getActiveSheet()->fromArray($sheet,null,'A1');

  header('Content-Type: application/vnd.ms-excel');
  header('Content-disposition: attachment;filename="your_name.xls"');
  header('Cache-Control: max-age=0');

  // Do your stuff here

  $writer = PHPExcel_IOFactory::createWriter($doc,'Excel5');

问题是我得到一个文件.任何想法可能是什么问题?

请试试 :
As per official documentation,您首先需要使用对象编写器保存文件

如果这是您想要的,请告诉我

<?PHP
date_default_timezone_set('America/Los_Angeles');

require_once('PHPExcel.PHP');

$sheet = array(
    array(
      'a1 data',)
  );

  $doc = new PHPExcel();
  $doc->setActiveSheetIndex(0);

  $doc->getActiveSheet()->fromArray($sheet,'A1');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-disposition: attachment;filename="your_name.xls"');
header('Cache-Control: max-age=0');

  // Do your stuff here
  $writer = PHPExcel_IOFactory::createWriter($doc,'Excel5');

$writer->save('PHP://output');
?>

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...