용량 큰 엑셀 파일 처리엔 Spout
최근에 파일 용량이 큰 엑셀 파일을 읽어서 DB에 데이터를 기록하는 걸 개발했는데
용량이 크니까 PHPExcel 에서는 처리가 되지 않고 오류를...
그래서 찾아낸 Spout : https://github.com/box/spout
개발환경이 PHP 5.6.x 라서 이 버전에 사용할 수 있는 2.7.3 버전을 사용했습니다.
설치는 컴포저로 했으며 만약 컴포저 사용이 어려울 때는 아래의 require 코드를 추가해줍니다.
버전 3.x 에서는 class 명 등이 변경됐으니 그에 맞게 사용하면 됩니다.
[code]
require_once '[PATH/TO]/src/Spout/Autoloader/autoload.php';
[/code]
[code]
<?php
ini_set('memory_limit', '-1');
ini_set('max_execution_time', '0');
$file = __DIR__.'/patent.xlsx';
use Box\Spout\Reader\ReaderFactory;
use Box\Spout\Common\Type;
$reader = ReaderFactory::create(Type::XLSX);
$reader->open($file);
foreach ($reader->getSheetIterator() as $sheet) {
//if ($sheet->getIndex() > 0)
// break;
foreach ($sheet->getRowIterator() as $row) {
print_r($row);
}
}
$reader->close();
[/code]
실제 사용해본 경험으로는 11MB 정도의 엑셀 파일을 읽고 데이터를 입력하는데 10초 정도
소요되는 듯 했습니다. 물론 이 시간은 서버 환경 등에 따라 달라질 수 있습니다.
댓글 13개
좋은 정보 감사합니다.~
감사합니다.
https://opensource.box.com/spout/docs/
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4766 | jQuery | 8년 전 | 1671 | ||
| 4765 | jQuery | 8년 전 | 1348 | ||
| 4764 | jQuery | 8년 전 | 2159 | ||
| 4763 | jQuery | 8년 전 | 1853 | ||
| 4762 | jQuery | 8년 전 | 1625 | ||
| 4761 | jQuery | 8년 전 | 1932 | ||
| 4760 | jQuery | 8년 전 | 1294 | ||
| 4759 | jQuery | 8년 전 | 1596 | ||
| 4758 | jQuery | 8년 전 | 1310 | ||
| 4757 | jQuery | 8년 전 | 1273 | ||
| 4756 | jQuery | 8년 전 | 1495 | ||
| 4755 | jQuery | 8년 전 | 1646 | ||
| 4754 | jQuery | 8년 전 | 1611 | ||
| 4753 | jQuery | 8년 전 | 1766 | ||
| 4752 | jQuery | 8년 전 | 1519 | ||
| 4751 | jQuery | 8년 전 | 1838 | ||
| 4750 | jQuery | 8년 전 | 1980 | ||
| 4749 | jQuery | 8년 전 | 1439 | ||
| 4748 | PHP | 8년 전 | 2809 | ||
| 4747 | jQuery | 8년 전 | 1389 | ||
| 4746 | jQuery | 8년 전 | 1645 | ||
| 4745 | jQuery | 8년 전 | 1651 | ||
| 4744 | jQuery | 8년 전 | 1529 | ||
| 4743 | jQuery | 8년 전 | 1612 | ||
| 4742 | jQuery | 8년 전 | 1701 | ||
| 4741 | jQuery | 8년 전 | 1597 | ||
| 4740 | jQuery | 8년 전 | 1600 | ||
| 4739 | jQuery | 8년 전 | 1795 | ||
| 4738 | jQuery | 8년 전 | 1306 | ||
| 4737 | jQuery | 8년 전 | 2096 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기