웹프로그래밍

Global It Leader!!


PHP


 
 

엑셀 파일 읽기 소스

페이지 정보

작성자 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 2,177회 작성일 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 예제들이 너무 많아서 혼란스러울 수 있습니다.

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

댓글목록

등록된 댓글이 없습니다.

전체 80
게시물 검색
PHP 목록
번호 제목 글쓴이 조회 날짜
80 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1335 03-29
79 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3438 03-26
78 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1496 03-26
77 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1356 03-17
76 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1905 11-28
75 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2123 08-11
74 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1862 08-10
73 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2444 08-02
72 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2529 07-20
71 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1833 07-05
70 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2123 05-27
69 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2874 03-30
열람중 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2178 03-30
67 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2117 03-29
66 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2110 03-27
65 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2669 03-10
64 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2754 02-24
63 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2172 02-22
62 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3764 12-31
61 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2420 10-30