183 responses to “Saving Form Data to Google Spreadsheets Using PHP and the Google Docs API”

  1. Abbas

    Thanks for all the help. I really appreciate it :)

  2. Matt

    Hey Dimas,

    Great helper class, I’m having all kinds of ideas for using this.

    One question:
    If we wanted to specify rows by more than one parameter, how is this done?

    i.e. let’s say I have a spreadsheet with the columns “campaign”, “action”, and “total”. My script gets the campaign value and the action value and I want to increment the total column for the row that matches BOTH campaign and action columns.
    So how do I specify, in the getRows and updateRows functions, that I only want the row that matches both?

  3. Danilo

    hello dimas,
    thx for api!
    but… i found a bug,
    your api only work when the worksheet name is the same of spreadsheet, ex:
    it works:
    $ss->useWorksheet(“Hillodb”);
    $ss->useSpreadsheet(“Hillodb”);

    it not works:
    $ss1->useWorksheet(“Hillodb”);
    $ss1->useSpreadsheet(“Aprovadas”);

    Error:
    Uncaught exception ‘Zend_Gdata_App_Exception’ with message ‘A spreadsheet key must be provided for list queries.’ in /home/content/22/3917722/html/dann/hillo/canvas/Zend/Gdata/Spreadsheets/ListQuery.php:264

    why?
    can u helpme?
    thx in advance.

  4. jusnit

    I want to find the worksheet Id from spreadsheet itself. Any Way in PHP?

    I want to retrieve last worksheet Id from a spreadsheet .

    I manually give worksheet Id’s as ‘od6′,’od7′,’od4′ , then column values can retrieved ,but after that I cant get anymore… because no worksheet id .

    How will I find worksheet id?

    Code:

    $spreadsheetKey = ” “;//key of spreadsheet
    $query = new Zend_Gdata_Spreadsheets_DocumentQuery();
    $query->setSpreadsheetKey($spreadsheetKey);
    $feed1 = $spreadsheetService->getWorksheetFeed($query);

    $worksheetId = ‘od6′;
    $query = new Zend_Gdata_Spreadsheets_ListQuery();
    $query->setSpreadsheetKey($spreadsheetKey);
    $query->setWorksheetId($worksheetId);
    $listFeed = $spreadsheetService->getListFeed($query);
    $customEntry = $listFeed->entries[1]->getCustomByName(‘stay’);
    $customEntry->getColumnName() . ” = ” . $customEntry->getText();

  5. Douglas Machado

    Greetings,

    Does anyone knows how to add columns?

    Thanks in advanced for your help.

  6. Usman

    heloo guru,

    I am taking data from google spread sheet and shown it to web page now i wana add quick search option for adding quick search i need html of spread sheet how can i get html of spread sheet or any other solution for adding quick search.

    thanx in advance

  7. Rob

    Dear Sir,

    You are awesome.

    That is all.

  8. sumesh

    I have a google form for collecting the customer visit details of each sales person. I wish to have separate spread sheet for each sales person upon selection of sales person name from the list ( google form) the data must go to the particular sheet. can any one tel me how to do this

  9. Metaksan

    I really liked the new version…

    btw, the heigh of each row might be seen high for you, if this happens just change from the options.

  10. Mei

    Hello Dimas, thanks for sharing this. I’ve got a question: how do we get all rows in a specific column?
    Thanks.

  11. Martin Grados Salinas

    Hola excelente el ejemplo, mira tengo un problema, en mi casa me funciona normal el ejemplo, pero en mi trabajo me sale error 500.

    No se a que se pueda deber .. pero en mi trabajo tengo proxy, no sé si tenga que ver eso.

    Espero alguna respuesta, gracias.

  12. Sumit Agrawal

    Does this need features like curl, fopen etc to be enabled on my hosting server or that is not required?

  13. Suresh V

    Hello Sir/Maam,

    I need some help in a problem I am having with spanish special characters. A brief summary of what I am doing first. I have written a PHP script which fetches data from Google Spreadsheet using Zend Google PHP API. This data is then put into MySql database.

    $row=$Col->getText(); //getText is the Google API that returns the value in the row.
    print “$row”; // I print the content

    But the problem is that some spanish characters such as ñer appear as ñer. Later on in the PHP code I go on to save these values in MySql. And even in the tables the same problem.Don’t know where the problem is.

    I tried various different things such as edit the PHP file and add:

    mbstring.language = Neutral ; Set default language to Neutral(UTF-8) (default)
    mbstring.internal_encoding = UTF-8 ; Set default internal encoding to UTF-8
    mbstring.encoding_translation = On ; HTTP input encoding translation is enabled
    mbstring.http_input = auto ; Set HTTP input character set dectection to auto
    mbstring.http_output = UTF-8 ; Set HTTP output encoding to UTF-8
    mbstring.detect_order = auto ; Set default character encoding detection order to auto
    mbstring.substitute_character = none ; Do not print invalid characters
    default_charset = UTF-8 ; Default character set for auto content type header
    mbstring.func_overload = 7 ; All non-multibyte-safe functions are overloaded with the mbstring alternatives

    Added in the below in MySql

    init_connect=’SET collation_connection = utf8_unicode_ci; SET NAMES utf8;’
    character-set-server=utf8
    collation-server=utf8_unicode_ci
    skip-character-set-client-handshake

    Changed Database and Table properties

    ALTER DATABASE db_name
    CHARACTER SET utf8
    DEFAULT CHARACTER SET utf8
    COLLATE utf8_general_ci
    DEFAULT COLLATE utf8_general_ci
    ;

    ALTER TABLE tbl_name
    DEFAULT CHARACTER SET utf8
    COLLATE utf8_general_ci
    ;

    Call SETNAMES etc just after mysql open connection.

    $q=”SET NAMES ‘utf8′”;
    $r=mysql_query($q);
    mysql_query(“SET CHARACTER SET utf8″);

    But nothing seems to work. Please help

  14. evlj

    I’m having a problem trying your solution, but i’m having a problem with zend gdata, would you be able to help me out please?

    Here’s the error:

    Fatal error: Uncaught exception ‘Zend_Gdata_App_HttpException’ with message ‘Expected response code 200, got 400 We're sorry, a server error occurred….

  15. Ahmed

    I was able to integrate your solution like a charm. Thanks a zillion.

    I have created a general purpose form that has a feature to save submitted data into Google Spreadsheet, that is available for sale on CodeCanyon.

    Let me know if you have any licensing issues with it?

  16. Ron

    I had a quick read through the posts here and noticed some were having the same issues as I did when I set it up.

    You have to have the extension openssl enabled in your php.ini file.

    You also have to have magic_quotes_gpc turned off.

    You also have to place the Zend folder in the root.

    And correct the path to the Zend Library, the numbers are for a later version now.

    Hope that helps.

  17. skumar

    I am trying to send data from phpmyadmin database to google spreadsheet. How can i send this data using zend framework.

    Can anyone help.

    thanks

  18. Saleem

    Thanks for this master piece of Google Spreadsheet code. It saved my hours of work.

  19. Dr. Uday Wad

    I would like to exchange data from my android code with google spreadsheet thro’ ofcourse java. Can any body suggest…

  20. pixeline

    I recently visited a script i produced using your class and now it does not work anymore. I cannot seem to login.
    Anyone having the same problem?

  21. Martin

    I am getting this error ‘Fatal error: Cannot redeclare class Zend_Loader in’ and have been advised to change a file in the application.ini file – could anybody explain howw to do this?

  22. Alfonso

    Is the library using any reference to Google Spreadsheets API v1 or v2? If it is the case, the code won’t work from October 20th (see https://developers.google.com/google-apps/spreadsheets/)

    Thanks for this amazing code, saved to me tons of hours!

  23. Hmm

    $service = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME;
    $http = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service);
    $this->client = new Zend_Gdata_Spreadsheets($http);

  24. Vincent Toms

    This is Really nice, is there any way to format the rows. Namely, I want to change the background color of the row.