Javascript如何使用setFormula

时间:2017-12-01 13:40:21

标签: javascript google-apps-script google-sheets spreadsheet

如何将变量放在import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author */ public class FileCatch8 { public static void main(String args[]) { List<String> fileNames = new ArrayList<>(); try { DirectoryStream<Path> directoryStream = Files.newDirectoryStream (Paths.get("files")); int fileCounter = 0; WordCount wordCnt = new WordCount(); for (Path path : directoryStream) { System.out.println(path.getFileName()); fileCounter++; fileNames.add(path.getFileName().toString()); System.out.println("word length: " + fileCounter + " ==> " + wordCnt.count(path.getFileName().toString())); } } catch(IOException ex){ } System.out.println("Count: "+fileNames.size()+ " files"); } }

的引号中
.setFormula

我的问题是变量文本是一个名称,我需要它作为条件在引号中。如果没有,公式将不起作用,并且需要设置activeSheet.getRange(125,2).setFormula("=SOMME.SI($A$1:$A$40;"+text+";B1:B40)*B124"); manualy

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

你可以使用单引号

activeSheet.getRange(125,2).setFormula("=SOMME.SI($A$1:$A$40;'"+text+"';B1:B40)*B124");

甚至更好地使用string template literals(注意反引号)

activeSheet.getRange(125,2).setFormula(`=SOMME.SI($A$1:$A$40;"${text}";B1:B40)*B124`);