Insert newline into a spreadsheet cell via python api

497 views
Skip to first unread message

Justin Onstine

unread,
Nov 2, 2011, 7:44:04 PM11/2/11
to google-docum...@googlegroups.com
Hi. I am trying to write a string with one or more carriage returns (newline, linefeed, \n, whatever) into a spreadsheet using the python UpdateCell() function and in the spreadsheet it is being rendered as a space. I've done some fairly extensive searching around the web and tried simply using a '\n' or a '\r' or both in my string to no avail. Is there a way to do this programatically?

Thank you,
Justin

Vic Fryzel

unread,
Nov 3, 2011, 12:01:09 AM11/3/11
to google-docum...@googlegroups.com
Hey Justin,

Try the 
 XML entity instead of a \r\n.  Here's some example XML that I just tested that works:

<entry  xmlns="http://www.w3.org/2005/Atom" xmlns:gs="http://schemas.google.com/spreadsheets/2006" xmlns:batch="http://schemas.google.com/gdata/batch" xmlns:gd="http://schemas.google.com/g/2005" gd:etag="&quot;YGgDTlERSyt7Ig..&quot;">
<gs:cell row="1" col="1" inputValue="asdf&#10;
asdf&#10;
asdf"></gs:cell>
</entry>

Thanks,
-Vic

Justin Onstine

unread,
Nov 3, 2011, 8:45:18 PM11/3/11
to google-docum...@googlegroups.com
I'm sorry, I'm not very good at the xml thing and wouldn't know how to make that kind of call from within python. Maybe this is more a case of a not so bright programmer. :/

Using &#10; in my UpdateCell call just causes the string literal to be put in the cell.

Thanks for your help,
Justin

Justin Onstine

unread,
Nov 3, 2011, 8:47:36 PM11/3/11
to google-docum...@googlegroups.com

Vic Fryzel

unread,
Dec 20, 2011, 4:49:30 PM12/20/11
to google-docum...@googlegroups.com
Oh, sorry, it's because &#10; is being replaced by &amp;&#10;.  I'm actually not quite sure how to resolve this in the current gdata-python-client without a lot of tricks...  Let me ask some colleagues and get back to you.

-Vic

Vic Fryzel

unread,
Dec 21, 2011, 5:21:42 PM12/21/11
to google-docum...@googlegroups.com
After a bunch of discussion, we've decided not to fix this in gdata-python-client because of the ramifications it would have for numerous existing clients.

We will fix this problem in a future version of the API.  I'm really sorry about this :(

-Vic

Justin Onstine

unread,
Dec 21, 2011, 5:27:09 PM12/21/11
to google-docum...@googlegroups.com, vicf...@google.com
I totally understand, thanks for giving it your attention!

Vic Fryzel

unread,
Dec 21, 2011, 5:29:22 PM12/21/11
to Justin Onstine, google-docum...@googlegroups.com
Thank you very much for understanding!

-Vic
Reply all
Reply to author
Forward
0 new messages