Sheets macro script edit for filter reset - google-sheets-api

I use buttons to reset and set all the filters. Now I need to manually set one of the filters on the same row (N14), and I don't want the scrips to change it or reset it. How can it be done?
function RESET() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('A1').activate();
spreadsheet.getActiveSheet().getFilter().remove();
spreadsheet.getRange('B14:O14').activate();
var currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
currentCell = spreadsheet.getCurrentCell();
spreadsheet.getSelection().getNextDataRange(SpreadsheetApp.Direction.DOWN).activate();
currentCell.activateAsCurrentCell();
spreadsheet.getRange('B14:O926').createFilter();
spreadsheet.getRange('H15:O100').activate();
};
function RULEX() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('D14').activate();
var criteria = SpreadsheetApp.newFilterCriteria()
.whenTextEqualTo('Rule')
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(4, criteria);
spreadsheet.getRange('E14').activate();
criteria = SpreadsheetApp.newFilterCriteria()
.whenTextEqualTo('No')
.build();
spreadsheet.getActiveSheet().getFilter().setColumnFilterCriteria(5, criteria);
};

Related

How to get the row reference for the current cell in Google Scripts?

EDITED POST
I am a script newbie so bear with me... :)
I am getting the script to send an email using the info in the 28th thru 32nd column. I need to get the value of those cells in the current row.
With the script below, it works perfect if it is row 4 and I write 4.
function SendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('Form Responses 1');
var sheet2=ss.getSheetByName('TEMPLATE');
var subject = sheet2.getRange(2,1).getValue();
var addressee=sheet1.getRange(4,28).getValue();
var emailAddress = sheet1.getRange(4,29).getValue();
var room=sheet1.getRange(4,30).getValue();
var date=sheet1.getRange(4,31).getValue();
var time=sheet1.getRange(4,32).getValue();
var message = sheet2.getRange(2,2).getValue();
message=message.replace("<addressee>",addressee).replace("<room>",room).replace("<date>",date).replace("<time>",time);
MailApp.sendEmail(emailAddress, subject, message);
};
How do I get it to recognize what row is active and use that value? U sed the suggestion from "Huaye sun" as follows but I get the following error... "Exception: Failed to send email: no recipient"
The email address it should grab is in fact there. What am I missing?
function SendEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet1=ss.getSheetByName('Form Responses 1');
var sheet2=ss.getSheetByName('TEMPLATE');
var subject = sheet2.getRange(2,1).getValue();
var activeCell = sheet1.getActiveCell();
var currentRow = activeCell.getRow();
var addressee=sheet1.getRange(currentRow,28).getValue();
var emailAddress = sheet1.getRange(currentRow,29).getValue();
var room=sheet1.getRange(currentRow,30).getValue();
var date=sheet1.getRange(currentRow,31).getValue();
var time=sheet1.getRange(currentRow,32).getValue();
var message = sheet2.getRange(2,2).getValue();
message=message.replace("<addressee>",addressee).replace("<room>",room).replace("<date>",date).replace("<time>",time);
MailApp.sendEmail(emailAddress, subject, message);
};

EPPPlus cannot open RDLC rendered to EXCELOPENXML

Does anyone have any idea , or even a solution, to open an xlsx file using EPPlus created from an rdlc report.
At the moment, when I try to do this I get an null exception when I try to access the worksheets.
// filename is the xlsx file created by exported rdlc to excel
FileInfo newFile = new FileInfo(filename);
ExcelPackage pck = new ExcelPackage(newFile);
// I get error here
pck.Workbook.Worksheets.Add("New Sheet");
If you intention is to add onto the file you are using the wrong constructor. The one you are using now is for creating a new package off of a template. The on your want is this (without the extra Boolean) which will open the file directly:
ExcelPackage pck = new ExcelPackage(newFile);
Response to Comments
#A.Ellwood I just tried it with the file you posted and it works fine for me. Here is the code I used:
[TestMethod]
public void RDLC_Test()
{
var datatable = new DataTable("tblData");
datatable.Columns.AddRange(new[]
{
new DataColumn("Col1", typeof (int)), new DataColumn("Col2", typeof (int)),
new DataColumn("Col3", typeof (object))
});
for (var i = 0; i < 10; i++)
{
var row = datatable.NewRow();
row[0] = i;
row[1] = i*10;
row[2] = Path.GetRandomFileName();
datatable.Rows.Add(row);
}
var fi = new FileInfo(#"c:\temp\Report1.xlsx");
using (var pck = new ExcelPackage(fi))
{
var workbook = pck.Workbook;
var worksheet = workbook.Worksheets.Add("Sheet1");
worksheet.Cells.LoadFromDataTable(datatable, true);
pck.Save();
}
}

Importing Gmail text to a specific Google Sheets

I receive everyday the same email from an app I've made. Those emails have the same text except for some numbers (for example 2 instead of 9). I'm trying to build a script that automatically compiles my Google Sheets report.
function myFunction() {
var thread = GmailApp.getUserLabelByName("").getThreads(0,1)[0]; // get first thread in inbox
var message = thread.getMessages()[0]; // get first message
Logger.log(message.getBody()); // log contents of the body
}
but it doesn't work.
What am I doing wrong?
The following script works for me. Note that due to the time it takes to execute and to stop duplicate results, I change the label after it is moved to the spreadsheet.
function myFunction() {
var ss = SpreadsheetApp.openById("Insert Sheet ID");
var sheet = ss.getSheetByName("Email Import");
var label = GmailApp.getUserLabelByName("Label");
var labelNew = GmailApp.getUserLabelByName("Label Moved");
var threads = label.getThreads();
for (var i=0; i<threads.length; i++)
{
var messages = threads[i].getMessages();
for (var j=0; j<messages.length; j++)
{
var sub = messages[j].getBody();
sheet.appendRow([sub])
}
threads[i].addLabel(labelNew);
threads[i].removeLabel(label);
}
}

Create memory index with Elasticsearch.net

I try to create memory index with following code but it creates regular index.
Any idea?
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node);
var client = new Elasticsearch.Net.ElasticsearchClient(settings);
var js = JsonConvert.SerializeObject("{settings: { index.store.type: memory}");
var index = client.IndicesCreate("sampleIndex", js);
Your second argument to the IndicesCreate method call is not correct. See the code below for a better way to achieve it. The first three lines are the same. In the fourth one, we properly create the settings for the index.
_body = new {
settings = new {
index = new {
store = new {
type = "memory"
}
}
}
};
var index = client.IndicesCreate("sampleIndex", _body);

Which RadioButton in a group is checked (Google AppScript)

Using Google AppScript. How could I find the checked RadioButton in a group? If it requires handler then with server one.
Many Thanks
there is an open issue on this but there is also a nice workaround ;-) (found by Romain Vialard, GAS TC)
here is a slightly modified version of his script adapted to run on a spreadsheet :
function radiotest() {
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var radioValue = app.createTextBox();
radioValue.setId("radioValue").setName("radioValue");
// var radioValue = app.createHidden().setName("radioValue") ;// choose the one you like
for(var i = 1; i < 10; i++){
var name = 'choice '+i;
var handler = app.createClientHandler().forTargets(radioValue).setText(name);
panel.add(app.createRadioButton('radioButtonGroup',name).addValueChangeHandler(handler));
}
panel.add(radioValue);
var Valide=app.createButton("Valide").setId("val");
panel.add(Valide)
app.add(panel);
//
var handler = app.createServerHandler("valide"); // this is the server handler
handler.addCallbackElement(radioValue)
Valide.addClickHandler(handler);
//
SpreadsheetApp.getActiveSpreadsheet().show(app);// show app
}
//
function valide(e){ ;// This function is called when key "validate" is pressed
var sh = SpreadsheetApp.getActiveSheet();
var RadioButton = e.parameter.radioValue;
sh.getRange('A1').setValue(RadioButton);
var app = UiApp.getActiveApplication();
return app;
}​
Note that the radioValue item can be either a textbox or a hidden text, both possibilities are in the script/