I am new to google app script. I am stuck in a situation. I have some ranges(created in spreadsheet) and I want to get the name of sheet associated to that ranges. The following function is on docs and I want to copy data by giving some ranges from sheet.
function selectTable(sheetURL,ranges,rangevalues )
{
var workbook = SpreadsheetApp.openByUrl(sheetURL);
var currentSheetId=workbook.getId();
// get the Spreadsheet by sheet id
var totalSheets = SpreadsheetApp.openById(currentSheetId);
// select the sheet
var sourcesheet = source.getSheetByName(rangevalues);//here i ma stuck I have ranges only and I want sheetname
var abc=sourcesheet.getNamedRanges();
Logger.log("source sheet name-:"+sourcesheet);
// get the values on selectd range
var srcData = sourcesheet.getRange(ranges).getValues();
Logger.log("getting the values-:"+srcData);
}
I am referring this answer Copy a range of SpreadSheet to a Doc.
To get the name of a sheet from a range object use:
range.getSheet().getName()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With