Home > PHP Framework > ThinkPHP > body text

An article explaining how thinkphp refers to the PHPExcel class library

藏色散人
Release: 2021-11-25 14:34:34
forward
2136 people have browsed it

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
Copy after login

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();
    }
Copy after login

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');
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template