PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Interacting With Cell-based Feeds

In a cell-based feed, each entry represents a single cell.

Note that we don't recommend interacting with both a cell-based feed and a list-based feed for the same worksheet at the same time.

Get a Cell-based Feed

To retrieve a worksheet's cell feed, use the getCellFeed() method of the Spreadsheets service.

<?php
$query 
= new Zend_Gdata_Spreadsheets_CellQuery();
$query->setSpreadsheetKey($spreadsheetKey);
$query->setWorksheetId($worksheetId);
$cellFeed $spreadsheetService->getCellFeed($query);

The resulting Zend_Gdata_Spreadsheets_CellFeed object $cellFeed represents a response from the server. Among other things, this feed contains an array of Zend_Gdata_Spreadsheets_CellEntry objects ($cellFeed>entries), each of which represents a single cell in a worksheet. You can display this information:

<?php
foreach($cellFeed as $cellEntry) {
  
$row $cellEntry->cell->getRow();
  
$col $cellEntry->cell->getColumn();
  
$val $cellEntry->cell->getText();
  echo 
"$row$col = $val\n";
}

Send a Cell Range Query

Suppose you wanted to retrieve the cells in the first column of a worksheet. You can request a cell feed containing only this column as follows:

<?php
$query 
= new Zend_Gdata_Spreadsheets_CellQuery();
$query->setMinCol(1);
$query->setMaxCol(1);
$query->setMinRow(2);
$feed $spreadsheetService->getCellsFeed($query);

This requests all the data in column 1, starting with row 2.

Change Contents of a Cell

To modify the contents of a cell, call updateCell() with the row, column, and new value of the cell.

<?php
$updatedCell 
$spreadsheetService->updateCell($row,
                                               
$col,
                                               
$inputValue,
                                               
$spreadsheetKey,
                                               
$worksheetId);

The new data is placed in the specified cell in the worksheet. If the specified cell contains data already, it will be overwritten. Note: Use updateCell() to change the data in a cell, even if the cell is empty.

Zend Framework