[php] PHPExcel插入图片

其它的代码就不贴了,直接上关键代码:

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objActSheet = $objPHPExcel->getActiveSheet();

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('avatar');
$objDrawing->setDescription('avatar');
$objDrawing->setPath(‘path_of_image/my_image.jpg’);
$objDrawing->setHeight(30);
$objDrawing->setWidth(30);
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

还有就是,是没有方法让图片嵌到单元格里面的,只能通过设置单元格的宽高来让图片显示在单元格里面,如

$objActSheet->getColumnDimension(‘A’)->setWidth(15);
$objActSheet->getRowDimension(1)->setRowHeight(40);

 

posted @ 2013-06-25 14:41 DavidHHuan 阅读(...) 评论(...) 编辑 收藏