如何在 Google 脚本中转义“/”字符
How to escape "/" character in Google Script
我正在尝试将 Wordpress 数据导入 Google 表格。
下面的脚本几乎适用于所有专栏,但我无法发送电子邮件,如果我尝试转义“-”,我的脚本将不会 运行.
function getPage(offset,per_page) {
// gets posts in chunks of per_page
var ui = SpreadsheetApp.getUi(); // used for error messages
var ss = SpreadsheetApp.getActiveSpreadsheet();
var options = {
'method': 'get',
"contentType" : "application/json",
'muteHttpExceptions': true
}
var apiHost = 'https://domain.com.br/wp-json'; // set to your own domain
url = apiHost + '/acf/v3/cadastros?per_page='+per_page+'&offset='+offset;
try {
var response = UrlFetchApp.fetch(url, options);
var data = JSON.parse(response)
// loop through the map and output to sheet
for (i = 0; i < data.length; i++) {
row=offset+i+2; // set the row to make sure it is below header and takes into account the paging
ss.getRange('A'+row).setValue(data[i].id);
ss.getRange('B'+row).setValue(data[i].acf.contato);
ss.getRange('C'+row).setValue(data[i].acf.e-mail); //this line is breaking everything I've tried to use "\", put quotes but nothing seems to work
ss.getRange('D'+row).setValue(data[i].acf.telefone);
ss.getRange('E'+row).setValue(data[i].acf.cnpj);
ss.getRange('F'+row).setValue(data[i].acf.endereco);
ss.getRange('G'+row).setValue(data[i].acf.principais_produtos);
ss.getRange('H'+row).setValue(data[i].acf.volume_disponivel);
ss.getRange('I'+row).setValue(data[i].acf.estoque_disponivel);
ss.getRange('J'+row).setValue(data[i].acf.aceite);
}
return data.length;
} catch(error) {
var result = ui.alert( error.toString());
}
return 0;
}
我该如何解决这个问题?
将 data[i].acf.e-mail
替换为 data[i]['acf']['e-mail']
既简单又快捷
我正在尝试将 Wordpress 数据导入 Google 表格。 下面的脚本几乎适用于所有专栏,但我无法发送电子邮件,如果我尝试转义“-”,我的脚本将不会 运行.
function getPage(offset,per_page) {
// gets posts in chunks of per_page
var ui = SpreadsheetApp.getUi(); // used for error messages
var ss = SpreadsheetApp.getActiveSpreadsheet();
var options = {
'method': 'get',
"contentType" : "application/json",
'muteHttpExceptions': true
}
var apiHost = 'https://domain.com.br/wp-json'; // set to your own domain
url = apiHost + '/acf/v3/cadastros?per_page='+per_page+'&offset='+offset;
try {
var response = UrlFetchApp.fetch(url, options);
var data = JSON.parse(response)
// loop through the map and output to sheet
for (i = 0; i < data.length; i++) {
row=offset+i+2; // set the row to make sure it is below header and takes into account the paging
ss.getRange('A'+row).setValue(data[i].id);
ss.getRange('B'+row).setValue(data[i].acf.contato);
ss.getRange('C'+row).setValue(data[i].acf.e-mail); //this line is breaking everything I've tried to use "\", put quotes but nothing seems to work
ss.getRange('D'+row).setValue(data[i].acf.telefone);
ss.getRange('E'+row).setValue(data[i].acf.cnpj);
ss.getRange('F'+row).setValue(data[i].acf.endereco);
ss.getRange('G'+row).setValue(data[i].acf.principais_produtos);
ss.getRange('H'+row).setValue(data[i].acf.volume_disponivel);
ss.getRange('I'+row).setValue(data[i].acf.estoque_disponivel);
ss.getRange('J'+row).setValue(data[i].acf.aceite);
}
return data.length;
} catch(error) {
var result = ui.alert( error.toString());
}
return 0;
}
我该如何解决这个问题?
将 data[i].acf.e-mail
替换为 data[i]['acf']['e-mail']