linux/php

PhpSpreadsheet 설치하기

mysop 2021. 12. 7. 17:36
반응형

공식 Git hub에 방법은 다 나와있지만..

https://github.com/PHPOffice/PhpSpreadsheet

 

composer로 설치를 해보자..

 

$ composer require phpoffice/phpspreadsheet

이렇게 하면 설치가 진행된다

 

만일 아래와 같이 에러가 발생한다면...

[InvalidArgumentException]                                                                                                  
Package phpoffice/phpspreadsheet has requirements incompatible with your PHP version, PHP extensions and Composer version:  
- phpoffice/phpspreadsheet 1.20.0 requires ext-zip * but it is not present.

PHP버젼을 먼저 확인하고

PHP CLI에서 zip extension을 지원하는지 확인해 보자

 

위 에러는 ext-zip을 활성화 시켜서 설치를 성공했다.

 

$ composer require phpoffice/phpspreadsheet

Using version ^1.20 for phpoffice/phpspreadsheet
./composer.json has been updated
Running composer update phpoffice/phpspreadsheet
Loading composer repositories with package information
Updating dependencies
Lock file operations: 6 installs, 0 updates, 0 removals
  - Locking ezyang/htmlpurifier (v4.13.0)
  - Locking maennchen/zipstream-php (2.1.0)
  - Locking markbaker/complex (3.0.1)
  - Locking markbaker/matrix (3.0.0)
  - Locking myclabs/php-enum (1.8.3)
  - Locking phpoffice/phpspreadsheet (1.20.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 6 installs, 0 updates, 0 removals
  - Downloading myclabs/php-enum (1.8.3)
  - Downloading markbaker/matrix (3.0.0)
  - Downloading markbaker/complex (3.0.1)
  - Downloading maennchen/zipstream-php (2.1.0)
  - Downloading ezyang/htmlpurifier (v4.13.0)
  - Downloading phpoffice/phpspreadsheet (1.20.0)
  - Installing myclabs/php-enum (1.8.3): Extracting archive
  - Installing markbaker/matrix (3.0.0): Extracting archive
  - Installing markbaker/complex (3.0.1): Extracting archive
  - Installing maennchen/zipstream-php (2.1.0): Extracting archive
  - Installing ezyang/htmlpurifier (v4.13.0): Extracting archive
  - Installing phpoffice/phpspreadsheet (1.20.0): Extracting archive
4 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package sstalle/php7cc is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
14 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

이렇게 나오면 설치 성공

 

자 간단하게 서버안에 업로드된 xlsx파일을 출력해보자

<?php

require 'vendor/autoload.php';

use PhpOffice\PhpSpreadsheet\Spreadsheet; 
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;

//파일경로
$server_inputFileName='excel/journalist.xlsx';

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($server_inputFileName);
$spreadData = $spreadsheet-> getActiveSheet()->toArray();

print_r($spreadData);

 

복사하고 붙여넣기

 

출처 : https://m.blog.naver.com/lsw3210/221921395943

 

HTML 폼과 PhpSpreadsheet를 이용한 엑셀 파일 읽기

PhpSpreadsheet를 이용해서 엑셀 파일을 읽을 수도 있고, 엑셀 파일로 쓸 수도 있는데, 이전에 쓰기에 대...

blog.naver.com

 

728x90
반응형

'linux > php' 카테고리의 다른 글

값이 숫자인지 확인하는 함수  (0) 2022.04.20
실시간 화면 출력 꼼수..  (0) 2021.12.13
php 휴일을 제외한 업무 일수 계산  (0) 2021.12.02
php엑셀 한글깨짐  (0) 2021.11.05
php 쉘에서 실행시 parameter 받기  (0) 2021.10.25