/**
* 导出图片到excel
*/
public function picexporttest() {
$objPHPExcel = $this->app->loadClass('phpexcel');
// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
$temp = chr(intval(ord("A")) + 0) . 1;
//1.图片填充列
/* 实例化插入图片类 */
$objDrawing = new PHPExcel_Worksheet_Drawing();
/* 设置图片路径 切记:只能是本地图片 */
$dir = $_SERVER['DOCUMENT_ROOT'];
$objDrawing->setPath($dir."/friend.jpg");
/* 设置图片高度 */
$objDrawing->setHeight(10);
$objDrawing->setWidth(10);
/* 设置图片要插入的单元格 */
$objDrawing->setCoordinates($temp);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
// 重命名 worksheet
$objPHPExcel->getActiveSheet()->setTitle("aaaa");
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
$filename = iconv("utf-8", "gb2312", $filename.date('Y-m-d'));
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$filename.'.xlsx"');
header('Cache-Control: max-age=0');
//注意这里 第二个参数写成 'Excel2007' 会避免特殊字符或中文乱码
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
}
宠物免费领养小程序,欢迎来踩