我试图发布此代码,但每当我运行此代码时,我都会收到错误无法调用方法" getDataRange"为null。请帮我解决这个问题。这是我的代码 功能
doGet() {
var ss = SpreadsheetApp.openById('sheet id');
var sheet = ss.getSheetByName('sheet name');
var data = sheet.getDataRange();
var dateFilter= Charts.newCategoryFilter().setFilterColumnIndex(0).build();
var ageFilter = Charts.newNumberRangeFilter().setFilterColumnIndex(7).build();
var transportFilter = Charts.newCategoryFilter().setFilterColumnIndex(2).build();
var nameFilter = Charts.newStringFilter().setFilterColumnIndex(1).build();
var tableChart = Charts.newTableChart().setDimensions(700, 300)
.setDataViewDefinition(Charts.newDataViewDefinition().setColumns([0,1,2,3,4,5,6,7]))
.build();
var pieChart = Charts.newPieChart()
.setDataViewDefinition(Charts.newDataViewDefinition()
.setColumns([1,7])).build();
var dashboard = Charts.newDashboardPanel().setDataTable(data)
.bind([dateFilter,ageFilter, transportFilter, nameFilter], [tableChart, pieChart])
.build();
var app = UiApp.createApplication().setHeight(50);
var todaysdate = new Date();
app.add(app.createLabel(todaysdate));
app.add(app.createHTML('<h1 style="text-align:center;">DEMO</h1>'));
var filterPanel = app.createHorizontalPanel();
var chartPanel = app.createHorizontalPanel();
filterPanel.add(dateFilter).add(ageFilter).add(transportFilter).add(nameFilter).setSpacing(10);
chartPanel.add(tableChart).add(pieChart).setSpacing(50);
dashboard.add(app.createVerticalPanel().add(filterPanel).add(chartPanel));
app.add(dashboard);
var service = ScriptApp.getService();
service.enable(service.Restriction.ALL);
return app;
}
答案 0 :(得分:1)
错误表明sheet
为空。确保在var sheet = ss.getSheetByName('sheet name');
中使用正确的工作表名称。如果有不可见的字符,请复制并粘贴Google文档中的工作表名称。