Home  >  Article  >  PHP Framework  >  An article explaining how thinkphp refers to the PHPExcel class library

An article explaining how thinkphp refers to the PHPExcel class library

藏色散人
藏色散人forward
2021-11-25 14:34:342096browse

The followingthinkphp frameworkThe tutorial column will introduce to you how thinkphp refers to the PHPExcel class library. I hope it will be helpful to friends in need!

Problem description:

thinkphp3.2.3 How to reference the PHPExcel class library?

Introducing the file directory location

ThinkPHP\Library\Org\Util
PHPExce(文件夹)
PHPExcel.php

As shown

An article explaining how thinkphp refers to the PHPExcel class library

Method code

public function getExcel()
    {
        //导入PHPExcel类库
        import("Org.Util.PHPExcel");
        import("Org.Util.PHPExcel.Writer.Excel5");
        import("Org.Util.PHPExcel.IOFactory.php");
        //创建PHPExcel对象
        $objPHPExcel = new \PHPExcel();
    }

An article explaining how thinkphp refers to the PHPExcel class library

Then I executed the program and it said that the class library does not exist

An article explaining how thinkphp refers to the PHPExcel class library

Problem analysis and methods:

It is not recommended to use third-party class libraries Place it under Org\Util. Thinkphp specially provides the function of importing third-party class libraries. Directly put your PHPExcel under the directory vendor (ThinkPHPLibraryVendor),

An article explaining how thinkphp refers to the PHPExcel class library

When using Use the vendor method to import

//相当于引入了vemdor目录下面PHPExcel\PHPExcel.php
vendor('PHPExcel.PHPExcel');
$x = new \PHPExcel();
//vendor('PHPExcel.PHPExcel');
//vendor('PHPExcel.PHPExcel.Writer.Excel5');
//vendor('PHPExcel.PHPExcel.IOFactory.php');

Recommended: "The latest 10 thinkphp video tutorials"

The above is the detailed content of An article explaining how thinkphp refers to the PHPExcel class library. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete