方法一
<?php
header("Content-Type: application/vnd.ms-excel");
Header("Accept-Ranges:bytes");
Header("Content-Disposition:attachment;filename=report.xls"); //$filename导出的文件名
header("Pragma: no-cache");
header("Expires: 0");
$txt = '<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT">
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name></x:Name>
<x:WorksheetOptions>
<x:DisplayGridlines/>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>';
echo "<table></table>";
<?php
方法二:
vendor('Excel.PHPExcel');
$objExcel = new PHPExcel();
$objActSheet = $objExcel->getSheet();
$objActSheet->setTitle(‘aa’);
//设置打印纸张A4
$objActSheet->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
//设置边距
$pageMargins = $objActSheet->getPageMargins();
$margin1 = 0.5 / 2.54;//0.5厘米,需要换算成像素
$margin2 = 0.7 / 2.54;//0.7厘米,需要换算成像素
$pageMargins->setTop($margin1); //上边距
$pageMargins->setBottom($margin1); //下
$pageMargins->setLeft($margin2); //左
$pageMargins->setRight($margin2); //右
$objActSheet->getColumnDimension('A')->setWidth(9);
$objActSheet->getColumnDimension('B')->setWidth(14);
$objActSheet->getColumnDimension('C')->setWidth(28);
$objActSheet->getColumnDimension('D')->setWidth(10);
$objActSheet->getColumnDimension('E')->setWidth(10);
$objActSheet->getColumnDimension('F')->setWidth(20);
$objActSheet->getRowDimension(1)->setRowHeight(30);
$objActSheet->getRowDimension(2)->setRowHeight(24);
$objActSheet->getRowDimension(3)->setRowHeight(18);
$objActSheet->getRowDimension(4)->setRowHeight(22);
$objActSheet->getRowDimension(5)->setRowHeight(22);
$objActSheet->getRowDimension(6)->setRowHeight(10);
$objActSheet->getRowDimension(7)->setRowHeight(1);
$objActSheet->getRowDimension(8)->setRowHeight(18);
//设置大标题
$objActSheet->setCellValue('A1', '情况表');
$objActSheet->mergeCells('A1:F1');
//设置字体
$objStyleA5 = $objActSheet->getStyle('A1');
$objFontA5 = $objStyleA5->getFont();
$objFontA5->setName('宋体');
$objFontA5->setSize(22);
//设置对齐方式
$objAlignA5 = $objStyleA5->getAlignment();
$objAlignA5->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objAlignA5->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);