V
V
Vladimir Zuev2020-06-04 13:14:10
Google Sheets
Vladimir Zuev, 2020-06-04 13:14:10

How to insert a string into a Google sheet cell instead of a formula?

Hello.
How to insert a string into a Google sheet cell instead of a formula?
Line such
"94,05 грн.+ 60 грн."
Tried on everyone. Here is the code

async function getProductsById () {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet1 = ss.getSheetByName('Продажи на Prom ua');
 var spreadsheet = SpreadsheetApp.getActive();
let x = 0;
var price;
var str= "";

var headers = {
  'Authorization': 'Bearer *******************************',
 'contentType': 'application/json; charset=utf-8'
};    
 
var options = {
      'method' : 'get',
      'headers': headers
          
};
while (x < 10) {        
        var result = await UrlFetchApp.fetch('https://my.prom.ua/api/v1/orders/113203508', options);         
        if (result) {break;}        
      x++
}; 
 orderList =  JSON.parse(result.getContentText());  
var  lngth = orderList["order"]['products'].length;
for (let i = 0; i<lngth; i++ ){
 price = orderList["order"]['products'][i]['price'];
if(i<lngth-1){
 str= str + price + '+ '+' ';
 } 
 else {str= str + price}
}
 var lr = sheet1.getLastRow();

cell = sheet1.getRange(lr+1,1);
cell.setFormula('=A1000+B1000 '+ str);

 //var orderList1 = JSON.stringify(orderList, null, 2);
 //Logger.log(orderList1); 

}

Please help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
1
1ndrei, 2020-07-25
@vladd56

Rewrite like this:
cell.setFormula('" "&"' + str+'"');
or like this:
cell.setFormula('""&"' + str+'"');

G
Grigory Boev, 2020-06-04
@ProgrammerForever

Instead , write This is just not the application of a formula, but "just a string", or rather, a value.
cell.setFormula('=A1000+B1000 '+ str);
cell.setValue('=A1000+B1000 '+ str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question