如何使用另一个表中的值实现下拉列表?共有3个表:报告;项目;任务。在报告中,您需要将项目和任务导入其中
答案 0 :(得分:1)
以下是使用其他工作表创建下拉列表的方法。
function validate() {
var ss1=SpreadsheetApp.getActiveSpreadsheet();
var sht1=ss1.getSheetByName('Val1');
var ss2=SpreadsheetApp.openById('SpreadSheetID');
var sht2=ss2.getSheetByName('Dat1');
var rng1=sht1.getRange('A2:A');
var rng2=sht2.getRange('A2:A7');
var rule = SpreadsheetApp.newDataValidation().requireValueInRange(rng2).build();
rng1.setDataValidation(rule);
}
这是Dat1中最终下拉的图像:
这是Val1中其他工作表数据的图像:
答案 1 :(得分:0)
function getProjects() {
var projectSheet = SpreadsheetApp.openById('id');
var projectsList = projectSheet.getSheets()[0];
var range = projectsList.getRange('A2:A400').getValues();
Logger.log(range);
var reportSheet = SpreadsheetApp.getActiveSpreadsheet();
var currentSheet = reportSheet.getActiveSheet();
var cell = currentSheet.getActiveCell();
var projects = [];
for (var i = 0; i < range.length; i++) {
if (range[i] != ''){
projects.push(range[i]);
Logger.log(projects[i]);
} else {
break;
}
}
var rule = SpreadsheetApp.newDataValidation().requireValueInList(projects);
cell.setDataValidation(rule);
}