Get link to sheet in image - javascript

how can i go to a specific sheet when i click on the image? I need to go to the "FERMENTADOR 2_002 / 2021" sheet when the user clicks on the "fermenter" image.
the problem is that the name of the sheet may change according to some criteria ... so the sheet to be activated needs to be with the value of cell A4 + the value of cell B16
function hyperlink(){
var sheet = SpreadsheetApp.getActiveSheet();
var nomeferm = sheet.getRange("A4").getValue();
var numlote = sheet.getRange("B16").getValue();
var pagina = nomeferm+"_"+numlote;
var tt = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(pagina);
}

Updated Code based on your comment:
function getToSheet() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName('HOME');
const name = sh.getRange('A4').getValue()+"_"+sh.getRange('B16').getValue();
const sheet = ss.getSheetByName(name);
if(sheet){
ss.setActiveSheet(sheet, true);
}
}
Solution:
I guess the most straightforward way is to attach the following very simple script to your image:
function getToSheet() {
const ss = SpreadsheetApp.getActive();
ss.setActiveSheet(ss.getSheetByName('FERMENTADOR 2_002/2021'), true);
}
The script will activate sheet FERMENTADOR 2_002/2021 therefore it will redirect you there.
You just need to assign this script to your image and then you can click on the image itself (see attached gif).
Illustration:

Related

How to import data from Google sheets to Slides

I am trying to create a button in google sheets that run a script every time it is triggered. The script should first create a new copy of the template and then using that google sheet replace all placeholder text in that presentation with data from sheets. I am not sure why the code is not working as of now.
// The following creates the UI button in sheets (This works)
function onOpen() {
let ui = SpreadsheetApp.getUi();
ui.createMenu('Create Report')
.addItem('Create Report', 'executeAll')
.addToUi();
}
function executeAll (){
var reportTemplate = DriveApp.getFileById('Presentation ID goes Here');
var copiedTemplate = reportTemplate.makeCopy('New Report', DriveApp.getFolderById("Folder ID Goes here"));
var skeleton = SlidesApp.openById(copiedTemplate.getId());
var slides = skeleton.getSlides();
return slide1();
function slide1 (){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('App Script Input Sheet');
var data = sheet.getRange('E1:F26').getValues;
var slide1 = slides[0];
var newslide1 = slide1.duplicate();
var shapes = (newslide1.getShapes());
shapes.forEach(function(shape){
shape.getText().replaceAllText('{{Date}}',data[2]);
shape.getText().replaceAllText('{{Title}}',data[3]);
shape.getText().replaceAllText('{{Value 1}}',data[4]);
shape.getText().replaceAllText('{{Value 2}}',data[5]);
//there are more to be replaced. will add once code works.
});
}
}

Google Sheet Script - onChange

Please help with Google onChange function Sheet Script.
I only want to log onChange for one sheet "Attendance" the change on this sheet is then logged in "Sheet5"
When there is a change in "Attendance" column C, then copy the value of column B into "Sheet5" and add the current date and time. Here is some code I tried, but do not know how to change it.
function createSpreadsheetOpenTrigger() {
ScriptApp.newTrigger('onChange')
.forSpreadsheet('ID to go here')
.onChange()
.create();
}
function onChange(e) {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet5");
const lastRow = sheet.getLastRow();
sheet.getRange(lastRow + 1,1,1,4).setValues([
[e.changeType,
e.source.getSheetName(),
e.source.getActiveSheet().getActiveRange().getValue(),
new Date()]
]);
}
Try this:
function onEdit(e) {
const sh=e.range.getSheet();
if(sh.getName()=='Attendance' && e.range.columnStart==3 && e.range.rowStart>'Your header row') {
e.source.getSheetByName("Sheet5").appendRow([e.range.offset(0,-1).getValue(),new Date()]);
}
}
onedit event obj

Issues with Triggers on Google Script

I have the following function which works perfectly fine when I run it manually.
function LastUpdate() {
var thisSS = SpreadsheetApp.getActiveSpreadsheet();
var sheet = thisSS.getSheetByName('Roster');
var data = Session.getActiveUser().getEmail();
var Edit = 0;
var time = TimeStamp();
var Row;
Row = findInColumn("L", data);
Edit = checkEdits(Row);
if (Edit == 1)
{
sheet.getRange(Row,20).setValue(time);
}
}
I set up a trigger manually by going to Resources -> Triggers and selected the above Function to execute onEdit. Basically, whenever a cell in the sheet is edited, I want to automatically trigger this function to execute. I am not sure what the issue is !
Any help would be much appreciated.
EDIT - I tried to do this and this also does not work
function onEdit(e)
{
LastUpdate ()
}
Why don't you use the simple onEdit trigger instead of the installed trigger? Since you're looking for the latest edit made by the active user that might be a much easier, faster and more stable solution.
function onEdit(e){
var range = e.range; //edited range
range.getColumn();
range.setValue();
//etc
}

Set background color for excel range using javascript

I want to open an existing .xls file, set the background color for the header and also merge few columns of the 1st row using javascript.
Thanks for any help.
Here is my code as of now.. I could, set the background color index of the cell and merge the cells.
var xls = new ActiveXObject("Excel.Application");
xls.visible = true;
xls.DisplayAlerts=false;
var wb=xls.Workbooks.Open("C:\\ECN REPORT.xls");
xls.Range("A1","B1").Interior.ColorIndex=37;
xls.Range("C1","D1").Interior.ColorIndex=37;
xls.Range("A1:D1").Merge();
wb.SaveAs("C:\\ECN REPORT.xls");
xls.Quit();
I have set the DisplayAlerts=False and want to save the excel again with wb.SaveAs(); It saves the file without prompt, but the merge changes are not reflected in the excel file.
Could somebody let me know where im wrong? Thanks in advance.
Font Color:
oSheet.Range("A1","X1").Font.ColorIndex = 49;
Interior Color:
oSheet.Range("A1","X1").Interior.ColorIndex = 15;
Merging Cells:
oSheet.Range("A1","X1").Merge();
or
oSheet.Range("A1","X1").MergeCells = true;
Here's the working example for my question.
It checks if the file exists, if so deletes and then creates an excel, merges columns, sets background colors,borders,fon.
var Excel = new ActiveXObject("Excel.Application");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var checkFile= fso.FileExists("C:\\Report.xlsx");
if(checkFile)
{
fso.DeleteFile("C:\\Report.xlsx",true);
}
var ExcelSheet=new ActiveXObject("Excel.Sheet");
ExcelSheet.ActiveSheet.Range("A1","G1").Merge();
ExcelSheet.ActiveSheet.Range("A1").value="ECN REPORT";
ExcelSheet.ActiveSheet.Range("A1").Font.Bold = true;
ExcelSheet.ActiveSheet.Range("A1").Font.Size = 24;
ExcelSheet.ActiveSheet.Range("A1").HorizontalAlignment = -4108;
ExcelSheet.ActiveSheet.Range("A1","F1").Interior.ColorIndex=2;
// xlEdgeLeft,xlEdgeTop,xlEdgeBottom,xlEdgeRight all set to continuous borders
ExcelSheet.ActiveSheet.Range("A1","F1").Borders(7).LineStyle=1;
ExcelSheet.ActiveSheet.Range("A1","F1").Borders(8).LineStyle=1;
ExcelSheet.ActiveSheet.Range("A1","F1").Borders(9).LineStyle=1;
ExcelSheet.ActiveSheet.Range("A1","F1").Borders(10).LineStyle=1;

Google Spreadsheet Custom Menu Returned Script Function Not Found

I am trying to add a custom menu to the google spreadsheet editor's interface to activate a script by Tony Hirst to pull calendar events into the spreadsheet.
By when I click on the custom menu option, it returned "script function not found: GetCalendar()"
I have tried to make modifications and read the google documentation but am not sure what I am doing wrong.
Thank you.
/**
* A custom function that gets the calendar events by calendar ID.
*/
function GetCalendar() {
// get the spreadsheet object
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
// set the second sheet as active
SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[1]);
// fetch this sheet
var sheet = spreadsheet.getActiveSheet();
//http://www.google.com/google-d-s/scripts/class_calendar.html#getEvents
// The code below will retrieve events between 2 dates for the user's default calendar and
// display the events the current spreadsheet
var calId = "SpecificCalendarID";
var cal = CalendarApp.getCalendarById(calId);
var events = cal.getEvents(new Date("June 15, 2015"), new Date("March 20, 2080"));
for (var i=0;i<events.length;i++) {
//http://www.google.com/google-d-s/scripts/class_calendarevent.html
var details=[[events[i].getTitle(), events[i].getDescription(), events[i].getStartTime()]];
var row=i+2;
var range=sheet.getRange(row,1,1,3);
range.setValues(details);
}
}
/**
* A function that runs when the spreadsheet is open, used to add a
* custom menu to the spreadsheet.
*/
function onOpen() {
var ui = SpreadsheetApp.getUi();
var menuItems = ui.createMenu ('Custom Menu');
menuItems.addItem ('Get Events','GetCalendar()');
menuItems.addToUi();
}
Remove the parenthesis from GetCalendar()
Should be:
menuItems.addItem ('Get Events','GetCalendar');

Categories

Resources