웹프로그래밍

Global It Leader!!


PHP


 
 

엑셀 파일 읽기 소스

페이지 정보

작성자 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 2,477회 작성일 21-03-30 08:48

본문

PHP 에서 엑셀 파일을 읽어 들이는 예제입니다.

PHPExcel (https://phpexcel.codeplex.com/) 을 이용한 예제입니다.

<?php
require_once dirname(__FILE__) . '/../Classes/PHPExcel/IOFactory.php';

$filepath = "test.xlsx";

$filetype = PHPExcel_IOFactory::identify($filepath);
$reader = PHPExcel_IOFactory::createReader($filetype);
$php_excel = $reader->load($filepath);

$sheet = $php_excel->getSheet(0);           // 첫번째 시트
$maxRow = $sheet->getHighestRow();          // 마지막 라인
$maxColumn = $sheet->getHighestColumn();    // 마지막 칼럼

$target = "A"."1".":"."$maxColumn"."$maxRow";
$lines = $sheet->rangeToArray($target, NULL, TRUE, FALSE);

// 라인수 만큼 루프
foreach ($lines as $key => $line) {
    $col = 0;
    $item = array(
        "A"=>$line[$col++],   // 첫번째 칼럼
        "B"=>$line[$col++],   // 두번쨰 칼럼
    );

    print_r($item["A"] .",". $item["B"] ."<br/>");
}

PHPExcel 예제들이 너무 많아서 혼란스러울 수 있습니다.

단순히 읽는 용도로 사용할 경우 위의 소스를 응용해서 간단하게 프로그래밍할 수 있습니다.

댓글목록

등록된 댓글이 없습니다.

전체 92
게시물 검색
PHP 목록
번호 제목 글쓴이 조회 날짜
92 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 112 01-06
91 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 122 12-22
90 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 191 10-09
89 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 205 10-09
88 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 208 10-08
87 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 245 09-03
86 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 232 07-26
85 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 235 07-26
84 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 231 07-07
83 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 218 07-07
82 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 222 06-15
81 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 287 04-23
80 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1675 03-29
79 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4119 03-26
78 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1858 03-26
77 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1662 03-17
76 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2391 11-28
75 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2583 08-11
74 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2195 08-10
73 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2817 08-02