php提取excel图片路径,PHP读取Excel图片对象,并保存替换为相对路径,对象已打开进行读取...

PHP读取Excel图片对象,并保存替换为相对路径PHP读取擅长图片对象,并保存替换为相对路径,下面由教程栏目给大家介绍服务器端编程语言(专业超文本预处理器的缩写)读取擅长图片对象,并保存替换为相对路径方法,希望对需要的朋友有所帮助!

服务器端编程语言(专业超文本预处理器的缩写)利用phpspredadssheet和xlswriter读取擅长图片对象,保存替换为相对路径

?服务器端编程语言(专业超文本预处理器的缩写)

/**

*由PhpStorm创建。

*用户:管理员

*日期: 2021/1/11 0011

*时间: 8:59

*/

命名空间应用程序\服务;

使用PhPoffice \ phpspredsheet \ Cell \ Coordinate;

使用PhPoffice \ PhPSPredssheet \异常;

使用PhPoffice \ phpspredsheet \ IOFactory;

使用PhpOffice \ PhpSpreadsheet \电子表格;

使用PhpOffice \ PhpSpreadsheet \工作表\绘图;

使用Vtiful \内核\ Excel

/**

* 读取擅长图片并保存其路径

*类ExcelImagePathServer

* @包应用程序\服务

*/

类ExcelImagePathServer

{

/**

* @var字符串

*/

protected $ relative _ path=’/images ‘;

/**

* @var电子表格

*/

受保护的$电子表格;

/**

* @var Excel

*/

受保护的$ xls _ writer

/**

* @var Excel

*/

受保护的$ sheet _ writer

/**

* @var字符串

*/

受保护的$ image _ path

/**

* ExcelImagePathServer构造函数。

* @param string $excel_file

* @抛出\ PhpOFFiCE \ PhpPredssheet \ Reader \异常

*/

public function _ _ construct($ excel _ file)

{

$ reader=io factory : create reader(‘ Xlsx ‘);

$这个-电子表格=$ reader-load($ excel _ file);

$ config=[‘ path ‘=dirname($ excel _ file)];

$ this-xls _ writer=new Excel($ config);

$ this-image _ path=dirname($ excel _ file).$ this-relative _ path;

if(!is_dir($this-image_path)) {

mkdir($this-image_path,0755);

}

}

/**

* @引发异常

*/

公共函数句柄()

{

$ write _ filename=date(‘ YmdHis ‘). xlsx ‘;

$工作表数=$ this-电子表格-GetSheetCount();

for($ I=0;$ i $ sheetCount$i ) {

$工作表=$这个-电子表格-GetSheet($ I);

$ data=$工作表-to array();

$ sheet name=$ this-电子表格-GetSheetNames();

var_dump($sheetCount,$ sheet names

//读取并修改

foreach($工作表-GetDrawingCollection()(作为$drawing) {

/**@var $drawing Drawing* */

list($startColumn,$ start row)=坐标:3360从字符串开始协调($ drawing-GetCoords());

$image_filename=’/{$i}-‘ .$ drawing-GetCoords();

$ image _ suffix=$ this-保存图像($ drawing,$ image _ filename);

$ image _ name=ltrim($ this-relative _ path,’/’).{$image_filename} .{ $ image _ suffix } ‘;

var _ dump($ image _ name);

$ start column=$ this-ABC2d decimal($ start column);

$ data[$ StartRow-1][$ StartColumn]=$ image _ name;

}

//写入文件

if ($i==0) {

$ this-sheet _ writer=$ this-xls _ writer-fileName($ write _ fileName,$ sheet name[$ I])-data($ data);

} else {

//向文件中追加工作表

$ this-sheet _ writer-addSheet($ sheet name[$ I])-data($ data);

}

}

//最后的最后,输出文件

$ FilePath=$ this-sheet _ writer-output();

var _ dump($ FilePath);

}

/**

* 保存图片

*

* @参数绘图$绘图

* @param $image_filename

* @返回字符串

* @引发异常

*/

受保护的函数保存图像(绘图$drawing,$image_filename)

{

$image_filename .=’.’。$ drawing-GetExtension();

switch($ drawing-GetExtension()){

case ‘jpg’:

大小写jpeg’:

$ source=imagecreatefrom JPEG($ drawing-GetPath());

imagejpeg($source,$this-image_path .$ image _ filename);

打破;

case ‘gif’:

$ source=imagecreatefromgif($ drawing-GetPath());

imagegif($source,$this-image_path .$ image _ filename);

打破;

case ‘png’:

$ source=imagecreatefrompng($ drawing-GetPath());

imagepng($source,$this-image_path .$ image _ filename);

打破;

默认值:

引发新异常(‘图像格式错误!’);

}

return $ drawing-GetExtension();

}

/**

* 坐标转换

*

* @param $abc

* @return float|int

*/

受保护的功能ABC 2分类(ABC)

{

$ ten=0;

$ len=strlen($ ABC);

for($ I=1;$ i=$ len$i ) {

$char=substr($abc,0 – $i,1);//反向获取单个字符

$ int=order($ char);

$ten=($int – 65) * pow(26,$ I-1);

}

返还十美元;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值