Posting multiple lines to a Google Docs Spreadsheet via the API

I’ve been writing a perl cgi script to populate a Google spreadsheet, using LWP, the spreadsheet list-based feeds, and the model outlined in the Google article “Using cURL to interact with Google Data Services“.

Everything was working fine until I had an html form with some multiline textarea input fields.  I wanted multiple lines of user input to go into a single cell in the Google spreadsheet.  When you’re manually entering data into a Google spreadsheet, you just use ctrl-enter to move to the next line inside a cell.

Some documentation said to put a linefeed (ascii 10, or “\n” in perl) between the lines, and it really is that simple.  Where I got hung up was in thinking that I already had a linefeed in the form field.  It turns out that I had carriage return + linefeed, which the Google spreadsheet API doesn’t like.  All you have to do is strip out the carriage return (“\r” in perl) and it will work fine.

I might not have had this problem with browsers running on Mac or linux, but I’m primarily dealing with browsers on Windows.

2 thoughts on “Posting multiple lines to a Google Docs Spreadsheet via the API

  1. karl.kranich Post author

    Good point. We’re using a web form to collect information about concerts. We wanted several fields (like “quotes from hosts”) to allow for several lines of input, but we want all of those lines to go into a single Google spreadsheet cell.

    It would have been easy with a Google Form, but we also wanted more styling options for the form, and possibly other submit actions in addition to populating the Google Doc. So, we needed a custom form processor that can also handle appending data to a Google Doc.

Leave a Reply

Your email address will not be published. Required fields are marked *