include '/phpexcel/PHPExcel.php';
$excel = new
PHPExcel();
$objDrawing = new
PHPExcel_Worksheet_Drawing();
$excel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$excel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objActSheet =
$excel->getActiveSheet();
$letter =
array('A','B','C','D','E','F','G','H','I','J','K','L','M','N');
$tableheader =
array('姓名', '性别', '年龄', '班级', '头像');
for($i = 0;$i <
count($tableheader);$i++) {
$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");
}
$data = array(
array('小王', '男', '20', 'CS12',
'test.jpg'),
array('小李', '女', '21', 'CS12',
'test.jpg'),
array('小周', '男', '22', 'CS12',
'test.jpg'),
array('小赵', '女', '23', 'CS12',
'test.jpg'),
array('小张', '男', '24', 'CS12', 'test.jpg')
);
for ($i = 0;$i <
count($data);$i++) {
$j = $i + 2;
$objActSheet->getColumnDimension("$letter[$i]")->setWidth(20);
$excel->getActiveSheet()->getRowDimension($j)->setRowHeight(100);
for ($row = 0;$row < count($data[$i]);$row++)
{
if ($row
== (count($data[$i]) -1 )) {
$objDrawing = new
PHPExcel_Worksheet_Drawing();
$objDrawing->setPath($data[$i][$row]);
$objDrawing->setHeight(100);
$objDrawing->setCoordinates("$letter[$row]$j");
$objDrawing->setOffsetX(80);
$objDrawing->setRotation(20);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(50);
$objDrawing->setWorksheet($excel->getActiveSheet());
continue;
}
$excel->getActiveSheet()->setCellValue("$letter[$row]$j","111");
}
}
$write = new
PHPExcel_Writer_Excel5($excel);
header("Pragma:
public");
header("Expires:
0");
header("Cache-Control:must-revalidate, post-check=0,
pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="测试文件.xls"');
header("Content-Transfer-Encoding:binary");
$write->save('php://output');