当前位置: 移动技术网 > IT编程>开发语言>PHP > php更新修改excel中的内容实例代码

php更新修改excel中的内容实例代码

2019年03月30日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

//模板存放目录
$dir = $document_root.'/backoffice/admin/oemcheck/';

$templatename = '1.xlsx';
$outputfilename = '模板.xlsx';
$txt='test';

//实例化excel读取类
$phpreader = new phpexcel_reader_excel2007();
if(!$phpreader->canread($dir.$templatename)){
 $phpreader = new phpexcel_reader_excel5();
 if(!$phpreader->canread($dir.$templatename)){
  echo '无法识别的excel文件!';
  return false;
 }
}
//读取excel
$phpexcel = $phpreader->load($dir.$templatename);
//读取工作表1
$currentsheet = $phpexcel->getsheet(0);

$currentsheet->setcellvalue('b13',iconv('gbk','utf-8',$txt));//表头赋值//
//实例化excel写入类
$phpwriter = new phpexcel_writer_excel2007($phpexcel);
ob_start();
header("content-type: application/force-download");
header("content-type: application/octet-stream");
header("content-type: application/download");
header('content-disposition:attachment;filename="' .$outputfilename. '"');//输出模板名称
header("content-transfer-encoding: binary");
header("last-modified:".gmdate("d, d m y h:i:s")." gmt");
header('pragma: public');
header('expires: 30');
header('cache-control: public');
$phpwriter->save('php://output');

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网