请教老师,这怎么没有提示错误也没下载反应?
奥立奥
奥立奥 2018-07-10 17:07:27
0
4
1215

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<body>

<?php

$r1r = implode(",",$_POST['ypname']);

$r2r = implode(",",$_POST['guige']);

$r3r = implode(",",$_POST['shengcan']);

$r4r = implode(",",$_POST['danwei']);

$r5r = implode(",",$_POST['pihao']);

$r6r = implode(",",$_POST['bz']);

$r7r = implode(",",$_POST['rq']);

$r8r = implode(",",$_POST['djlx']);

$r9r = implode(",",$_POST['rk']);

$rwr = implode(",",$_POST['ch']);


$data2 = array_merge($r1r,$r2r);

var_dump ($data2);

/**

 * 数据导出

 * @param array $title   标题行名称

 * @param array $data   导出数据

 * @param string $fileName 文件名

 * @param string $savePath 保存路径

 * @param $type   是否下载  false--保存   true--下载

 * @return string   返回文件全路径

 * @throws PHPExcel_Exception

 * @throws PHPExcel_Reader_Exception

 

 */

 $title = array("商品名称","规格","厂商","单位","批号","备注","日期","单据类型","入库数量","出货数量");

 $type = true;

 $data = r1r;

 

 $fileName = 'bflxexc';

function exportExcel($title=array(), $data=array(), $fileName='', $savePath='./', $isDown=false){

include('PHPExcel.php');

$obj = new PHPExcel();

 

//横向单元格标识

$cellName = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ');

$obj->getActiveSheet(0)->setTitle('bflx');   //设置sheet名称

$_row = 1;   //设置纵向单元格标识

if($title){

$_cnt = count($title);

$obj->getActiveSheet(0)->mergeCells('A'.$_row.':'.$cellName[$_cnt-1].$_row);   //合并单元格

$obj->setActiveSheetIndex(0)->setCellValue('A'.$_row, '$r1r'.date('Y-m-d H:i:s'));  //设置合并后的单元格内容

$_row++;

$i = 0;

foreach($title AS $v){   //设置列标题

$obj->setActiveSheetIndex(0)->setCellValue($cellName[$i].$_row, $v);

$i++;

}

$_row++;

}

 

//填写数据

if($data){

$i = 0;

foreach($data AS $_v){

$j = 0;

foreach($_v AS $_cell){

$obj->getActiveSheet(0)->setCellValue($cellName[$j] . ($i+$_row), $_cell);

$j++;

}

$i++;

}

}

//文件名处理

if(!$fileName){

        $fileName = uniqid(time(),true);

    }

 

$objWrite = PHPExcel_IOFactory::createWriter($obj, 'Excel2007');

 

if($isDown){   //网页下载

header('pragma:public');

header("Content-Disposition:attachment;filename=$fileName.xls");

        $objWrite->save('php://output');exit;

}

 

$_fileName = iconv("utf-8", "gb2312", $fileName);   //转码

$_savePath = $savePath.$_fileName.'.xlsx';

$objWrite->save($_savePath);

 

return $savePath.$fileName.'.xlsx';

//exportExcel(array('姓名','年龄'), array(array('a',21),array('b',23)), '档案', './', true);

 ?>

 

 </body>

 <?php

 ?>

//数组还没有转换,但是为什么没有提示下载的?

奥立奥
奥立奥

全部回复(2)
、馬

路径会不会有问题

  • 回复 include('PHPExcel.php');这个路径吗?我添加了./也没法反应。
    奥立奥 作者 2018-07-10 22:51:04
奥立奥

post都有值的

  • 回复 是的
    、馬 作者 2018-07-10 17:47:09
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板