Google Sheets Script Parameter for e.g. Button - excel

Is it possible to pass parameters on a signed script?
I have a spreadsheet and made a couple of buttons signing functions to each.
Sample function:
function foo(){
return "bar";
}
Calling this function on a cell
=foo()
returns me bar, signing this function to a button
foo
returns me nothing but of course it works. I mean the script cant return a string to an image (whats actually my button). Anyways...
Sample function with parameter:
function foo(bar){
return bar;
}
calling the script in a cell
=foo('hello world')
returns me hello world as expacted
Signing this to my button
foo('hello world')
causes an error because the button cant find the script. He's searching for a function name foo('hello world') but (...) has non to do with the function.
So how can I pass params when signing script?
At the moment I have 26 functions (all the same, only 1 param changes) to solve this. But with passing a parameter I could do all this with 2 functions instead of 26.

You can't pass parameters when using a custom function via assigning it to a drawable image. It only works when the custom function is called from a cell.
Possible workarounds is to store your parameters on certain sheets and cells then retrieve them via
getRange() and getDisplayedValue().
Other possible workarounds are posted in a Google product help forum which can be found here

I found the best option to create separate helper methods for each individual button, which then pass the correct parameter to the generic method.
In the below example you would bind to the buttons the city specific method, for example for "Helsinki" button "updateAvailabilityInfoHelsinki".
function updateAvailabilityInfoHelsinki() {
updateAvailabilityInfo("Helsinki");
}
function updateAvailabilityInfoPorvoo() {
updateAvailabilityInfo("Porvoo");
}
function updateAvailabilityInfo(citySheet) {
// Do something with citySheet parameter
}

Related

nodejs pass parameter after parameter

I know that the title looks crazy
but here is the problem
i have a function with 2 parameter both have default value
function a(author="unknown" message="my message"){
...
}
i can access it using a("john", "hello")
but what if i need to change only the 2nd parameter?
a("","hello")
if i set the first param to "" it change the default
so i need to do?
i want is a(default,message="new message")
An alternative way to achieve this is if you can modify the function to accept an object then you can choose which parameters to pass in.
function a({ author="unknown", message="my message" } = {}){
...
}
then to call it
a({ message: "new message" }
Put simply, no, there is no way in js to get parameters by name, only by order.
You can always consult the docs for that information here.
You should call your function in the below manner.
eg.
a(undefined, "new message")
This will take default value of author and take message parameter.
This is answered properly in one of the question. Check it here

Getting excel range from argument example javascript api

I am trying to write a custom function in scriptlab to check if a value is in a selected range, however I cannot seem to figure out how to actually accept that range as the function argument. The example function I have created is below (where I thought range would equal something like "A1:D1"):
/** #CustomFunction */
async function exists(range): any {
const sheet = context.workbook.worksheets.getActiveWorksheet()
sheet.getRange(range)
...
}
This however results in a $CALC! error. Any tips or ideas?
Custom Function doesn't support to call office.js API yet. Please stay turned, that will be enabled soon.

Blockly: How to obtain value of a Dropdown or Checkbox Block

I´m new to Blockly and can not find a way to obtain field value of a dropdown or checkbox.
Lets consider following scenario (generated with blockly-dev-tools):
Blockly.Blocks['feature'] = {
init: function () {
this.appendDummyInput()
.appendField("Feature") // just for label
.appendField(new Blockly.FieldDropdown([["manufacturer", "feature_manufacturer"], ["profile", "feature_profile"], ["glas", "feature_glas"]]), "category"); // for dropdown values
this.appendValueInput("feature_name")
.setCheck("String")
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("Name");
this.appendValueInput("feature_prio")
.setCheck("Number")
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("Priorität");
this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("Versteckt")
.appendField(new Blockly.FieldCheckbox("TRUE"), "hidden");
now obtaining values from value inputs is not a problem, you can get thouse like this:
const featureName = element.getInputTargetBlock("feature_name");
if (featureName) {
console.log(featureName.getFieldValue("TEXT"));
}
const featurePrio = element.getInputTargetBlock("feature_prio");
if (featurePrio) {
console.log(featurePrio.getFieldValue("NUM"));
}
but dummy inputs hosting dropdowns or checkboxes have no methods to provide selected values.
It might be that this is my conceptual error to use dummy inputs to host the elements, but when using value input, you have always those nipples to the right, which are obsolate, since the values are provided by the checkbox or dropdown.
You should be able to skip the middleman and use element.getFieldValue. For example, to get the value from the checkbox field named "hidden", you could use element.getFieldValue("hidden").
P.S. You can also skip the element.getInputTargetBlock middleman and use Blockly.JavaScript.valueToCode (I.E., to get the value of the block in the "feature_name" input, you could use Blockly.JavaScript.valueToCode(element, "featureName", Blockly.JavaScript.ORDER_ATOMIC) or what have you). If you use a different generator than JavaScript, replace JavaScript with the generator you use (e.g. Python or whatever).

Using XMLHttpRequest To Paste Clipboard

I am currently using Flask to create a website and have come across an interesting issue. There is some code that gives the user the option to input a value in for about 20 separate input fields. What I am trying to do is construct a button that would allow the user to paste in a column from an Excel table. Essentially, a button that will look at the clipboard, take the field, convert the string into an array, and place the values into each input in the order they appear in the list.
So far, I have been able to get the clipboard into a string using tk.Tk().clipboard_get(), and believe that I can get this value by making an XMLHttpRequest, but have had little luck in making it actually work.
Some code for what I am trying to accomplish:
Python:
#app.route('/some/path/here', methods = ['GET'])
def paste():
try:
values = tk.Tk().clipboard_get()
values = values.replace('\n',',')
return values
except:
return None
HTTP:
<button type="button" style="float: right" onclick="Testing()">Paste</button>
<p id="textHere"></p>
JavaScript:
<script>
function Testing() {
var wvpst = new XMLHttpRequest();
wvpst.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200) {
var list = this.responseXML;
// list = list.replace(/'/g,"").replace(/ '/g,"");
// list = list.split(", ");
document.getElementById("textHere").innerHTML = list;
}
}
wvpst.open("GET","{{ url_for('paste') }}",true);
wvpst.send();
}
</script>
For now, I am just trying to get the list of values copied from an Excel sheet, but nothing is being returned when the button is pressed. Am I simply using XMLHttpRequest incorrectly or is there something else I need to do to get this to work?
Set a debug breakpoint inside
if (this.readyState == 4 && this.status == 200) {
}
and inspect your response. Set another on the first line of your function in Flask. Those should give you visibility into where the breakdown is.
A few other, perhaps more important notes:
Point 1) In your flask try/except, on failure you should serve a response, just a 500 response. Replace return None with:
return app.make_response('Couldn't parse clipboard information!'), 500
Point 2) There is no need to pass this information to your server for processing. You can accomplish this within the javascript of the front end and save your server some processing and your client some time waiting on an HTTP response.
Have the user paste their content into a textbox or another element, and then access the value from there.
Direct clipboard access isn't something most browsers give up freely, and so best to avoid that route.
Summary:
Your xmlhttprequest looks fine to me. I would guess that your try in flask is failing and returning something useless if anything at all.
Do this in javascript.

Drupal6: In theme_preprocess_page(&$vars), where do $vars come from? (How to manipulate breadcrumb)

I want to remove the breadcrumb when it's just one entry ("Home"). I'm in my theme's theme_preprocess_page(&$vars) function. $vars['breadcrumb'] is available, but it's just HTML. This is a bit to clumsy to work with. I'd rather get it as an array of items in the breadcrumb list, and do something like this:
if (count($breadcrumb) == 1) {
unset($breadcrumb);
}
Where does $vars come from? How can I override the code creating it originally?
A $vars array is passed on between all preprocess functions. In case of the _preprocess_page functions, most of the values in $vars are created in template_preprocess_page (see http://api.drupal.org/api/function/template_preprocess_page/6). In that function, you'll see:
$variables['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb());
Here, drupal_get_breacrumb returns an array of breadcrumb elements, which is then themed by the theme_breadcrumb() function (or its override).
The easiest way to get what you want is to override the theme_breadcrumb function. To do that, you take the original theme_breadcrumb function (http://api.drupal.org/api/function/theme_breadcrumb/6), copy it to your template.php, replace 'theme' in the function name with the name of your theme and alter the code so it looks like this:
function THEMENAME_breadcrumb($breadcrumb) {
if (count($breadcrumb) > 1) { // This was: if (!empty($breadcrumb))
return '<div class="breadcrumb">'. implode(' » ', $breadcrumb) .'</div>';
}
}
For a better understanding of Drupal theme overrides and preprocess functions, see About overriding themable output and Setting up variables for use in a template (preprocess functions).

Resources