<?phprequire_once'PHPExcel/Classes/PHPExcel/IOFactory.php';$file_name='./1.xlsx';$objPHPExcelReader=PHPExc...
<?php
require_once 'PHPExcel/Classes/PHPExcel/IOFactory.php';
$file_name = './1.xlsx';
$objPHPExcelReader = PHPExcel_IOFactory::load($file_name);
$sheet = $objPHPExcelReader->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$data = [];
function createPic($data, $filename)
{
$src="./1.jpg";
$info=getimagesize($src);
$image=imagecreatefromjpeg($src);
$color=imagecolorallocate($image,100,100,100);
$font=realpath('./msyh.ttf');
foreach ($data as $key=>$pos) {
//使用指定的字体文件绘制文字
//参数2:字体大小
//参数3:字体倾斜的角度
//参数4、5:文字的x、y坐标
//参数6:文字的颜色
//参数7:字体文件
//参数8:绘制的文字
imagettftext($image, 9, 0, $pos[0], $pos[1], $color, $font, $key);
}
header("content-type:".$info['mime']);
imagejpeg($image,"./pics/{$filename}.jpg",100);
imagedestroy($image);
unset($image);
}
for ($start = 3; $start <= $highestRow; $start++) {
$filename = $sheet->getCell("A{$start}")->getValue();
$item_1 = $sheet->getCell("B{$start}")->getValue();
$item_2 = str_replace("/","\n",$sheet->getCell("C{$start}")->getValue());
$item_3 = $sheet->getCell("D{$start}")->getValue();
$item_4 = str_replace("/","\n",$sheet->getCell("E{$start}")->getValue());
$item_5 = $sheet->getCell("F{$start}")->getValue();
$item_6 = $sheet->getCell("G{$start}")->getValue();
$data=[];
$data[$item_1.' ']=[442,105];
$data[$item_2]=[403,170];
$data[$item_3]=[508,170];
$data[$item_4]=[655,170];
$data[$item_5]=[764,170];
$data[$item_6]=[905,170];
createPic($data,$filename);
}
全文详见:http://xpxw.com/?id=140