2014-06-13 4 views
0

PHP/Zend 스크립트를 통해 Google 스프레드 시트에서 모든 행을 가져 오려고합니다. 이것은 내가 사용하고있는 스크립트입니다PHP/Zend/Google 스프레드 시트가 모든 행을 가져 오지 않습니다.

$service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME; 
    $client = Zend_Gdata_ClientLogin::getHttpClient('xxxxxxxxx', 'xxxxxxx', $service); 
    $spreadsheetService = new Zend_Gdata_Spreadsheets($client); 

    // Get spreadsheet key 
    $spreadsheetsKey = 'xxxxxxxxxxxxx'; 
    $worksheetId = 'xxx'; 

    // Get cell feed 
    $query = new Zend_Gdata_Spreadsheets_CellQuery(); 
    $query->setSpreadsheetKey($spreadsheetsKey); 
    $query->setWorksheetId($worksheetId); 
    $cellFeed = $spreadsheetService->getCellFeed($query); 

    // Build an array of entries: 
    $ssRows = array(); 
    $ssRow = array(); 
    $titleRow = array(); 

    $tableRow = 1; 
    foreach($cellFeed as $cellEntry) { 
     $row = $cellEntry->cell->getRow(); 
     $col = $cellEntry->cell->getColumn(); 
     $val = $cellEntry->cell->getText(); 
     // Add each row as a new array: 
     if ($row != $tableRow) { 
      array_push($ssRows, $ssRow); 
      $ssRow = array(); 
      // Move to the next row/new array 
      $tableRow = $row; 
     } 
     // Build the array of titles: 
     if ($row == 1) { 
      $titleRow[$col] = $val; 
     } 
     // Build the array of results with the title as the key: 
     else { 
      $key = $titleRow[$col]; 
      $ssRow[$key] = $val;     
     } 
    } 

    // Pass the results array: 
    return array_reverse($ssRows); 

이, 스프레드 시트에서 세부 사항의 대부분 나에게 배열을 구축하지만 항상 마지막 항목을 그리워 - 사람이 내가 잘못 뭐하는 거지 볼 수 있으며,이 스프레드 시트에서 모든 데이터를 가져 오는 더 좋은 방법은 무엇입니까?

양식은 다른 답변을 기준으로 3 부분 형식입니다. 한 부분을 채울 때 양식의 두 번째 부분을 더 빨리 채울 수 있도록 첫 번째 양식의 일부 세부 사항을 미리 입력하여 양식에 URL을 표시하고 싶습니다. 이것은 모두 괜찮습니다, 그것은 중요한 문제가 단순히 누락 된 마지막 항목입니다!

감사합니다.

답변

1

코드는 다음과 같이 작동합니다 : 당신이 다음 행으로 이동하면

if (next_row) { 
    data[] = current_row 
    current_row = array(); 
} 
if (first_row) { 
    title_row logic 
} else { 
    add cell to current_row 
} 

그래서 당신은 당신의 집에 행을 추가합니다. 마지막 전환이 그리워지기 때문에 마지막 행이 누락됩니다.

foreach 루프 다음에 바로 array_push($ssRows, $ssRow);을 추가하면됩니다. 0 행의 수표를 추가해야합니다.이 경우 건너 뜁니다.


더 적절한 수정은 행 단위로 반복 한 다음 셀 단위가 아니라 셀 단위로 반복하는 것입니다.

+0

D' oh는 명백한 대답처럼 보인다, Forrest를 위해 나무를 볼 수 없었다! 목록 피드를 얻으려고했지만 응답이 없으므로 문서가 매우 얇습니다! 문서의 예제 다음에 아무것도 반환하지 않습니다! 리스트 피드가 질의를 받아 들일 때 고통 스러울 수 있습니다. 즉, 모든 것을 얻지 않고 얻은 결과의 나이를 선택할 수 있습니다! – Scoobler

관련 문제