admin管理员组

文章数量:1318156

Looking for something in google apps script that does something similar to ES6 javascript.

Ss.main.getRange('C2').setValue('${Ss.main.getRange(2,2).getDisplayValue()}')

expected C2 cell to equal the value in B2. instead i get ${Ss.main.getRange(2,2).getDisplayValue()}

Looking for something in google apps script that does something similar to ES6 javascript.

Ss.main.getRange('C2').setValue('${Ss.main.getRange(2,2).getDisplayValue()}')

expected C2 cell to equal the value in B2. instead i get ${Ss.main.getRange(2,2).getDisplayValue()}

Share Improve this question edited Apr 12, 2019 at 0:53 zmag 8,26112 gold badges37 silver badges46 bronze badges asked Apr 12, 2019 at 0:47 MavDarknessMavDarkness 511 silver badge2 bronze badges 1
  • Although I'm not sure whether I could correctly understand about your question, do you want to copy the value of "B2" to "C2" using Google Apps Script? – Tanaike Commented Apr 12, 2019 at 0:53
Add a ment  | 

2 Answers 2

Reset to default 5

Look at there: V8 Runtime Overview

Example:

// V8 runtime
var name = `Hi ${first} ${last}.`;
var url = `http://localhost:3000/api/messages/${id}`;

The current version of Apps Script does not support ES6 string literals (but that will change with the uping V8 upgrade, hopefully in the near future). In the meantime, you can leverage the Utilities.formatString() function.

Your sample code can be converted as follows:

Ss.main.getRange('C2').setValue(Utilities.formatString(
    "%s",
    Ss.main.getRange(2,2).getDisplayValue()
));

However, if all you need to do is convert the returned value to a string then you can use the getDisplayValue() call directly (since the function returns a string by default):

Ss.main.getRange('C2').setValue(Ss.main.getRange(2,2).getDisplayValue());

本文标签: javascriptwhat string literal is available in google apps scriptStack Overflow