##导入类库
require
'PHPExcel/Classes/PHPExcel.php'
;
require
'PHPExcel/Classes/PHPExcel/Writer/Excel5.php'
;
##基础属性设定
$objPHPExcel
= \PHPExcel_IOFactory::load(
'a.xls'
);
$objPHPExcel
->setActiveSheetIndex(0);
$objPHPExcel
->getActiveSheet()->getDefaultStyle()->getFont()->setName(
'宋体'
);
$objPHPExcel
->getProperties()->setTitle(
'xxx'
);
##单元格编辑
$objPHPExcel
->getActiveSheet()->setCellValue(
'A3'
,
'xxx'
);
##单元格绘图
$objDrawing
=
new
\PHPExcel_Worksheet_Drawing();
$objDrawing
->setPath(
'a.jpg'
);
$objDrawing
->setCoordinates(
'A4'
);
$objDrawing
->setName(
'Photo'
);
$objDrawing
->setDescription(
'Photo'
);
$objDrawing
->setHeight(120);
$objDrawing
->setWidth(100);
$objDrawing
->setOffsetX(7);
$objDrawing
->setOffsetY(7);
$objDrawing
->setWorksheet(
$objPHPExcel
->getActiveSheet());
##excel文件浏览器下载导出
$filename
=
'a.xls'
;
$encoded_filename
= rawurlencode(
$filename
);
$ua
=
$_SERVER
[
"HTTP_USER_AGENT"
];
header(
'Content-type: application/vnd.ms-excel'
);
if
(preg_match(
"/MSIE/"
,
$ua
) || preg_match(
"/Trident\/7.0/"
,
$ua
) || preg_match(
"/Edge/"
,
$ua
)) {
header(
'Content-Disposition: attachment; filename="'
.
$encoded_filename
.
'"'
);
}
else
if
(preg_match(
"/Firefox/"
,
$ua
)) {
header(
"Content-Disposition: attachment; filename*=\"utf8''"
.
$filename
.
'"'
);
}
else
{
header(
'Content-Disposition: attachment; filename="'
.
$filename
.
'"'
);
}
header(
"Pragma:no-cache"
);
header(
"Expires:0"
);
$objWriter
= PHPExcel_IOFactory::createWriter(
$objPHPExcel
,
'Excel5'
);
$objWriter
->save(
'php://output'
);
##excel文件html显示(可用于调试)
$objWriter
=
new
\PHPExcel_Writer_HTML(
$objPHPExcel
);
$objWriter
->save(
'php://output'
);