我如何使谷歌脚本忽略空单元格?



我们有一个将项目上传到数据库的脚本。脚本如何忽略空白的单元格?

//furnitureVariantOptions var furnitureVariantOptions = []; if (dr.getCell(i, 8).getValue() != "") { woodTypes = dr.getCell(i, 8).getValue().split(","); var items = []; woodTypes.forEach(item => { items.push({ "value": item.trim() }); })
var woodTypesObject = {
"name": "Wood types",
"values": items
};
furnitureVariantOptions.push(woodTypesObject);
}
if (dr.getCell(i, 9).getValue() != "") { fabricTypes = dr.getCell(i, 9).getValue().split(","); fItems = []; fabricTypes.forEach(item => { fItems.push({ "value": item.trim() }); })
var fabricTypesObject = {
"name": "Fabrics",
"values": fItems
};
furnitureVariantOptions.push(fabricTypesObject);
}
if (dr.getCell(i, 10).getValue() != "") { sizeTypes = dr.getCell(i, 10).getValue().split(","); var sizeItems = []; sizeTypes.forEach(item => { sizeItems.push({ "value": item.trim() }); })
var sizeTypesObject = {
"name": "Sizes",
"values": sizeItems
};
furnitureVariantOptions.push(sizeTypesObject);
}

有时变量只是木材类型,因此织物和尺寸是空的,我们希望脚本忽略它们的单元格,只读取那些有值的。

function myfunk() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet0");
const vs = sh.getDataRange().getValues();
vs.forEach(r => {
//checks to see if column one is empty
if(r[0] === '') {
Logger.log("column A is null");
}
});

相关内容

最新更新