龙空技术网

上传excel文件生成HTML

夜尽相思 256

前言:

现在小伙伴们对“phpoffice导出商城订单”都比较珍视,大家都需要学习一些“phpoffice导出商城订单”的相关资讯。那么小编同时在网络上汇集了一些关于“phpoffice导出商城订单””的相关文章,希望大家能喜欢,我们快快来学习一下吧!

<?php/** * 安装excel处理类 composer require phpoffice/phpexcel * @return \think\response\Json * @throws \PHPExcel_Reader_Exception * @throws \PHPExcel_Writer_Exception * Created on 2018/12/26 23:29 * Created by Dh */public function excelToHtml(){ return $this->apiSuc(ActionExcel::excel2html(request()->file()));}/** * 逻辑处理 * 将excel生成HTML * @param $data 上传的excle文件对象 * @return array 更加excel的sheet生成的HTML文件访问路径数组 * @throws \PHPExcel_Reader_Exception * @throws \PHPExcel_Writer_Exception * Created on 2018/12/26 23:27 * Created by Dh */public static function excel2html($data){ $obj = $data['file']; //上传文件 $info = $obj->move(ROOT_PATH . 'public' . DS . 'uploads'. DS . 'file'); $filePath = $info->getPathname(); $externsion = $info->getExtension(); $fileFullName = $info->getFilename(); $htmlName = str_replace('.' . $externsion, '', $fileFullName); //文件名自动判断文件类型 $fileType = \PHPExcel_IOFactory::identify($filePath); $objReader = \PHPExcel_IOFactory::createReader($fileType); $objPHPExcel = $objReader->load($filePath); $sheetIndex = $objPHPExcel->getSheetCount(); $objWriter = new \PHPExcel_Writer_HTML($objPHPExcel); //可以将括号中的0换成需要操作的sheet索引 $sheetHtml = []; for ($i = 0;$i < $sheetIndex;$i++) { //这里记得将文件名包含进去 $savePath = ROOT_PATH . 'public' . DS . 'uploads' . DS . 'html' . DS . $htmlName . '_' . ($i+1) . '.html'; $objWriter->setSheetIndex($i); //保存为html文件 $objWriter->save($savePath); $downloadPath = config('setting.site_url') . '/uploads/html/'. $htmlName . '_' . ($i+1) . '.html'; array_push($sheetHtml, $downloadPath); } return $sheetHtml;}

标签: #phpoffice导出商城订单