关于TP5.1使用phpexcel

安装composer,不懂请跳:https://blog.csdn.net/qq_31164125/article/details/80455215

安装好了之后,windows DOS命令进入当前网站的目录。比如,我的网站名称叫tp5.1,那就直接进到此目录

composer require phpoffice/phpspreadsheet

composer require phpoffice/phpexcel

输入运行这两个命令。

在需要引用PHPexcel这个第三方类库的当前文件的顶部直接调用(切记,5.1已经弃用了vendor方法和load::import方法)

namespace app\index\controller;
use think\Controller;
use PHPExcel;
use PHPExcel_IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use PhpOffice\PhpSpreadsheet\IOFactory;
use Db;
class Index extends Controller
{
    public function index()
    {  
    	$objPHPExcel = new PHPExcel();  //excel对象
		$Worksheet = new \PHPExcel_Worksheet();
		$PHPExcel_Cell = new \PHPExcel_Cell(null,null,$Worksheet);
       return $this->fetch('index');
    }

直接这样就可以使用了

猜你喜欢

转载自blog.csdn.net/qq_31164125/article/details/82837485