웹프로그래밍

Global It Leader!!


PHP


 
 

엑셀 파일 업로드 및 읽기

페이지 정보

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

본문

# 엑셀 파일 업로드 소스코드

 excel_upload.php

<html>

<head>

<title>:: PHPExcel 파일읽기 ::</title>

</head>

<form enctype="multipart/form-dataaction="./excel_read.phpmethod="post">

<table border="1">

<tr>

<th style="background-color:#DCDCDC">파일</th>

<td><input type="file" name="excelFile"/></td>

</tr>

<tr>

<th style="background-color:#DCDCDC">등록</th>

<td style="text-align:center;"><input type="submit" value="업로드"/></td>

</tr>

</form>

</html>


# 엑셀 파일 읽기 소스코드 

 excel_read.php 

<?php

include "./PHPExcel-1.8/Classes/PHPExcel.php";


$objPHPExcel = new PHPExcel();


// 엑셀 데이터를 담을 배열을 선언한다.

$allData = array();


// 파일의 저장형식이 utf-8일 경우 한글파일 이름은 깨지므로 euc-kr로 변환해준다.

$filename = iconv("UTF-8", "EUC-KR", $_FILES['excelFile']['name']);


try {

        // 업로드한 PHP 파일을 읽어온다. 

$objPHPExcel = PHPExcel_IOFactory::load($filename);

$sheetsCount = $objPHPExcel -> getSheetCount();


// 시트Sheet별로 읽기

for($i = 0; $i < $sheetsCount; $i++) {


          $objPHPExcel -> setActiveSheetIndex($i);

          $sheet = $objPHPExcel -> getActiveSheet();

          $highestRow = $sheet -> getHighestRow();    // 마지막 행

          $highestColumn = $sheet -> getHighestColumn(); // 마지막 컬럼


          // 한줄읽기

          for($row = 1; $row <= $highestRow; $row++) {


            // $rowData가 한줄의 데이터를 셀별로 배열처리 된다.

            $rowData = $sheet -> rangeToArray("A" . $row . ":" . $highestColumn . $row, NULL, TRUE, FALSE);


            // $rowData에 들어가는 값은 계속 초기화 되기때문에 값을 담을 새로운 배열을 선안하고 담는다.

            $allData[$row] = $rowData[0];

          }

}

} catch(exception $e) {

echo $e;

}


echo "<pre>";

print_r($allData);

echo "</pre>";

?>

댓글목록

등록된 댓글이 없습니다.

전체 80
게시물 검색
PHP 목록
번호 제목 글쓴이 조회 날짜
80 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1370 03-29
79 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3542 03-26
78 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1536 03-26
77 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1386 03-17
76 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1953 11-28
75 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2157 08-11
74 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1891 08-10
73 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2489 08-02
72 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2565 07-20
71 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 1860 07-05
70 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2157 05-27
열람중 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2919 03-30
68 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2211 03-30
67 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2149 03-29
66 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2144 03-27
65 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2726 03-10
64 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2851 02-24
63 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2204 02-22
62 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3868 12-31
61 no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 2451 10-30