Home >Backend Development >PHP Tutorial >phpexcel 导出多张图片,该怎么解决

phpexcel 导出多张图片,该怎么解决

WBOY
WBOYOriginal
2016-06-13 12:14:381527browse

phpexcel 导出多张图片

本帖最后由 nzr_dream 于 2015-01-29 17:11:16 编辑 phpexcel 导出图片
   我在网上看了资料  都是导出一张图片,我想导出每行第一列是一个图片,如何实现,下边是一个导出的方法,我应该怎么加入哪?其他的数据都导出来了,就图片出不来,图片的路径信息保存到了$data二维数组下  。注:类库已导入。坐等。。。
<br />//写入excel<br />function getExcel($fileName,$headArr,$data){<br />    if(empty($data) || !is_array($data)){<br />        die("data must be a array");<br />    }<br />    if(empty($fileName)){<br />        exit;<br />    }<br />    $date = date("Y_m_d h:i:s",time());<br />    $fileName .= "_{$date}.xlsx";<br /> <br />    //创建新的PHPExcel对象<br />    $objPHPExcel = new PHPExcel();<br />    $objProps = $objPHPExcel->getProperties();<br />     <br />    //设置表头<br />    $key = ord("A");<br />    foreach($headArr as $v){<br />        $colum = chr($key);<br />        $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($colum.'1', $v);<br />        $key += 1;<br />    }<br />    <br />	//表数据<br />    $column = 2;<br />    $objActSheet = $objPHPExcel->getActiveSheet();<br />    foreach($data as $key => $rows){ //行写入<br />		$span = ord("A");<br />        foreach($rows as $keyName=>$value){// 列写入<br />            $j = chr($span);<br />           //我想在此处加入图片的code但是不成功,应该怎么写,请提示下<br /><br />            // $objDrawing = new PHPExcel_Worksheet_Drawing();<br />            // $objDrawing->setName(‘test’);<br />            // $objDrawing->setDescription(‘test’);<br />            // $objDrawing->setPath($data['imgurl']);<br />            // $objDrawing->setHeight(36);<br />            // $objDrawing->setCoordinates('');      这里应该怎么写??<br />            // $objDrawing->setWorksheet($objActSheet);<br /><br /><br />            $objActSheet->setCellValue($j.$column, $value);<br />            $span++;<br />        }<br />        $column++;<br />    }<br />	//重命名表<br />    $objPHPExcel->getActiveSheet()->setTitle('记录');<br />	$fileName = iconv("utf-8", "gb2312", $fileName);<br />	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');<br />	$objWriter->save($fileName); //脚本方式运行,保存在当前目录<br />	exit;<br />}<br />

------解决思路----------------------
1、被你注释掉的导出图片的代码中,你使用了全角的引号,应改为半角的
2、$objDrawing->setCoordinates('这里是单元格标识');
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