本文介绍了在Google表格中导入JSON格式的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在成员/朋友@Tanaike的帮助下,我们能够开发代码以从JSON列表中导入数据,但价格"中的数据会被删除.字段按如下方式导入'16 .4700000000',而我只想导入'之后的前两位数字.的"16.47".
with the help of member / friend @Tanaike we were able to develop a code to import the data from a JSON list, but the data in the "price" field is imported as follows '16 .4700000000 'and I would like to import only the first 2 digits after the' . ' getting "16.47".
您能帮我完成这项任务吗?
could you help me on this mission?
这是我正在使用的当前代码:
this is the current code I am using:
// Call the Bling API var response = UrlFetchApp.fetch("bling.br/Api/v2/produtos/json&apikey=APIKEY?imagem=S&estoque=S"); //Logger.log(response.getContentText()); // Parse the JSON reply var json = response.getContentText(); var data = JSON.parse(json); // Aquisição de dados. var values = data.retorno.produtos.map(({produto: {codigo, gtin, descricao, preco, situacao}}) => [codigo, gtin, descricao, preco, situacao]); var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("produtos"); sheet.getRange(/*sheet.getLastRow() + */ 2, 1, values.length, values[0].length).setValues(values); ``` 推荐答案这是我其中一个项目的代码段,我在其中设置了数字格式以及边框和背景.
Here is a snippet from one of my projects where I set the number format as well as borders and background.
sheet.getRange(summaryAnnRetsFirstRow, 1, summaryAnnRetsLen, 4).setValues(summaryAnnRets); sheet.getRange(summaryAnnRetsFirstRow,2, summaryAnnRetsLen, 2).setNumberFormat("$#,##0;$(#,##0)"); sheet.getRange(summaryAnnRetsFirstRow,4, summaryAnnRetsLen, 1).setNumberFormat("0.00%"); sheet.getRange(summaryAnnRetsFirstRow,1, summaryAnnRetsLen, sheet.getLastColumn()).setBorder(true, true, true, true, true, true, 'black', SpreadsheetApp.BorderStyle.SOLID_LIGHT); sheet.getRange(summaryAnnRetsFirstRow,1, summaryAnnRetsLen, sheet.getLastColumn()).setBackground("#bdd4f9");更多推荐
在Google表格中导入JSON格式的数据
发布评论