I am inserting Data into a Google Worksheet using :
var row = new RowWork(null, null, {
column1: col1,
column2: col2,
});
this.GData.postEntry(row);
and
toAtom: function() {
return '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">'+
'<gsx:col1><![CDATA['+this.col1+']]></gsx:col1>'+
'<gsx:col2><![CDATA['+this.col2+']]></gsx:col2>'+
'</entry>';
}
postEntry: function(row)
{
var req = new XMLHttpRequest();
var atom = row.toAtom();
req.open('POST', row.editurl, false);
req.setRequestHeader('Authorization', 'GoogleLogin auth='+ClientLogin.token);
req.setRequestHeader('GData-Version', '3.0');
req.setRequestHeader('Content-Type', 'application/atom+xml; charset=utf-8');
req.setRequestHeader('Content-Length', atom.length);
req.setRequestHeader('Connection', 'close');
req.sendAsBinary(atom);
if(! req.responseText.match(/^<\?xml.+/)) {
throw new Error(req.responseText);
}
var parser = new DOMParser();
var DOM = parser.parseFromString(req.responseText, "text/xml");
row.editurl = DOM.getElementsByTagName('link')[1].getAttribute('href');
row.etag = DOM.getElementsByTagName('entry')[0].getAttribute('gd:etag');
return row;
},
But the data i am inserting sometimes have accented character, so once inserted let say for example : mécho
I get m cho
in the worksheet. And when using alert(col2)
before the insertion, i get the right mécho
.
what seems to be the problem?
Use the replace
function to convert the literal to its XML entity equivalent:
var atom = row.toAtom().replace(/é/g, "é");
References
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.