【发布时间】:2017-02-21 20:48:17
【问题描述】:
我正在尝试根据下拉列表和辅助列显示数据。这是样本表:https://docs.google.com/spreadsheets/d/1LgHrze7bp0Epfw273Ylx3sVW98VDyd0sSQ1lYmZJUL4/edit?usp=sharing
我正在尝试让数据表信息显示在工作表的下拉菜单下。
任何帮助都会很棒!谢谢!
【问题讨论】:
标签: google-sheets
我正在尝试根据下拉列表和辅助列显示数据。这是样本表:https://docs.google.com/spreadsheets/d/1LgHrze7bp0Epfw273Ylx3sVW98VDyd0sSQ1lYmZJUL4/edit?usp=sharing
我正在尝试让数据表信息显示在工作表的下拉菜单下。
任何帮助都会很棒!谢谢!
【问题讨论】:
标签: google-sheets
像这样使用 hlookup。放入工作表B2:
=transpose(arrayformula(hlookup(B1,Data!B1:G8,{2,3,4,5,6,7,8},false)))
如果您将城市按行排列,则添加新城市会容易得多。您可以将下拉数据验证设置为 A2:A 并将查找设置为 A2:H。 然后,您可以在不进行任何调整的情况下添加城市。使用 vlookup 的公式如下:
=transpose(ARRAYFORMULA(vlookup(A1,RData!A2:H,{2,3,4,5,6,7,8},false)))
您也可以使用 Google Apps 脚本来执行此操作,该脚本将扩展到您拥有的城市和类别的数量。我已将此添加到脚本选项卡上的共享表中。它使用 RData 选项卡作为其源。
function onEdit(event) {
var sheet = event.source.getActiveSheet().getName()//get the sheet name
if(sheet=="Script" ){//if sheet name is Script
var ss= SpreadsheetApp.getActiveSpreadsheet()
var s=ss.getSheetByName("RData")//get the data sheet
var lr=s.getLastRow()//get the last row with data(city)
var lc=s.getLastColumn()//get the last column with data (category)
var rng=s.getRange(1, 1, lr, lc).getValues()//get the values
var dd= s.getRange("Script!A1").getValue()//get the selected city from the dropdown
var val=[]
var cat=[]
for(i=0;i<rng.length;i++){
if(dd==rng[i][0]){
for(j=1;j<rng.length+1;j++){
var t=rng[i][j]
val.push([rng[i][j]])
cat.push([rng[0][j]])
ss.getSheetByName("Script").getRange(1, 2, val.length,1).setValues(cat) //write the category values
ss.getSheetByName("Script").getRange(1, 3, val.length,1).setValues(val) //write the numbers
break //quit when the city is processed
}}}}}
附件是一个共享电子表格,其中显示了解决问题的所有方法:
https://docs.google.com/spreadsheets/d/1h3kYpBTK8OpSVL5PGwQzYsFbIHmCaKx0G5Y8FXSdHH8/edit?usp=sharing
【讨论】: