简体   繁体   English

空单元格时如何使用脚本插入公式

[英]How to use script to insert a formula when there's an empty cell

I have one spreadsheet that has all my website's pricing. 我有一个包含我网站所有价格的电子表格。 I run a script to convert the spreadsheet into a format that I can upload to my website. 我运行脚本将电子表格转换为可以上传到我的网站的格式。 But sometimes I have a cost price but the supplier doesn't provide a Recommended Retail Price (RRP). 但是有时候我有一个成本价,但是供应商没有提供建议零售价(RRP)。 So when I upload the file, some products end up with a price of $0.00. 因此,当我上传文件时,某些产品的价格为0.00美元。

I'm trying to get the following working, but I reckon I'm missing something. 我正在尝试以下工作,但我想我缺少了一些东西。 The RRP is in skuData[i][6] or column G in the original spreadsheet. RRP在skuData [i] [6]或原始电子表格的G列中。 Column F has the cost price in the original spreadsheet or skuData[i][5] I guess. 我想F列的成本是原始电子表格或skuData[i][5]

// When No RRP
if (skuData[i][6].isBlank()) {
cell.setValue("=ROUND((F2*1.3),0)-0.01");
}

I'm trying to make it do the following: 我正在尝试使其执行以下操作:

If price is 100 and RRP is empty then make RRP 129.99 如果价格为100并且RRP为空,则使RRP为129.99

Assuming that cell is a Range there is a setFormula function that you can use. 假设单元格是一个范围,则可以使用setFormula函数。 Also assuming that skuData[i][6] is the two dimensional array returned by getValues() then you can just check that it is blank by using a == comparison. 还要假设skuData [i] [6]是getValues()返回的二维数组,那么您可以使用==比较来检查它是否为空白。

// When No RRP
if (skuData[i][6] == "") {
    cell.setValue("=ROUND((F2*1.3),0)-0.01");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM