我有一個產品表,A 列有產品代碼,C 列有英鎊價格,D 列有歐元價格。在報價單上,當我在 A 列輸入產品代碼并在 c 列輸入貨幣時,我需要代碼從產品表中的相應貨幣列中獲取價格值。我撰寫的代碼可以從產品表中獲取價格值,但我無法獲取代碼以根據貨幣選擇正確的價格值。有人可以幫忙嗎?謝謝
function updateData(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var quotationsSheet = ss.getSheetByName('QUOTATION');
var productSheet = ss.getSheetByName("PRODUCTS");
var lastProd = productSheet.getLastRow();
var priceList = productSheet.getRange(2,1,lastProd,4).getValues();
var drg = quotationsSheet.getRange(2, 1, quotationsSheet.getLastRow() - 1, 4);
var newPrice = quotationsSheet.getLastRow();
quotationsSheet.getRange(newPrice,2).setValue("Not found");
var code = quotationsSheet.getRange(newPrice,1).getValue();
var vs = drg.getValues();
vs.forEach((r,j) => {
let currency = r[2];
for (j = 0;j <priceList.length;j ){
if (priceList[j][0] == code && currency !='STERLING' ){
var description = priceList[j][1];
var price = priceList[j][2];
if (priceList[j][0] == code && currency !='EURO' )
var description = priceList[j][1];
var price = priceList[j][3];
quotationsSheet.getRange(newPrice,12).setValue(description)
quotationsSheet.getRange(newPrice,13).setValue(price)
}
}
});}
uj5u.com熱心網友回復:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var quotationsSheet = ss.getSheetByName('QUOTATION');
var productsSheet = ss.getSheetByName("PRODUCTS");
var lastprod = productsSheet.getLastRow();
var productList = productsSheet.getRange(2,1,lastprod,4).getValues();
var currencyType = quotationsSheet.getLastRow();
var ct = quotationsSheet.getRange(currencyType,3,1,4);
var gs = ct.getValue();
var ge = ct.getValue();
var newProd = quotationsSheet.getLastRow();
quotationsSheet.getRange(newProd,2).setValue("Not found");
var code = quotationsSheet.getRange(newProd,1).getValue();
for (j = 0;j <productList.length;j ){
//for (i = 0;i <gs.length;i )
if (productList[j][0] == code && gs == 'STERLING'){
var description = productList[j][1];
var price = productList[j][2];
quotationsSheet.getRange(newProd,6).setValue(description)
quotationsSheet.getRange(newProd,7).setValue(price)
} }
for (j = 0;j <productList.length;j )
if (productList[j][0] == code && ge == 'EURO'){
var description = productList[j][1];
var price = productList[j][3];
quotationsSheet.getRange(newProd,6).setValue(description)
quotationsSheet.getRange(newProd,7).setValue(price)
}
}```
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/379795.html
上一篇:Apps腳本:如何使用令牌
