/**
* 导出Excel
* @author david
* @data 2018/10/18
*/
function export_goods_diff($exportData)
{
header("Content-Type:text/html;charset=utf-8");
include 'excel/Classes/PHPExcel/IOFactory.php';
$file_name = auto_charset("商品入库单差异对比导出", "gb2312", "utf8");
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle("商品列表");
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial')->setSize(10);
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
$objPHPExcel->getActiveSheet()
->setCellValue('A1', '单据编号')
->setCellValue('B1', '入库单号')
->setCellValue('C1', '合同单号')
->setCellValue('D1', '发放仓')
->setCellValue('E1', '收方')
->setCellValue('F1', '商品SKU')
->setCellValue('G1', '条形码')
->setCellValue('H1', '应入库数量')
->setCellValue('I1', '已入库数量')
->setCellValue('J1', '差异');
foreach ($exportData as $k => $v) {
$field1 = 'A'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field1, $v['djbh'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field1 = 'B'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field1, $v['entryOrderCode'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field2 = 'C'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field2, $v['purchaseOrderCode'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field3 = 'D'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field3, $v['issue'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field4 = 'E'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field4,$v['consignee'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field4 = 'F'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field4,$v['barcode'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field4 = 'G'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field4,$v['barcode'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field4 = 'H'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field4,$v['planQty'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field4 = 'I'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field4,$v['count'],
PHPExcel_Cell_DataType::TYPE_STRING);
$field4 = 'J'.($k+2);
$objPHPExcel->getActiveSheet()->setCellValueExplicit($field4,$v['diff'],
PHPExcel_Cell_DataType::TYPE_STRING);
}
// exit;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
// 到浏览器
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="' . $file_name . '.xls"');
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$objWriter->save('php://output');
//$objWriter->save('e:\\temp\\'.$file_name.".xls");
}
PHP 导出Excel 的方法
最新推荐文章于 2022-04-18 14:23:46 发布