如何在Google表格中搜索具有特定单词的多个单词并返回结果的单元格?

时间:2022-04-06 20:07:42

Here's what I'm trying to accomplish:

这是我想要完成的事情:

  1. A project manager fills out a Google Form. It spits the result to a spreadsheet, and I want to manipulate that data.
  2. 项目经理填写Google表格。它将结果吐出到电子表格中,我想操纵该数据。

  3. The first question/cell is what social media the product is using, with a multiple choice checkbox.
  4. 第一个问题/单元格是产品使用的社交媒体,带有多选复选框。

  5. If someone checks off Facebook and Twitter, the cell returns "Facebook, Twitter" and I'm having trouble searching the cell for "Twitter" since it's not first.
  6. 如果有人检查Facebook和Twitter,该单元格会返回“Facebook,Twitter”,而我在搜索单元格时遇到“Twitter”,因为它不是第一个。

Here's what I have so far:

这是我到目前为止所拥有的:

function testplan() {

var mainsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var testplan = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TestPlan");

var socialData = mainsheet.getRange(3, 3).getValues();
var socialDataText = socialData.length;
var fbSocial = "Facebook";
var twitSocial = "Twitter";

for (var i = 0; i < socialDataText; i++) {
if (socialData[i][0] == fbSocial) {
  testplan.getRange("A15").setValue("User can log into the app with Facebook.");
  testplan.getRange("A16").setValue("User can share content from the app with Facebook.");
} {
  return 0;
};
};

for (var i = 0; i < socialDataText; i++) {
if (socialData[i][0] == twitSocial) {;
  testplan.getRange("A17").setValue("User can log into the app with Twitter.");
  testplan.getRange("A18").setValue("User can share content from the app with Twitter.");
                     } {
     return 0;
};
};

The first command to look for "Facebook" works, because it's the first bit of text. But anything after it isn't able to be found. I've searched a lot and have found things that are close, but nothing that works the way I'm expecting it to. It's probably a command or something really obvious that I'm not seeing.

寻找“Facebook”的第一个命令有效,因为它是第一个文本。但是之后的任何事情都无法找到。我经常搜索并发现了很接近的东西,但是没有任何东西能像我期待的那样发挥作用。这可能是一个命令,或者我没有看到的非常明显的事情。

1 个解决方案

#1


try

function testplan() {

    var mainsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
    var testplan = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TestPlan");

    var socialData = mainsheet.getRange(3, 3).getValues();
    var socialDataText = socialData.length;
    var fbSocial = "Facebook";
    var twitSocial = "Twitter";

    for (var i = 0; i < socialDataText; i++) {
        if (socialData[i][0].indexOf(fbSocial) > -1) {
          testplan.getRange("A15").setValue("User can log into the app with Facebook.");
          testplan.getRange("A16").setValue("User can share content from the app with Facebook.");
        };
        if (socialData[i][0].indexOf(twitSocial) > -1) {;
          testplan.getRange("A17").setValue("User can log into the app with Twitter.");
          testplan.getRange("A18").setValue("User can share content from the app with Twitter.");            
        };
    };
};

for simplicity

#1


try

function testplan() {

    var mainsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
    var testplan = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TestPlan");

    var socialData = mainsheet.getRange(3, 3).getValues();
    var socialDataText = socialData.length;
    var fbSocial = "Facebook";
    var twitSocial = "Twitter";

    for (var i = 0; i < socialDataText; i++) {
        if (socialData[i][0].indexOf(fbSocial) > -1) {
          testplan.getRange("A15").setValue("User can log into the app with Facebook.");
          testplan.getRange("A16").setValue("User can share content from the app with Facebook.");
        };
        if (socialData[i][0].indexOf(twitSocial) > -1) {;
          testplan.getRange("A17").setValue("User can log into the app with Twitter.");
          testplan.getRange("A18").setValue("User can share content from the app with Twitter.");            
        };
    };
};

for simplicity