PHPexcel 에서 에러가 발생합니다.

PHPexcel 에서 에러가 발생합니다.

QA

PHPexcel 에서 에러가 발생합니다.

본문

아래 첨부한 소스를 사용해

한 행의 범위가 A~ AC까지 되어있는 xlsx 파일을 

phpexcel을 통해 sql로 업로드하려고 합니다.

헌데 파일을 업로드하면 계속 에러가 뜹니다..ㅠ

무엇이 문제 일까요..?

 

아래 코드는 메인 폼에서 파일을 업로드하고 난뒤 불러지는 proc파일입니다..

 

 


<?
include_once('./_common.php'); //database설정관련 
include 'Classes/PHPExcel.php'; 
include 'Classes/PHPExcel/IOFactory.php'; //phpexcel 불러오기 

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

try {
    $objPHPExcel = PHPExcel_IOFactory::load($up_file);
    $objReader = PHPExcel_IOFactory::createReaderForFile($up_file);
    
    //읽기전용으로 set
    $objReader->setReadDataOnly(true);
    
    //엑셀파일 읽기
    $objExcel = $objReader->load($up_file);
    // 첫번째 시트를 선택
    $objExcel->setActiveSheetIndex(0);
    
    $objWorksheet = $objExcel->getActiveSheet();
    $rowIterator = $objWorksheet->getRowIterator();
 
    foreach ($rowIterator as $row) {
               $cellIterator = $row->getCellIterator();
               $cellIterator->setIterateOnlyExistingCells(false);
    }
    
    $maxRow = $objWorksheet->getHighestRow();
    $maxCell = $objWorksheet->getHighestColumn();
     for ($i = 0 ; $i <= $maxRow; $i++) {
         
               $acell = $objWorksheet->getCell('A' . $i)->getValue(); // A열
               $bcell = $objWorksheet->getCell('B' . $i)->getValue(); // B열 
 
               $ccell = $objWorksheet->getCell('C' . $i)->getValue(); // C열 
               $dcell = $objWorksheet->getCell('D' . $i)->getValue(); // D열
               $ecell = $objWorksheet->getCell('E' . $i)->getValue();  // E열 
         
                $fcell = $objWorksheet->getCell('F' . $i)->getValue(); // A열
               $gcell = $objWorksheet->getCell('G' . $i)->getValue(); // B열 
 
               $hcell = $objWorksheet->getCell('H' . $i)->getValue(); // C열 
               $icell = $objWorksheet->getCell('I' . $i)->getValue(); // D열
               $jcell = $objWorksheet->getCell('J' . $i)->getValue();  // E열 
         
                $kcell = $objWorksheet->getCell('K' . $i)->getValue(); // A열
               $lcell = $objWorksheet->getCell('L' . $i)->getValue(); // B열 
 
               $mcell = $objWorksheet->getCell('M' . $i)->getValue(); // C열 
               $ncell = $objWorksheet->getCell('N' . $i)->getValue(); // D열
               $ocell = $objWorksheet->getCell('O' . $i)->getValue();  // E열 
         
                $pcell = $objWorksheet->getCell('P' . $i)->getValue(); // A열
               $qcell = $objWorksheet->getCell('Q' . $i)->getValue(); // B열 
 
               $rcell = $objWorksheet->getCell('R' . $i)->getValue(); // C열 
               $scell = $objWorksheet->getCell('S' . $i)->getValue(); // D열
               $tcell = $objWorksheet->getCell('T' . $i)->getValue();  // E열 
         
                 $ucell = $objWorksheet->getCell('U' . $i)->getValue(); // A열
               $vcell = $objWorksheet->getCell('V' . $i)->getValue(); // B열 
 
               $wcell = $objWorksheet->getCell('W' . $i)->getValue(); // C열 
               $xcell = $objWorksheet->getCell('X' . $i)->getValue(); // D열
               $ycell = $objWorksheet->getCell('Y' . $i)->getValue();  // E열 
         
                $zcell = $objWorksheet->getCell('Z' . $i)->getValue(); // A열
               $aacell = $objWorksheet->getCell('AA' . $i)->getValue(); // B열 
 
               $abcell = $objWorksheet->getCell('AB' . $i)->getValue(); // C열 
               $accell = $objWorksheet->getCell('AC' . $i)->getValue(); // D열
                  if (empty($bcell)) {continue;}  // no value for bcat so go to the next row
               // 날짜 형태의 셀을 읽을때는 toFormattedString를 사용한다.
               //$h = PHPExcel_Style_NumberFormat::toFormattedString($h, 'YYYY-MM-DD');
 
      //   echo $a . " / " . $b. " / " . $c . " / " . $d . " / " . $e . " / " . $f . " / " . $g . " <br>\n";
    
              $acell  = addslashes($acell);
             $bcell  = addslashes($bcell);
             $ccell  = addslashes($ccell);
             $dcell  = addslashes($dcell);
             $ecell  = addslashes($ecell);
              $fcell  = addslashes($fcell);
             $gcell  = addslashes($gcell);
             $hcell  = addslashes($hcell);
             $icell  = addslashes($icell);
             $jcell  = addslashes($jcell);
              $kcell  = addslashes($kcell);
             $lcell  = addslashes($lcell);
             $mcell  = addslashes($mcell);
             $ncell  = addslashes($ncell);
             $ocell  = addslashes($ocell);
              $pcell  = addslashes($pcell);
             $qcell  = addslashes($qcell);
             $rcell  = addslashes($rcell);
             $scell  = addslashes($scell);
             $tcell  = addslashes($tcell);
              $ucell  = addslashes($ucell);
             $vcell  = addslashes($vcell);
             $wcell  = addslashes($wcell);
             $xcell  = addslashes($xcell);
             $ycell  = addslashes($ycell);
              $zcell  = addslashes($zcell);
             $aacell  = addslashes($aacell);
             $abcell  = addslashes($abcell);
             $accell  = addslashes($accell);

 
          //$sql = "insert into echo_test (a,b,c,d,e) values ('$a','$b','$c','$d','$e')";
          $sql = "    insert into echo_excel set 
              bcat = '$acell',
            scat = '$bcell',
            partnumber = '$ccell',
            frequency_gbn = '$dcell',    
            sfrequency = '$ecell',
            efrequency = '$fcell',
            frequency = '$gcell',
            ilbw = '$hcell',
            rlbw = '$icell',
            ripple = '$jcell',
            rejection = '$kcell',
            imp = '$lcell',
            type = '$mcell',
            size = '$ncell',
            centernotch = '$ocell',
            notchbw = '$pcell',
            ilpass = '$qcell',
            nomux = '$rcell',
            isolation = '$scell',
            inputpower = '$tcell',
            noofway = '$ucell',
            connector = '$vcell',
            coupling = '$wcell',
            directivity = '$xcell',
            lowfreq = '$ycell',
            highfreq = '$zcell',
            channels = '$aacell',
            switchspeed = '$abcell',
            controlmethod = '$accell'
          ";
          sql_query($sql);

      }
   echo $maxRow . " Data inserting finished !";
 
} catch (exception $e) {
    echo '엑셀파일을 읽는도중 오류가 발생하였습니다.!';
}
?>
 

이 질문에 댓글 쓰기 :

답변 1

답변을 작성하시기 전에 로그인 해주세요.
전체 28
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT