简体   繁体   中英

How can I return data from more than one cell in Google Sheets Apps Script?

so I'm currently using Google Sheets for an expense tracker I am making.

Here is an example

At the moment, I am able to display expenses that are more than 100 through this function;

 function MORETHANONEHUNDRED(values) { let myArray= []; for(let i =0; i<values.length; i++) { let num = parseInt(values[i]); if(num>100) { myArray.push(num); } } return "Here is your array " + myArray; }

However, this only displays the number, whereas I'd also like the clothing brand to be displayed. How would I make both the expense, as well as the clothing brand corresponding it display to the user if the expense is more than 100?

Thanks!

If you are interested in displaying the current selected range of a spreadsheet in a dialog:

function dispssdata() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const rg = sh.getActiveRange();
  const vs = rg.getDisplayValues();
  let html = '<style>td{border:1px solid black;text-align:center;padding:1px 2px}</style><table>'
  vs.forEach((r,i) =>{
    html += '<tr>';
    r.forEach((c,j) => {
      html+= `<td>${c}</td>`
    });
    html += '</tr>'
  })
  html += '</table>'
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutput(html),'Display Active Range');
}

Active Range:

在此处输入图像描述

Dialog:

在此处输入图像描述

to answer my question, the following line of code will allow me to accomplish what I wanted: const MORETHANONEHUNDRED = v => v.filter(([a]) => a > 100); . Thank you to Tanaike for the assistance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM