简体   繁体   中英

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). So when I upload the file, some products end up with a price of $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. Column F has the cost price in the original spreadsheet or skuData[i][5] I guess.

// 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

Assuming that cell is a Range there is a setFormula function that you can use. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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