Home  >  Article  >  Backend Development  >  PHPExcel导出插入图片和居中问题

PHPExcel导出插入图片和居中问题

WBOY
WBOYOriginal
2016-06-23 13:32:402794browse

首先到网上先下载PHPExcel

  下载后解压得到这两个文件

  

  下载后引用该文件

  

  最后编写相关代码:

  首先是图片插入导出

  

$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Photo');
$objDrawing->setDescription('Photo');
$objDrawing->setPath("./1.jpg");
$objDrawing->setHeight(375);
$objDrawing->setWidth(270);
$objDrawing->setCoordinates('L2');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
//打印图片

  其次是居中

$objPHPExcel->getActiveSheet()->getStyle('A1:K55')//改行表示A1-K55的单元格都居中
->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn