Closed hdwebpros closed 8 years ago
+1! I have the same problem!
anybody found solution for this? Thanks
You need to retrieve a CellFeed first. Once you have that you create CellEntry's and add them to a BatchRequest. Finally upload the batch using the CellFeed class. e.g.
$serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($accessToken);
Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle("test");
$worksheet = $spreadsheet->getWorksheets()->getByTitle('Sheet1');
$cellFeed = $worksheet->getCellFeed();
$batchRequest = new Google\Spreadsheet\Batch\BatchRequest();
$batchRequest->addEntry($cellFeed->createInsertionCell(2, 1, "row 2 cell 1 content"));
$batchRequest->addEntry($cellFeed->createInsertionCell(3, 1, "row 3 cell 1 content"));
$batchRequest->addEntry($cellFeed->createInsertionCell(4, 1, "row 4 cell 1 content"));
$batchResponse = $cellFeed->insertBatch($batchRequest);
if($batchResponse->hasErrors()) {
//
}
@asimlqt I have tried your solution and it works to add cells in batch but after that if I try to add a new row using the code below.
$serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($accessToken);
Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle("test");
$worksheet = $spreadsheet->getWorksheets()->getByTitle('Sheet1');
$cellFeed = $worksheet->getCellFeed();
$batchRequest = new Google\Spreadsheet\Batch\BatchRequest();
$batchRequest->addEntry($cellFeed->createInsertionCell(1, 1, "Name"));
$batchRequest->addEntry($cellFeed->createInsertionCell(1, 2, "Number"));
$batchRequest->addEntry($cellFeed->createInsertionCell(1, 3, "Email"));
$batchResponse = $cellFeed->insertBatch($batchRequest);
if($batchResponse->hasErrors()) {
//
}
$listFeed = $worksheet->getListFeed();
$row = array(
"name" => "sagar",
"number" => "549679985904",
"email" => 'abc@abc.com'
);
$listFeed->insert($row);
It gives me 'Error in Google Request' error. Any idea why it's happening?
@sagark1510 I'm not sure why off the top of my head, the code seems ok to me.
I'll look into it and let you know what I find.
@sagark1510
Thanks for spotting this. It has now been fixed and tagged as 2.3.6
I need to add multiple (few hundreds) rows into google spreadsheet. Currently I'm doing it in a loop which is extremely slow, because rows are added one by one. How can I do a batch request using this?