寻求Google表格的帮助。
我们希望有一张表格,根据另一张表格中的数据输入创建摘要信息。
Let's say we have a list of people like this.
In another sheet within the same document, we could like output like this.
随着原始数据表的增长,我们可能会吸引更多人。输入会增长,看起来像这样:
Room ID First Name Last Name Full Name State Zip Room Leader
1 Brian Smith Brian Smith NY 10011
1 Lazy Fox Lazy Fox VA 22209 Yes
2 Lauren Appleby Lauren Appleby CA 94063 Yes
3 Aaron Johnson Aaron Johnson IL 60603 Yes
3 Adam Johnson Adam Johnson IL 60001
当发生这种情况时,我们希望输出改变以反映出来。它可能看起来像这样。
Room Number 1 State VA
Name Lazy Fox
Room Number 2 State CA
Name Lauren Appleby
Room Number 3 State IL
Name Aaron Johnson
对于随机剪切和粘贴,我想我没有足够的代表来添加所有内容。希望它能说明问题。
这是可能的吗?任何想法将不胜感激。谢谢!
答案 0 :(得分:0)
这是您作为无模式对话框的摘要。我使用您的标题作为摘要字段名称。我假设你想要在Room Leader专栏中有一个Yes的行。
function dispSummary()
{
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sht=ss.getSheetByName('RoomInfo');
var rng=sht.getDataRange();
var rngA=rng.getValues();
var s='<style>.ttl{color:blue;}</style>';
for(var i=1;i<rngA.length;i++)
{
if(rngA[i][6]=='Yes')
{
s+='<br />' + '<span class="ttl">' + rngA[0][0] + '</span>' + ' = ' + rngA[i][0] + ' ' + '<span class="ttl">' + rngA[0][4] + '</span>' + ' = ' + rngA[i][4] + ' ' + '<span class="ttl">' + rngA[0][3] + '</span>' + ' = ' + rngA[i][3];
}
}
var html=HtmlService.createHtmlOutput(s).setWidth(600).setHeight(500);
SpreadsheetApp.getUi().showModelessDialog(html, 'Values Found')
}
如果你希望他们排得更好,这里的表格也是一样的。
function dispSummary()
{
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sht=ss.getSheetByName('RoomInfo');
var rng=sht.getDataRange();
var rngA=rng.getValues();
var s='<style>.ttl{color:blue;}</style><table>';
for(var i=1;i<rngA.length;i++)
{
if(rngA[i][6]=='Yes')
{
s+='<tr><td>' + '<span class="ttl">' + rngA[0][0] + '</span>' + ' = ' + rngA[i][0] + '</td><td>' + '<span class="ttl">' + rngA[0][4] + '</span>' + ' = ' + rngA[i][4] + '</td><td>' + '<span class="ttl">' + rngA[0][3] + '</span>' + ' = ' + rngA[i][3] + '</td></tr>';
}
}
s+='</table>';
var html=HtmlService.createHtmlOutput(s).setWidth(600).setHeight(500);
SpreadsheetApp.getUi().showModelessDialog(html, 'Values Found')
}
或者您可能希望将摘要放在另一张表格中,这是一种方法。
function dispSummary()
{
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sht=ss.getSheetByName('RoomInfo');
var rng=sht.getDataRange();
var rngA=rng.getValues();
var sumsht = ss.getSheetByName('Summary')
var sumA = [];
for(var i=1;i<rngA.length;i++)
{
if(rngA[i][6]=='Yes')
{
sumA.push( [rngA[0][0],rngA[i][0],rngA[0][4],rngA[i][4],rngA[0][3],rngA[i][3]]);
}
}
var sumrng = sumsht.getRange(1,1,sumA.length,sumA[0].length);
sumrng.setValues(sumA);
}
这种方法将您想要的标题列放在顶行,并且只在输出表的其余部分中包含数据。
function dispSummary()
{
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sht=ss.getSheetByName('RoomInfo');
var rng=sht.getDataRange();
var rngA=rng.getValues();
var sumsht = ss.getSheetByName('Summary')
var sumA = [];
sumA.push( [rngA[0][0],rngA[0][4],rngA[0][3]]);
for(var i=1;i<rngA.length;i++)
{
if(rngA[i][6]=='Yes')
{
sumA.push( [rngA[i][0],rngA[i][4],rngA[i][3]]);
}
}
var sumrng = sumsht.getRange(1,1,sumA.length,sumA[0].length);
sumrng.setValues(sumA);
sumsht.activate();//you could add this if you want to go to the summary sheet immediately after the script completes.
}