Blank rows cannot be written; use delete instead - PHP

964 views Asked by At

I'm using Symfony 3.2 (PHP Framework) and Google API for Manage Google Spreadsheet using code.

I use google/apiclient, and asimlqt/php-google-spreadsheet-client library for manage Google Sheets.

As usually, I also created Application in console.developers.google.com.

Everything is working perfectly, but when I add new columns in Google Sheets after that this issue is raised.

I deleted the Application from console.developers.google.com and re-create it also I create new spreadsheet - but same issue again.

I'm following this Document which mentions the issue but not how to fix it.

2

There are 2 answers

0
Ketav On BEST ANSWER

Yoo, Answer found, I did silly mistake and nothing wrong with the code.

1) If you're using Google Spreadsheets and it suddenly stopped working, verify that you didn't accidentally insert a blank row anywhere. It interprets a blank row as the end of the spreadsheet.

2) Deleting existing rows or columns and Resorting the sheet

3) Make sure that Header name of sheet and Your Array Key (insert object) must be same.

4) Google Sheets documents does not support column names that begin with a numeral, contain spaces, or contain underscores.

After Deleting all the Rows and columns, I tried with same code and it is working.

1
bScutt On

Do any of your column names contain underscores?

I found that when adding data, the following:

$worksheet = $sheet->getWorksheetByTitle('Test');
$listFeed = $worksheet->getListFeed();
$cellFeed = $worksheet->getCellFeed();
$cellFeed->editCell(1,1, 'email_address');

foreach ($rows as $row) {
    $listFeed->insert([
        'email_address' => $row['email_address'],
    ]);
}

Did not work, however the following did work:

$worksheet = $sheet->getWorksheetByTitle('Test');
$listFeed = $worksheet->getListFeed();
$cellFeed = $worksheet->getCellFeed();
$cellFeed->editCell(1,1, 'email_address');

foreach ($rows as $row) {
    $listFeed->insert([
        'emailaddress' => $row['email_address'],
    ]);
}

Note the difference between the text of the array key - email_address and emailaddress.

It seems you must strip out underscores from the array keys when using the insert method on a list feed.