Google Spreadsheet API let’s you add rows to spreadsheets using the header names, this process is described here
The documentation however just gives an example of a simple case where the header text is made of of lowercase text (or text fitting the expression [a-z0-9]).
My application requires me to be able to set arbitrary header names for text (i.e. those that do not necessarily fit the expression above). Through much experimentation, I’ve figured out that special characters and symbols (apart from period) are generally not supported. To access a spreadsheet that uses header rows containing special characters, the header text with the special characters removed has to be used.
These transformations are not documented and I have found them mostly by trial and error.
For instance, to access a column with the header 'Foo Bar' via the API, the transformation of the header text to 'foobar' is required. Similarly, 'Foo.Bar' becomes 'foo.bar'.
Some special characters too have to be eliminated, however I keep getting corner cases in my code.
What transformations need to be made to the actual header text to access it via the API?
Also for this spreadsheet the transformation of the header text 'País' to 'país' doesn’t seem to work. I suspect it has something to do with the non-ASCII character 'í'
Any suggestions will be greatly appreciated.
You’ve got to remember when using ‘List feed’, it uses XML elements to delimit each value, taking the name of the field from Row 1 in the sheet. Thus, the limits on the name are those on XML element names. There is an article on XML.com about it here.
As to the exact algorithm they use to transform various header-cell values into valid XML element names, I’ve never seen Google specify this (even though people have asked for clarification before now). However, one might imagine it is something like:
Certainly, they do tend to omit spaces (for example) instead of converting them (as would be quite reasonable) to an underscore.
Now about characters outside of the ASCII set …
If your í is “LATIN SMALL LETTER I WITH ACUTE”, then it’s Unicode code-point is U+00ED, and it’s written in XML-land as í. As such, it’s a valid character for an XML name. From http://www.w3.org/TR/REC-xml/#NT-NameChar, it does seem to be a valid
NameStartCharIf they do have an algorithm like the above, then í ought to be ‘in’. However, I’d be paying close attention to encodings that you’re sending the Spreadsheet API, and which it is sending back to you. I wouldn’t put it past Google to have a bug in that respect.
You could of course do an experiment: put the values in the header row of a sheet using the Google Apps user-interface, and then doing a GET of the List feed, to see how the XML actually turns out. (But I expect you have been using this in your experiments so far).
Good luck.