matt
matt

Reputation: 700

PHP Zend_Gdata_Spreadsheets update multiple cells in a batch?

I'm using Zend_Gdata_Spreadsheets to interact with a Google Docs spreadsheet in PHP. I need to modify many cells in the spreadsheet, so I use the updateCell() method:

Example: $spreadsheetService->updateCell(1, 1, "hello", $spreadSheetKey, $worksheetId);

My code works fine for updating a cell. But I need to update many cells (usually 20 or 30 cells) and if I update them one by one (using the code above), it makes a separate api call for each cell update. This can take a LONG time to run if I have lots of cells to udpate.

Is there a way for me to update a batch of cells all at once so it's more efficient?

Upvotes: 2

Views: 672

Answers (1)

Roger
Roger

Reputation: 610

Just use the insertRow function to insert data row by row. Example code:

$key ="YOUR_SPREADSHEET_KEY"

$row = array(
"a" => "A column value",
"b" => "B column value",
"c" => "C column value",
"d" => "D column value"
);

$spreadSheetService->insertRow($row, $key);

Important: in this example you have to edit the first row of your target spreadsheet manually. You have to write "a" in the first column, "b" in the second, etc until you write "d" in the fourth column. Note these are the keys of the associative array we have to pass to insertRow method.

Upvotes: 1

Related Questions