| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 티스토리
- SKT
- 자바스크립트
- KB증권
- php
- PHP-FPM
- centos
- 알리익스프레스
- 알뜰폰
- OpenWrt
- 스톤에이지
- proxmox
- Apache
- 복현오거리
- 가상서버호스팅
- 윈도우10
- 아파치
- 킹북이초월
- nginx
- Rocky
- KB국민카드
- 램가스초월
- 리눅스
- iptime
- 소비전력
- jQuery
- Linux
- mysql
- 보르비스초월
- 시놀로지
- Today
- Total
맛집 여행 캠핑 일상 생활
[Linux] PHPExcel 대체용 PHPSpreadSheet 설치 방법 본문
728x90
PHP8.2 버전에서는 PHPExcel 이 엄청난 에러를 뿜어내는군요~
php 8.x 버전에서는 PhpSpreadSheet 를 사용하면 되네요~
먼저 /etc/php.ini 파일에서 allow_url_fopen 을 On 으로 되어 있어야 아래의 composer 가 실행이 됩니다.
설치하려는 위치에서 아래 명령어로 설치하면 됩니다.
cat /etc/php.ini | grep ^allow_url_fopen
sed -i 's/^allow_url_fopen\ =\ Off/allow_url_fopen = On/g' /etc/php.ini
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
composer require phpoffice/phpspreadsheet
sed -i 's/^allow_url_fopen\ =\ On/allow_url_fopen = Off/g' /etc/php.ini
의외로 간단하네요~
ls -l vendor 잘 설치가 되었는지 확인합니다.
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('memory_limit',-1);
$filename = "example.xls"; // xls Xls, xlsx Xlsx
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)
->mergeCells('A1:E1')
->setCellValue('A1', '[PHP Spread Sheet Example]');
$spreadsheet->setActiveSheetIndex(0)
->setCellValue('A2', 'T1')
->setCellValue('B2', 'T2')
->setCellValue('C2', 'T3')
->setCellValue('D2', 'T4')
->setCellValue('E2', 'T5');
// Rename worksheet
$spreadsheet->getActiveSheet()->setTitle('Sheet');
$objWriter = IOFactory::createWriter($spreadsheet, 'Xls');
$objWriter->save('php://output');
?>
위 내용으로 excel.php 를 만들어서 다운로드 테스트를 합니다.
728x90
반응형
'LINUX' 카테고리의 다른 글
| [Rocky] docker certbot duckdns 인증서 발급 방법 (0) | 2025.04.29 |
|---|---|
| [Linux] Apache NGINX duckdns.org certbot 인증서 발급 방법 (0) | 2025.04.29 |
| [Linux] CentOS 7.x 지원 종료로 인한 yum update 에러 (0) | 2025.04.11 |
| [Linux] CentOS 7.x xtables-addons 설치 방법 (0) | 2025.04.04 |
| [Linux] Rocky 9 리눅스 xtables-addons 설치 방법 (0) | 2025.04.04 |
Trackback : | Comments :