How to remove spam automatically and archive email addresses in sheet

function onOpen() {
ScriptApp.newTrigger(' DelSpam')

function DelSpam() {
var base = SpreadsheetApp.getActiveSpreadsheet();
var sheet = base.getSheets()[2];
var last = sheet.getLastRow();
var range = sheet.getRange("G1:G" + last+10);
var col1 = 1;
for (var x=2; x<last; x++) {
if ( range.getCell(x, 1).getValue() != "" ) {
col1 +=1;
var search = "label:spam";
var compt= 0;
var threads =, 0, 10);
for (var i=0; i<threads.length; i++) {
var messages = GmailApp.getMessagesForThread(threads[i]);
for (var j=0; j<messages.length; j++) {
var email = messages[j];
var de = email.getFrom();
range.getCell(col1, 1).setValue(de);
var nus = range.getCell(2, 1).getValue();
range.getCell(2, 1).setValue(nus+1);

Post has shared content
Multiple FILE maker - Learn how to quickly make multiple copies of files on Drive with Apps Script
Multiple FILE maker - Learn how to quickly make multiple copies of files on Google Drive with Apps Script
This includes:
*Checking for user mistakes
*Match & regular expressions - to extract the file ID from the file URL
*DriveApp class

I want to do some like this:
I need to automatically copy the values ​​of a spreadsheet that is filled from one form to another spreadsheet each time a record is entered from the form. The final data should be only values. can somebody teach me please? is some like IMPORTRANGE but with PASTE VALUES ONLY

Say I have the following spreadsheet:

code dataElem age sex place type value denom denom_code
a1 population all all all num 10 1 1
a2 population all all rural num 6 1 1
a3 population all all urban num 4 1 1
a4 wealthy all all all % 40 10 a1
a5 wealthy all all all % 34 6 a2
a6 wealthy all all all % 50 4 a3
a7 Educated all all all % 70 10 a1
a8 Educated all all all % 50 6 a2
a9 Educated all all all % 100 4 a3
with values as given above, and where where cell A1-A3 and cell G1-G3 are primary keys. I want to enforce that subsequent fields use the primary keys defined above as foreign keys. That is new records entered must be checked against the foreign key cells, which are denom (col-H) and denom_code (col-I). How do I achieve this in excel vba. Someone help please..

I have a script that moves a row to another sheet based on a text in a column.
This works fine when i type it.
Now i have put a array formula is that column, that also works fine, except that the script doesnt function no more.
I know it has to do with the values within the script but i dont know enough to change them to howe it's suppose to be.
I hope someone can help me out

function onEdit(e) {
var ss = SpreadsheetApp.openById(" ");
var sourceSheet = ss.getSheetByName(' ');
var targetSpreadsheet = SpreadsheetApp.openById(" ");
var targetSheet = targetSpreadsheet.getSheetByName(' ');
var r = e.range;
var actionCol = 32;
var col = r.getColumnIndex();
var row = r.getRowIndex();
var lastColumn = sourceSheet.getLastColumn();

if (e.value == "done" && col == actionCol) {
var dataRange = sourceSheet.getRange(row,1,1,lastColumn);
var dataValues = dataRange.getValues();
var lastRow = targetSheet.getLastRow();
targetSheet.getRange(lastRow+1, 1).offset(0, 0, 1, lastColumn).setValues(dataValues);

I have a shared sheet where people might set a filter and I have a script that runs with an onsubmit trigger which will not work if the filter is set (actually it might mess up all the data) how can I make sure the script can run smoothly?
Is there a way to avoid someone sets a filter of remove it with google script? 

I'm trying to write a script for Google Sheets that, when called by the user (not me as the spreadsheet owner), converts the user from an editor to a viewer.

Although the documentation for removeEditor() seems to say that the current user can't be removed from the list of editors, that part actually works fine. That is, when I'm logged in as (user, but not owner) and I call removeEditor(, I'm instantly removed and can no longer access the spreadsheet.

However, I'm also removed as a viewer. I've tested this using the spreadsheet owner account. Here's the script:

function testScript() {
var ss = SpreadsheetApp.openById("XXXXXXX");
var sheet1 = SpreadsheetApp.setActiveSheet(ss.getSheets()[0]);
var currentGuy;

//convert "" from editor to viewer
currentGuy = ""
So there are several unexpected behaviors here:

When I output the list of editors and viewers before running the script, shows up in both lists, even though I've initiated him as an editor (using the regular permissions interface, not a script). I understand that editors can view the spreadsheet, but this should be part of their abilities as an editor. They shouldn't need to be part of the viewer list, which should be only for people with view-only permissions.
When I remove from the list of editors, he's removed from the list of viewers as well. This is true even if I explicitly add him to the list of viewers before removing him from the list of editors, as the script above does.

Obviously I can't call addViewer() after calling removeEditor(), since this will fail when the script is called by the user. Once he's removed as an editor, he no longer has permission to edit the viewers list.

Two questions:
1. Why does removeEditor remove the user from the viewers list?
2. Is there a work-around?

I have some code that brings up a user box to download a PDF created from the active sheet I am using. I am trying to have it name the PDF with content found in A1. I can't seem to get it to do that. Any advice? Here is the code I have so far:

function finalizePO() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getRange("A1:J");

var range2 = sheet.getRange("a1");
var name = range2.getValue();
var gid = sheet.getSheetId();
var pdfOpts = '&size=0&fzr=false&portrait=true&fitw=true&gridlines=false&printtitle=false&sheetnames=false&pagenum=UNDEFINED&attachment=true&gid='+gid;
var row2 = sheet.getMaxRows();
var url = ss.getUrl().replace(/edit$/, '') + 'export?format=pdf' + pdfOpts;

var app = UiApp.createApplication().setWidth(200).setHeight(80);
app.setTitle('PDF Created');

var link = app.createAnchor('Download PDF', url).setTarget('_self');

Has anyone tried this? I'm trying to use JavaScript to add to a Google slide, like I do with docs. This is what I have. No error, but also no result. The fine is copied fine, but the text is not replaced.

var presentation = DriveApp.getFileById('')
.makeCopy("Presentation", folder);
var reqs = [
{'replaceAllText': {
'presentationId': presentationID,
'containsText': {'text': '{{COURSE}}'},
'replaceText': 'Hello World!'

Post has shared content
Something new to look out for if you are working with Sheets...
Wait while more posts are being loaded