Is it possible to get the values of the date-input-boxes from rangeSelector?
var chart = new Highcharts.StockChart(chartingOptions);
...
var zoomStartEpochTime = chart.rangeSelector.leftBox.HCTime;
var zoomEndEpochTime = chart.rangeSelector.rightBox.HCTime;
Alternatively you can query the xAxis's extreme values for the same
var zoomStartEpochTime = chart.xAxis[0].getExtremes().min;
var zoomEndEpochTime = chart.xAxis[0].getExtremes().max;
Yes you can get these values. If you are using JQuery:
var minDate = $('input.highcharts-range-selector:eq(0)').val();
var maxDate = $('input.highcharts-range-selector:eq(1)').val();
Related
I'm trying to get this code to work but keep getting a "TypeError: offset.copyTo is not a function". The script is supposed to take one value from sheet "Budget" and copy it into the next available row in column F on sheet "Projected".
I have tried playing around with syntax and other ways to copy but to now avail, any help would be greatly appreciated
function OffsetRecord() {
var sheet = SpreadsheetApp.openById("xx").getSheetByName("Budget");
var offset = sheet.getRange('I5').getValue();
var destSheet = SpreadsheetApp.openById("xx").getSheetByName("Projected");
var colF = destSheet.getRange('F:F').getValues();
var fcolF = colF.filter(function (e) {return e[0];});
var firstEmptyRowIncolF = fcolF.indexOf('')+1;
offset.copyTo(firstEmptyRowIncolF, {contentsOnly: true});
copyTo expects ranges as parameters, not values or column numbers, see here
Modify your code as following:
function OffsetRecord() {
var spreadsheet = SpreadsheetApp.openById("XX");
var sheet = spreadsheet.getSheetByName("Budget");
var offset = sheet.getRange('I5');//without ".getValue();"!
var destSheet = spreadsheet.getSheetByName("Projected");
...
firstEmptyRowIncolF = ...;
var destinationColumn = 1;
var range = destSheet.getRange(firstEmptyRowIncolF, destinationColumn);
offset.copyTo(range, {contentsOnly: true});
}
So I am new to Google Sheets. I am making an inspection report for a small company using Sheets. I would like to add a button to the bottom of the sheet which does the following script:
Duplicate original sheet
Rename sheet to a cell value +today's date. i.e Fred01011980
Email the sheet as a PDF to a recipient.
Finally clear the inputted values in the original master template sheet.
I have looked up how to do each of these and a few of them are straightforward, but I don't know how to combine them. Can I just add all of the functions individually together without any additional syntax needed? Any help on this would be really appreciated. Thank you.
I believe you can just create another function that calls your functions, like this:
function doAllStuff() {
doStuff();
doMoreStuff();
}
Here's how I did it:
function AllinOne() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var name = "Inspection";
var sheet = ss.getSheetByName("Inspection").copyTo(ss);
var newname = ss.getSheetByName("Inspection").getRange(2, 2).getValue();
var newnamedate = ss.getSheetByName("Inspection").getRange(3, 2).getValue();
var sheetx = ss.getActiveSheet()
var thisSheet = sheetx.getName();
var actualSheetName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName()
var sheetfinal = ss.getSheetByName("Inspection")
var old = ss.getSheetByName(newname+newnamedate);
if (old) ss.deleteSheet(old);
sheet.setName(newname+newnamedate); //copies the sheet and renames it to "store+date"
ss.setActiveSheet(sheet)
// below is pdf conversion
var originalSpreadsheet = SpreadsheetApp.getActive();
var sourcesheet = originalSpreadsheet.getActiveSheet();
var sourcerange = sourcesheet.getRange('A1:B176'); // range to get - here I get all of columns which i want
var sourcevalues = sourcerange.getValues();
var data = sourcesheet.getDataRange().getValues();
var newSpreadsheet = SpreadsheetApp.create(thisSheet); // can give any name.
var sheetnow = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var projectname = SpreadsheetApp.getActiveSpreadsheet();
var sheetz = sourcesheet.copyTo(newSpreadsheet);
var destrange = sheetz.getRange('A1:B176');
destrange.setValues(sourcevalues);
newSpreadsheet.getSheetByName('Sheet1').activate();
newSpreadsheet.deleteActiveSheet();
var pdf = DriveApp.getFileById(newSpreadsheet.getId());
var theBlob = pdf.getBlob().getAs('application/pdf').setName(newname+newnamedate);
var folderID = "File_ID"; // Folder id to save in a folder.
var folder = DriveApp.getFolderById(folderID);
var newFile = folder.createFile(theBlob);
DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);
MailApp.sendEmail("Email","New Manager Inspection: "+newname+newnamedate, "A new Manager Inspection Report has been added to the Drive.");
ss.getSheetByName(name).getRangeList(["B176","B150:B164","B138:B146","B129:B134","B119:B125","B106:B115","B99:B102","B84:B95","B78:B80","B66:B74","B55:B62","B48:B51","B34:B44","B25:B30","B18:B21","B10:B14","B4:B7","B2","B16","B23","B32","B46","B53","B53","B64","B76","B82","B97","B104","B117","B127","B136","B148","B166"]).clearContent();
ss.setActiveSheet(sheetfinal);
SpreadsheetApp.getUi().alert("Report Submitted, Please do NOT Resubmit. Thank You");
}
I have this:
var app = SpreadsheetApp;
var activesheet = app.getActiveSpreadsheet().getActiveSheet();
var RecipeList = app.getActiveSpreadsheet().getSheetByName('Recipe List')
var recipename = activesheet.getRange('D3').getValue();
var costperserve = activesheet.getRange('J5').getValue();
var foodcostpercentage = activesheet.getRange('J6').getValue();
var sellingprice = activesheet.getRange('J7').getValue();
var grossprofit = activesheet.getRange('J10').getValue();
var spreadsheetname = activesheet.getSheetName() ;
var Last = RecipeList.getLastRow();
RecipeList.getRange(Last+1,1,1,1).setValue(recipename), {contentsOnly:true};
RecipeList.getRange(Last+1,2,1,1).setValue(costperserve), {contentsOnly:true};
RecipeList.getRange(Last+1,3,1,1).setValue(foodcostpercentage),
{contentsOnly:true};
RecipeList.getRange(Last+1,4,1,1).setValue(sellingprice), {contentsOnly:true};
RecipeList.getRange(Last+1,5,1,1).setValue(grossprofit), {contentsOnly:true};
RecipeList.getRange(Last+1,6,1,1).setValue(spreadsheetname),
{contentsOnly:true};
Though I want the values to = ( = 'spreadsheetname' !D3) as a pose to just the value so I can change the value and it is updated.
There is a setFormula() method that you can use exactly like setValue(), but it's not necessary. You can use setValue() just as well here.
It looks like you're trying to pass an option of {contentsOnly:true} into setValue(), but that's not valid. As you can see in the linked documentation, this method doesn't allow any options. Moreover, it doesn't allow that particular option because it affects the contents only anyway.
Try this example code:
function insertFormulaTest() {
var ss = SpreadsheetApp.getActive();
var sourceSheet = ss.getSheetByName("Source Sheet");
var sourceCell = sourceSheet.getRange("D3");
var formula = "='" + sourceSheet.getName() + "'!" + sourceCell.getA1Notation(); // "='Source Sheet'!D3"
var destinationSheet = ss.getSheetByName("Destination Sheet");
destinationSheet.getRange("A1").setValue(formula);
}
I have a script that will copy a line into another sheet when I enter a value in column 17 (the date when the file is closed).
I don't know why but before copying, the format changes and the date appears in numeric format
for example: 04/08/2017 => 42951
Any idea on what could be the problem?
Here is my script:
function onEdit(r) {
var sheet = r.source.getActiveSheet();
if(sheet.getName()!="Remboursements"){return}
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source_sheet = ss.getSheetByName("Remboursements");
var target_sheet = ss.getSheetByName("Remboursements traités");
var range1 = r.range;
var columnOfCellEdited = range1.getColumn();
if (columnOfCellEdited === 17){
var source_range = source_sheet.getRange("A"+ range1.getRow()+":Q"+ range1.getRow());
var last_row = target_sheet.getLastRow();
target_sheet.insertRowAfter(last_row);
var target_range = target_sheet.getRange("A"+(last_row+1)+":Q"+(last_row+1));
source_range.copyTo(target_range);
source_sheet.deleteRow(range1.getRow())
}
}
Here's another way to do this:
function onEdit(r) {
if(r.source.getActiveSheet().getName()!="Remboursements"){return}
var source_sheet=r.source.getSheetByName("Remboursements");
var target_sheet=r.source.getSheetByName("Remboursements traités");
if (r.range.getColumn()==17)
{
var source_range=source_sheet.getRange("A"+ r.range.getRow() +":Q"+ r.range.getRow());
var values=source_range.getValues();
target_sheet.appendRow(values);
source_sheet.deleteRow(r.range.getRow())
}
}
I'm trying to create a script in google sheets. What I'm trying to do is to search the value of a cell (let's say A2 sheet1), then change the value of another cell (B2 sheet2). When the first iteration is over, proceed to the next row (A3 sheet1) and again change the value of B2. Also wait 10 secs at the end of every iteration.
I don't know why it is not working. After I run the code it just says "Finished", but nothing has changed.
function test() {
var ss = SpreadsheetApp.getActive();
var gensheet = ss.getSheetByName('Generador SE');
var clientsheet = ss.getSheetByName('Clientes SE');
var clientrange = clientsheet.getRange("A1:C200");
var clientsquantity = clientrange.getNumRows()
var servicetochange = gensheet.getRange(2,2)
var i;
for (i=1;i>clientsquantity;i++){
var currentservice = clientrange.getRange(i,1).getValue;
servicetochange=gensheet.getRange().setValue(currentservice);
Utilities.sleep(10000);
}
}
I have changed some code in the loop ... now it does something (but I can't be sure it does what you expect):
function test() {
var ss = SpreadsheetApp.getActive();
var gensheet = ss.getSheetByName('Generador SE');
var clientsheet = ss.getSheetByName('Clientes SE');
var clientrange = clientsheet.getRange("A1:C200");
var clientsquantity = clientrange.getNumRows()
var servicetochange = gensheet.getRange(2,2)
var i;
for (i=1;i<clientsquantity;i++){
var currentservice = clientrange.offset(i,0,1,1).getValue();
servicetochange.offset(i,0,1,1).setValue(currentservice);
Utilities.sleep(10000);
}
}