TypeError:无法在Google工作表脚本中读取null(第6行,文件“代码")的属性"getRange" [英] TypeError: Cannot read property 'getRange' of null (line 6, file "Code") in google sheet script
本文介绍了TypeError:无法在Google工作表脚本中读取null(第6行,文件“代码")的属性"getRange"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从网页中读取数据,为此我使用了Importdata函数.为自动刷新写了一个脚本.下面是代码.我收到类似的错误 TypeError:无法读取null的属性"getRange"(第16行,文件代码")如何摆脱这个错误.
I wanted to read data from the webpage for this I have used the Importdata function. For auto-refresh wrote a script. Below is the code. I am getting error like TypeError: Cannot read property 'getRange' of null (line 16, file "Code") How to get rid of this error.
function getData() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("2020 MTD");
var queryString = Math.random();
var cellFuntion = '=IMPORTDATA("https://dosairnowdata.org/dos/historical/NewDelhi/2020/NewDelhi_PM2.5_2020_05_MTD.csv")';
sheet.getRange('A1').setValue(cellFuntion);
}
推荐答案
下面是工作代码.
function importCSVFromWeb() {
// Provide the full URL of the CSV file.
var csvUrl = "https://dosairnowdata.org/dos/historical/NewDelhi/2020/NewDelhi_PM2.5_2020_05_MTD.csv";
var csvContent = UrlFetchApp.fetch(csvUrl).getContentText();
var csvData = Utilities.parseCsv(csvContent);
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(1, 1, csvData.length, csvData[0].length).setValues(csvData);
}
这篇关于TypeError:无法在Google工作表脚本中读取null(第6行,文件“代码")的属性"getRange"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文