2014-01-14 3 views
2

저는 PHPExcel에 새로 입하했습니다.phpexcel을 사용하여 특정 셀 범위의 값 읽기

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

: 내가 뭘 원하는 아래의 엑셀 스프레드 시트 샘플 스프레드 시트 인에서 이미 몇 가지 필요한 초기화를 수행 한 excel spreadsheet example

을 읽을 수있는 부분을 보여주는 하이라이트 섹션, 일부 세포를 읽는 것입니다 어떤 제안이라도 도움이 될 것입니다.

+0

파일로드와 관련하여 무엇을 시도 했습니까? 어쨌든 전체 영역을 읽을 수있는 phpexcel comfort 함수가 있는지 확실하지 않습니다. 아마도 파일을 반복하고 각 셀의 값을 읽을 수 있습니다. 기본 아이디어입니다. – briosheje

답변

2

내가했습니다 작동하는 문제에 대한 해결 방법을 얻었습니다 ...

$objReader = new PHPExcel_Reader_Excel2007(); 
     $objReader->setReadDataOnly(true); 
     $objPHPExcel = $objReader->load($filename); // load filename into PHPExcel object 
     $objPHPExcel->setActiveSheetIndexByName('CA1'); 
     $objWorksheet = $objPHPExcel->getActiveSheet(); 

     $row_index = $objWorksheet->getHighestRow(); // e.g. 5 
     $col_name = $objWorksheet->getHighestColumn(); // e.g. B 
     $col_index = PHPExcel_Cell::columnIndexFromString($col_name); // e.g. 1 (which is equivalent to B) 


     for($row =4; $row <= $row_index; $row++){     
      for($col=1; $col<=$col_index; $col++){ 
       echo $objWorksheet->getCellByColumnAndRow($col, $row)->getValue().' '; 
      } 
      echo '<br>'; 
     } 
2

당신은 PHP 배열로 셀 범위의 콘텐츠를 전송하기 위해 워크 시트의 rangeToArray() 메소드를 사용할 수 있습니다 방법에

$myDataArray = $objPHPExcel->getActiveSheet()->rangeToArray('B4:N7', NULL, True, True); 

인수는 다음과 같습니다

* @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") 
* @param mixed $nullValue Value returned in the array entry if a cell doesn't exist 
* @param boolean $calculateFormulas Should formulas be calculated? 
* @param boolean $formatData Should formatting be applied to cell values? 
* @param boolean $returnCellRef False - Return a simple array of rows and columns 
*          indexed by number counting from zero 
*        True - Return rows and columns indexed by their 
*          actual row and column IDs 
+0

감사합니다.이 방법도 좋습니다. 나는이 게시물을보기 전에 해결 방법을 시도했다. 하지만 내 문제에 대한 열은 동적입니다. 즉 'N7'에서 끝나지 않을 수도 있습니다. – osagie

+0

열이 동적 인 경우 범위를 찾아서 'B4 : N7'과 같은 문자열을 만듭니다. –

+0

어쨌든이 작업을 수행 할 수 있습니까? * ** 파일을로드하지 않고 *? 내가 파일을로드 할 때 '허용 된 메모리 크기'문제가 나타납니다. – AleOtero93

관련 문제