欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

想导出的$objWriter->save('my-test'.$id.'.xls');里的文件,但实际保存的是整个页面的信息,求大神指点解决方案

程序员文章站 2022-06-13 11:19:05
...
想导出的$objWriter->save('my-test'.$id.'.xls');里的文件,但实际保存的是整个页面的信息,求大神指点
$phpexceldao = $db->query("select a.uri,b.order_id,b.product_id,b.qty,b.goods_groups,b.attr,a.product_img ,d.order_sn,d.dateline,c.supplier_name from ".RP_TABLEPRE."order_goods as b left join product as a on a.product_id=b.product_id left join supplier as c on c.supplier_name=b.supplier_name left join `order` as d on d.order_id =b.order_id where b.order_id=$id");


$objPHPExcel = new PHPExcel();
//行高
for($i = 2; $i {
$objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(22);
}


$i=2;
if($phpexceldao){
while($row= mysql_fetch_array($phpexceldao)){
$objPHPExcel->getActiveSheet()->setCellValue('A1','备货期');
$objPHPExcel->getActiveSheet()->setCellValue('A'.$i,$row[uri]);

$objPHPExcel->getActiveSheet()->setCellValue('B1','采购编号');
$objPHPExcel->getActiveSheet()->setCellValue('B'.$i,$row[order_id]);

$objPHPExcel->getActiveSheet()->setCellValue('C1','产品型号');
$objPHPExcel->getActiveSheet()->setCellValue('C'.$i,$row[product_id]);

$objPHPExcel->getActiveSheet()->setCellValue('D1','数量');
$objPHPExcel->getActiveSheet()->setCellValue('D'.$i,$row[qty]);

$objPHPExcel->getActiveSheet()->setCellValue('E1','品类');
$objPHPExcel->getActiveSheet()->setCellValue('E'.$i,$row[goods_groups]);

$objPHPExcel->getActiveSheet()->setCellValue('F1','尺码');
$objPHPExcel->getActiveSheet()->setCellValue('F'.$i,$row[attr]);

$objPHPExcel->getActiveSheet()->setCellValue('H1','订单号');
$objPHPExcel->getActiveSheet()->setCellValue('H'.$i,$row[order_sn]);

$objPHPExcel->getActiveSheet()->setCellValue('I1','订单日期');
$objPHPExcel->getActiveSheet()->setCellValue('I'.$i,$row[dateline]);

$objPHPExcel->getActiveSheet()->setCellValue('J1','供应商编号');
$objPHPExcel->getActiveSheet()->setCellValue('J'.$i,$row[supplier_name]);
//添加图片
$objPHPExcel->getActiveSheet()->setCellValue('G1','产品图片');
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Photo');
$objDrawing->setDescription('Photo');
$objDrawing->setPath($row[product_img]);
$objDrawing->setHeight(70);
$objDrawing->setWidth(20);
$objDrawing->setCoordinates('G'.$i);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

$i++;
}
}

}
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('my-test'.$id.'.xls');

header("Content-type: text/csv");//重要
header('Content-Disposition: attachment;filename="test'.$id.'.xls"');
header('Cache-Control: must-revalidate, post-check=0,pre-check=0');
header("Content-Type:application/vnd.ms-execl");
header('Expires:0');
header('Pragma:public');

------解决方案--------------------
header("Content-type: text/csv");//重要
header('Content-Disposition: attachment;filename="test'.$id.'.xls"');
header('Cache-Control: must-revalidate, post-check=0,pre-check=0');
header("Content-Type:application/vnd.ms-execl");
header('Expires:0');
header('Pragma:public');

这段放到$objWriter->save('my-test'.$id.'.xls');前面去
想导出的$objWriter->save('my-test'.$id.'.xls');里的文件,但实际保存的是整个页面的信息,求大神指点解决方案

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频