How do I name a range in google docs? - google-apps-script

The Google Apps Script API for Docs has a number of methods defined that work with Named Ranges in Docs. While I am familiar with Named Ranges in Sheets, I cannot find a way to name a range in Docs.
Does anyone know how to name a range using the Docs UI? (obviously one can do so programmatically).

I was wondering about that also, but it looks as if it is not possible to edit or even see named ranges in the docs UI.
Lets hope, this will be changed in the future...

Related

Google Apps Script: Get list of users "assigned" to a google doc and comments

In google docs, when commenting on something, you can type "+" to 'assign' a user to an item. I'm wondering if there's a way to get the list of "assigned" users in a google doc (and maybe filterable by status - resolved/done/etc).
I've seen some other posts stating that getting comment data isn't possible within the Documents Apps script, but that it is possible with the Drive API. Can the Drive API be used in a Google Sheets script? If so, could it be used to get the information mentioned above?
The Advanced Drive API can get a list of all comments in a spreadsheet but I don't think it will achieve what you are looking for as you can't tell which cell the comments are attached to.
I don't think you will be able to assess the assigned status using this method.

Google sheets Named ranges not consistent between sheets

I have two similar spreadsheets that share code in an apps script library.
I use named ranges to access the sheets from the code.
In one spreadsheet the ranges are sheetname!range like this:
and the other spreadsheet just uses range:
I have tried copying both spreadsheets and tried recreating ranges to match the other format but nothing seems to work. I have looked for something that tells me that the spreadsheets are different versions but cant find anything that is different. I can make the code look for either format but.....
If you copy a worksheet in a spreadsheet with a Named Range, then Google Sheets has to do something, as you can't have two Named Ranges with the same name in the same spreadsheet. What it does is create new Ranges with worksheet-level scope of the form: newworksheet!existingnamedrange. So I think that probably explains how you got to where you are.
In terms of fixing it? You can just delete the newworksheet!existingnamedrange name and recreate existingnamedrange. As you can have the same name in different spreadsheets. Or am I misunderstanding the problem?

Google Apps Script: Get the ID of script bound to a spreadsheet

I want to write a Google Apps Script to generate a list of the IDs of the scripts bound to certain spreadsheets.
I cannot find a way to programmatically, via GAS, get the ID of a bound script.
If I have a spreadsheet object, I have methods like getId to get the ID of the spreadsheet, but not the bounded script.
Using the DriveApp, I can find standalone scripts using DriveApp.getFilesByType('application/vnd.google-apps.script') but not bound ones!
Any suggestions?
Unfortunately (by my own research) this is not currently possible. I have been wanting to programatically identify and access bound scripts for several years, I look into it periodically, I've always come up empty handed.
Haven't found any Google documentation explicitly on the topic, still hoping this hole gets filled eventually.

How to use ImportXML in a Google Script?

Scenario:
I am trying to use Google spreadsheet to do something like this:
I've a set of Blog URL's (more than 50) for which I want to fetch title
Currently I am using the formula: ImportXML(A2,"//h1[#class='entry-title']" )
The Problem w/ this approach is that ImportXML calls are limited to 50 per spreadsheet and I've more than 50.
I browsed/searched - found out that we can use ImportXML calls in google apps script but did not found any example.
I found this: https://developers.google.com/apps-script/articles/XML_tutorial but I was hoping to use ImportXML function.
Can anyone describe or point to a resource where they have used ImportXML in a google apps script? Thanks!
I would use a few spreadsheets, then pull the results together into a master spreadsheet, or are you doing >1000 or so. If you have lots, the XML_tutorial link you have is the place to start.
But last time I checked, google-apps-script does not support google spreadsheet functions, if I remember, the feature request to support all spreadsheet functions in GAS was rejected.

alternative to setrowsdata in Google Apps Scripts

Writing to a Google Spreadsheet from Google App Scripts is described here:
https://developers.google.com/apps-script/storing_data_spreadsheets#writing
Which includes details of the setRowsData method.
I was wondering if there was a method for just setting an individual cell in the spreadsheet. I've searching Google and SO, but can't find anything yet. I'm guessing perhaps that setRowsData is the only way to go, but if there's an alternative setCellData call or similar I'd love to hear about it.
Many thanks in advance
p.s. profusely sorry if this isn't the right place to ask, but the Google App Script team is directing all questions to SO
The Range.setValue service to set a value of a cell. The range should be defined to the cell, for instance, the follwing code does it.
var range = SpreadsheetApp.getActiveSheet().getRange("A1");