public function send_export(){
Loader::import('PHPExcel.Classes.PHPExcel');
Loader::import('PHPExcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
Loader::import('PHPExcel.Classes.PHPExcel.Reader.Excel2007');
Loader::import('PHPExcel.Classes.PHPExcel.Reader.Excel5');
$obj = new \PHPExcel();
$obj->getActiveSheet(0)->setTitle('sheet1'); //设置sheet名称
$activeSheet = $obj->getActiveSheet();
$activeSheet->mergeCells('A1:G1');
$activeSheet->mergeCells('A2:G2');
$activeSheet->mergeCells('B5:C5');
$activeSheet->mergeCells('B6:C6');
$activeSheet->mergeCells('B7:C7');
$activeSheet->mergeCells('D5:E5');
$activeSheet->mergeCells('D6:E6');
$activeSheet->mergeCells('D7:E7');
$activeSheet->mergeCells('F5:G5');
$activeSheet->mergeCells('F6:G6');
$activeSheet->mergeCells('F7:G7');
$obj->getDefaultStyle()->getFont()->setName('微软雅黑');//字体
$obj->getActiveSheet()->getStyle('A1:G7')->getAlignment()
->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);//文字居中
$obj->getActiveSheet()->getStyle('A1:G2')->getFont()->setSize(14);//字体大小
$activeSheet->getDefaultColumnDimension()->setWidth(11);
$obj->getActiveSheet()->getRowDimension(1)->setRowHeight(55);
$obj->getActiveSheet()->getRowDimension(2)->setRowHeight(55);
$obj->getActiveSheet()->getRowDimension(3)->setRowHeight(55);
$obj->getActiveSheet()->getRowDimension(4)->setRowHeight(55);
$obj->getActiveSheet()->getRowDimension(5)->setRowHeight(55);
$obj->getActiveSheet()->getRowDimension(6)->setRowHeight(55);
$obj->getActiveSheet()->getRowDimension(7)->setRowHeight(55);
//所有垂直居中
$obj->getActiveSheet()->getStyle('A1:G7')
->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
//***********************画出单元格边框*****************************
$styleArray = array(
'borders' => array(
'allborders' => array(
//'style' => PHPExcel_Style_Border::BORDER_THICK,//边框是粗的
'style' => \PHPExcel_Style_Border::BORDER_THIN,//细边框
//'color' => array('argb' => 'FFFF0000'),
),
),
);
$activeSheet->getStyle('A1:G7')->applyFromArray($styleArray);//这里就是画出从单元格A5到N5的边框,看单元格最右边在哪哪个格就把这个N改为那个字母替代
//***********************画出单元格边框结束*****************************
$obj->setActiveSheetIndex(0)->setCellValue('A1', '我们的有限公司');
$obj->getActiveSheet(0)->setCellValue('A2', '出货装箱单');
$obj->getActiveSheet(0)->setCellValue('A3', '出货日期');
$obj->getActiveSheet(0)->setCellValue('B3', '商品名称');
$obj->getActiveSheet(0)->setCellValue('C3', '箱数');
$obj->getActiveSheet(0)->setCellValue('D3', '出货数量/件');
$obj->getActiveSheet(0)->setCellValue('E3', '重量/KG');
$obj->getActiveSheet(0)->setCellValue('F3', '出货国家');
$obj->getActiveSheet(0)->setCellValue('G3', '物流公司');
// $obj->getActiveSheet(0)->setCellValue('A4', '2019-01-23');
// $obj->getActiveSheet(0)->setCellValue('D4', '5');
// $obj->getActiveSheet(0)->setCellValue('F4', '美国');
// $obj->getActiveSheet(0)->setCellValue('G4', '跨境易通');
$obj->getActiveSheet(0)->setCellValue('A5', '发货人:');
$obj->getActiveSheet(0)->setCellValue('D5', '物流公司签名:');
$obj->getActiveSheet(0)->setCellValue('A6', '审核:');
$obj->getActiveSheet(0)->setCellValue('D6', '司机签字:');
$obj->getActiveSheet(0)->setCellValue('D7', '车牌号:');
$objWrite = \PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
header('pragma:public');
header("Content-Disposition:attachment;filename=出货装箱单.xlsx");
$objWrite->save('php://output');
exit;
}
如图: