Process only selected rows in scripts and add-ons
It is super easy in Google Sheets to select only specific rows, even if they are not adjacent. Simply hold down the CTRL / command key while making your selections:
This can be useful to copy selected rows in another sheet, delete a bunch of rows,…
And those selections are also available in Google Apps Script via the method
getActiveRangeList()😍. Thus, add-ons which perform a specific action on each row in a spreadsheet can target only those selected rows.
We have implemented this new feature in Mergo, our mail merge add-on and Publigo, our document merge add-on.
Until now, those add-ons would process all visible rows (they correctly detect which rows have been hidden or filtered out 🕵️) while making sure no duplicate email is sent (Mergo) and no duplicate PDF is generated (Publigo).
But often users want to perform a merge on a single or a few records only: to test with different examples / email addresses before going through the full list or because they are always using the same contact list and generate documents as needed:
I have medical consultations with patients and generate a letter for them after each visit. I use several letter templates for each patient over time (first visit, surgery, first follow up, second follow up etc.). The patient details are stored in a spreadsheet. If for example a patient comes for their first follow up visit, I would click on the patient’s details in my spreadsheet, open my “First follow up” template and use Publigo to print a pdf with all the relevant fields populated automatically.
This is now super easy with Mergo & Publigo. 👍
For Google Apps Script developers, here is a quick snippet showing how to process only selected rows.