테스트 사이트 - 개발 중인 베타 버전입니다

PHPexcel 에서 에러가 발생합니다. 채택완료

시우우 6년 전 조회 4,075

아래 첨부한 소스를 사용해

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

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

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

무엇이 문제 일까요..?

 

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

 

 

</p>

<p><?

include_once('./_common.php'); //database설정관련 

include 'Classes/PHPExcel.php'; 

include 'Classes/PHPExcel/IOFactory.php'; //phpexcel 불러오기 </p>

<p>

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

<p>

try {

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

    $objReader = PHPExcel_IOFactory::createReaderForFile($up_file);

    

    //읽기전용으로 set

    $objReader->setReadDataOnly(true);

    

    //엑셀파일 읽기

    $objExcel = $objReader->load($up_file);</p>

<p>    // 첫번째 시트를 선택

    $objExcel->setActiveSheetIndex(0);

    

    $objWorksheet = $objExcel->getActiveSheet();</p>

<p>    $rowIterator = $objWorksheet->getRowIterator();</p>

<p> 

    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열</p>

<p>               $bcell = $objWorksheet->getCell('B' . $i)->getValue(); // B열 

 

               $ccell = $objWorksheet->getCell('C' . $i)->getValue(); // C열 </p>

<p>               $dcell = $objWorksheet->getCell('D' . $i)->getValue(); // D열</p>

<p>               $ecell = $objWorksheet->getCell('E' . $i)->getValue();  // E열 

         

                $fcell = $objWorksheet->getCell('F' . $i)->getValue(); // A열</p>

<p>               $gcell = $objWorksheet->getCell('G' . $i)->getValue(); // B열 

 

               $hcell = $objWorksheet->getCell('H' . $i)->getValue(); // C열 </p>

<p>               $icell = $objWorksheet->getCell('I' . $i)->getValue(); // D열</p>

<p>               $jcell = $objWorksheet->getCell('J' . $i)->getValue();  // E열 

         

                $kcell = $objWorksheet->getCell('K' . $i)->getValue(); // A열</p>

<p>               $lcell = $objWorksheet->getCell('L' . $i)->getValue(); // B열 

 

               $mcell = $objWorksheet->getCell('M' . $i)->getValue(); // C열 </p>

<p>               $ncell = $objWorksheet->getCell('N' . $i)->getValue(); // D열</p>

<p>               $ocell = $objWorksheet->getCell('O' . $i)->getValue();  // E열 

         

                $pcell = $objWorksheet->getCell('P' . $i)->getValue(); // A열</p>

<p>               $qcell = $objWorksheet->getCell('Q' . $i)->getValue(); // B열 

 

               $rcell = $objWorksheet->getCell('R' . $i)->getValue(); // C열 </p>

<p>               $scell = $objWorksheet->getCell('S' . $i)->getValue(); // D열</p>

<p>               $tcell = $objWorksheet->getCell('T' . $i)->getValue();  // E열 

         

                 $ucell = $objWorksheet->getCell('U' . $i)->getValue(); // A열</p>

<p>               $vcell = $objWorksheet->getCell('V' . $i)->getValue(); // B열 

 

               $wcell = $objWorksheet->getCell('W' . $i)->getValue(); // C열 </p>

<p>               $xcell = $objWorksheet->getCell('X' . $i)->getValue(); // D열</p>

<p>               $ycell = $objWorksheet->getCell('Y' . $i)->getValue();  // E열 

         

                $zcell = $objWorksheet->getCell('Z' . $i)->getValue(); // A열</p>

<p>               $aacell = $objWorksheet->getCell('AA' . $i)->getValue(); // B열 

 

               $abcell = $objWorksheet->getCell('AB' . $i)->getValue(); // C열 </p>

<p>               $accell = $objWorksheet->getCell('AC' . $i)->getValue(); // D열

                  if (empty($bcell)) {continue;}  // no value for bcat so go to the next row</p>

<p>               // 날짜 형태의 셀을 읽을때는 toFormattedString를 사용한다.

               //$h = PHPExcel_Style_NumberFormat::toFormattedString($h, 'YYYY-MM-DD');</p>

<p> </p>

<p>      //   echo $a . " / " . $b. " / " . $c . " / " . $d . " / " . $e . " / " . $f . " / " . $g . " 
\n";</p>

<p>    

              $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);</p>

<p>

 </p>

<p>          //$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);</p>

<p>

      }

   echo $maxRow . " Data inserting finished !";</p>

<p> </p>

<p>} catch (exception $e) {

    echo '엑셀파일을 읽는도중 오류가 발생하였습니다.!';</p>

<p>}</p>

<p>?></p>

<p> </p>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
e
6년 전

오류는 구체적으로 알려주시구요.

중간에 echo 하면서 찾아야 합니다.

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인