Composer 下载地址 https://getcomposer.org/download/
页面中 Composer-Setup.exe 点击下载
安装步骤 百度经验链接
https://jingyan.baidu.com/article/f96699bbe16386894e3c1b36.html
安装完成 打开cmd 输入
D:\XAMPP7\htdocs\nongfutong\ThinkPHP\Library>composer
会显示
D:\XAMPP7\htdocs\nongfutong\ThinkPHP\Library>composer
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.7.2 2018-08-16 16:57:12
下载 phpspreadsheet 输入命令
composer require phpoffice/phpspreadsheet
我是本地已有 进行了更新操作 显示如下
Using version ^1.4 for phpoffice/phpspreadsheet
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 1 update, 0 removals
- Installing markbaker/complex (1.4.6): Loading from cache
- Updating phpoffice/phpspreadsheet (1.3.1 => 1.4.0): Loading from cache
Writing lock file
Generating autoload files
创建文件composer.json 告诉composer您的项目所依赖的包
注意位置 一定要是你项目的插件位置
文件内容
{
"require": {
"phpoffice/phpspreadsheet": "^1.4"
}
}
用cmd composer 安装 phpoffice/phpspreadsheet 注意位置 一定要是你项目的插件位置
D:\XAMPP7\htdocs\nong\ThinkPHP\Library>composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Installing psr/simple-cache (1.0.1): Loading from cache
- Installing phpoffice/phpspreadsheet (1.3.1): Loading from cache
phpoffice/phpspreadsheet suggests installing mpdf/mpdf (Option for rendering PDF with PDF Writer)
phpoffice/phpspreadsheet suggests installing dompdf/dompdf (Option for rendering PDF with PDF Writer)
phpoffice/phpspreadsheet suggests installing tecnick.com/tcpdf (Option for rendering PDF with PDF Writer)
phpoffice/phpspreadsheet suggests installing jpgraph/jpgraph (Option for rendering charts, or including charts with PDF or HTML Writers)
Writing lock file
Generating autoload files
更新composer update
D:\Library> composer update
之后要是添加别的需要用 也是用到 composer update 进行按照进的或者更新
D:\Library> composer update
Ok
创建php文件使用吧
require ‘vendor/autoload.php’;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue(‘A1‘, ‘Hello‘);
$sheet->setCellValue(‘A2‘, ‘Hello World‘);
$sheet->setCellValue(‘A3‘, ‘!‘);
$writer = new Xlsx($spreadsheet);
$writer->save(‘hello world.xlsx‘);
?>
默认保存到执行php的根目录,以thinkphp为例index.php在D:\wwwroot\thinkphp\public,那么文件就保存在这
注:如果不想保存到文件,可以传入php://output或php://stdout直接输出(例如html,输出网页)