将字符串转换为Google Spreadsheet中的公式 [英] Convert a string to a formula in Google Spreadsheet

本文介绍了将字符串转换为Google Spreadsheet中的公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了十多个小时,并尝试了不同的选择,但都没有成功.

I´d been more than 10 hours reading and trying different options with no success.

我有这个字符串(这实际上是由其他公式生成的字符串)

QUERY({IMPORTRANGE(A1;$D$1);IMPORTRANGE(A2;$D$1);IMPORTRANGE(A3;$D$1);IMPORTRANGE(A4;$D$1)};"select Col13, sum(Col1), sum(Col2), sum(Col3), sum(Col4), sum(Col5), sum(Col6), sum(Col7), sum(Col8), sum(Col9), sum(Col10), sum(Col11), sum(Col12) group by Col13";0)

我希望将其作为公式阅读. 因此,例如,我尝试使用此功能:

And I want it to be read as a formula. So for example I try this function:

function doConvert(formula) {
  // Strip leading "=" if there
  if (formula.charAt(0) === '=') formula = formula.substring(1);
  return eval(formula);
}

但是我得到了

错误/语法错误:Falta:"发行说明.

Error / SyntaxError: Falta ":" detrás del ID de propiedad.

(用英语写的是::",位于属性ID后面.

(In English would be: ":" missing after property ID.

任何其他解决方案都很好.

Any other solution would be great.

推荐答案

=添加到生成的字符串中,然后尝试执行以下操作:

add = to your generated string and try like this:

function onEdit() { 
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet_Name_Here');  
var src = sheet.getRange("A1");              // The cell which holds the formula
var str = src.getValue(); 
var cell = sheet.getRange("C5");             // The cell where you want the results to be in
cell.setFormula(str);              
}

这篇关于将字符串转换为Google Spreadsheet中的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆