Google表格中的动态

Google表格中的动态

本文介绍了Google表格中的动态/依赖下拉菜单是如何做的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据在Google表单中的主类别下拉列表中选择的值填充下拉菜单中的子类别列?



并找不到任何好的解决方案,因此我想分享我自己的。请参阅下面的答案。

如下所示。



您可以通过正常的Data> Validations菜单提示设置第一列下拉菜单。



主页





下拉来源页面





之后,您需要设置一个脚本,其名称 onEdit 。 (如果你不使用这个名字,getActiveRange()将不会做任何事情,但会返回单元格A1)

并使用这里提供的代码:

  function onEdit(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var myRange = SpreadsheetApp.getActiveRange();
var dvSheet = SpreadsheetApp.getActiveSpreadsheet()。getSheetByName(Categories);
var option = new Array();
var startCol = 0; $()
$ b if(sheet.getName()==Front Page&&& myRange.getColumn()== 1&&& myRange.getRow()> 1){
if(myRange.getValue()==Category 1){
startCol = 1;
} else if(myRange.getValue()==Category 2){
startCol = 2;
} else if(myRange.getValue()==Category 3){
startCol = 3;
} else if(myRange.getValue()==Category 4){
startCol = 4;
} else {
startCol = 10
}

if(startCol> 0&& startCol< 10){
option = dvSheet .getSheetValues(3,startCol,10,1);
var dv = SpreadsheetApp.newDataValidation();
dv.setAllowInvalid(false);
//dv.setHelpText(\"Some help text here);
dv.requireValueInList(option,true);
sheet.getRange(myRange.getRow(),myRange.getColumn()+ 1).setDataValidation(dv.build());


if(startCol == 10){
sheet.getRange(myRange.getRow(),myRange.getColumn()+ 1).clearDataValidations();
}
}
}

之后,设置一个通过编辑>当前项目触发器在脚本编辑器屏幕中触发。这将弹出一个窗口让你选择各种下拉菜单,最终以此结束:



你应该很好的追求!


How do you get a sub-category column to populate a drop down based on the value selected in the main category drop down in google sheets?

I googled around and couldn't find any good solutions, therefore I wanted to share my own. Please see my answer below.

解决方案

You can start with a google sheet set up with a main page and drop down source page like shown below.

You can set up the first column drop down through the normal Data > Validations menu prompts.

Main Page

Drop Down Source Page

After that, you need to set up a script with the name onEdit. (If you don't use that name, the getActiveRange() will do nothing but return cell A1)

And use the code provided here:

function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  var myRange = SpreadsheetApp.getActiveRange();
  var dvSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Categories");
  var option = new Array();
  var startCol = 0;

  if(sheet.getName() == "Front Page" && myRange.getColumn() == 1 && myRange.getRow() > 1){
    if(myRange.getValue() == "Category 1"){
      startCol = 1;
    } else if(myRange.getValue() == "Category 2"){
      startCol = 2;
    } else if(myRange.getValue() == "Category 3"){
      startCol = 3;
    } else if(myRange.getValue() == "Category 4"){
      startCol = 4;
    } else {
      startCol = 10
    }

  if(startCol > 0 && startCol < 10){
    option = dvSheet.getSheetValues(3,startCol,10,1);
    var dv = SpreadsheetApp.newDataValidation();
    dv.setAllowInvalid(false);
    //dv.setHelpText("Some help text here");
    dv.requireValueInList(option, true);
    sheet.getRange(myRange.getRow(),myRange.getColumn() + 1).setDataValidation(dv.build());
   }

  if(startCol == 10){
    sheet.getRange(myRange.getRow(),myRange.getColumn() + 1).clearDataValidations();
  }
  }
}

After that, set up a trigger in the script editor screen by going to Edit > Current Project Triggers. This will bring up a window to have you select various drop downs to eventually end up at this:

You should be good to go after that!

这篇关于Google表格中的动态/依赖下拉菜单是如何做的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 04:42