If 和 Else 倒置
If and Else are inverted
我这里有这段代码,但它不知何故颠倒了...
function OnEdit(e) {
const range = e.range;
const sheet = range.getSheet();
if (sheet.getSheetName() != "Formulário" || range.getA1Notation() != "D7" || range.getValue() != "Sucesso do Cliente"){
var url = "https://docs.google.com/spreadsheets/d/1BbuJfPPOSdbvHZ5b8xVTMndeydNfslDhPLm9ftL1pLU/edit?usp=sharing";
const html = `<script>window.open('${url}', '_blank');google.script.host.close();</script>`;
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), "Carregando...");
} else if (sheet.getSheetName() != "Formulário" || range.getA1Notation() != "D7" || range.getValue() != "Faturamento"){
var url = "https://docs.google.com/spreadsheets/d/1o1lKauuBXFTXb2jEEF5t9wAtaYLBPFYu9Y3T_XnO5rk/edit#gid=0";
const html = `<script>window.open('${url}', '_blank');google.script.host.close();</script>`;
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), "Carregando...");
}
}
当单元格 D7 =“Sucesso do Cliente”时,我返回的是 else 中的 url 而不是 If
当单元格 D7 =“Faturamento”时,我返回 If 内的 URL(即“Sucesso do Cliente”的 URL),而不是 url 在 else
里面
这样试试:
function OnEdit(e) {
const sheet = e.range.getSheet();
if (sheet.getSheetName() == "Formulário" && e.range.getA1Notation() == "D7" || e.range.getValue() == "Sucesso do Cliente") {
var url = "https://docs.google.com/spreadsheets/d/1BbuJfPPOSdbvHZ5b8xVTMndeydNfslDhPLm9ftL1pLU/edit?usp=sharing";
const html = `<script>window.open('${url}', '_blank');google.script.host.close();</script>`;
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), "Carregando...");
} else if (sheet.getSheetName() == "Formulário" || e.range.getA1Notation() == "D7" || e.range.getValue() == "Faturamento") {
var url = "https://docs.google.com/spreadsheets/d/1o1lKauuBXFTXb2jEEF5t9wAtaYLBPFYu9Y3T_XnO5rk/edit#gid=0";
const html = `<script>window.open('${url}', '_blank');google.script.host.close();</script>`;
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), "Carregando...");
}
}
您真的必须阅读代码才能弄清楚它在说什么
我这里有这段代码,但它不知何故颠倒了...
function OnEdit(e) {
const range = e.range;
const sheet = range.getSheet();
if (sheet.getSheetName() != "Formulário" || range.getA1Notation() != "D7" || range.getValue() != "Sucesso do Cliente"){
var url = "https://docs.google.com/spreadsheets/d/1BbuJfPPOSdbvHZ5b8xVTMndeydNfslDhPLm9ftL1pLU/edit?usp=sharing";
const html = `<script>window.open('${url}', '_blank');google.script.host.close();</script>`;
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), "Carregando...");
} else if (sheet.getSheetName() != "Formulário" || range.getA1Notation() != "D7" || range.getValue() != "Faturamento"){
var url = "https://docs.google.com/spreadsheets/d/1o1lKauuBXFTXb2jEEF5t9wAtaYLBPFYu9Y3T_XnO5rk/edit#gid=0";
const html = `<script>window.open('${url}', '_blank');google.script.host.close();</script>`;
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), "Carregando...");
}
}
当单元格 D7 =“Sucesso do Cliente”时,我返回的是 else 中的 url 而不是 If
当单元格 D7 =“Faturamento”时,我返回 If 内的 URL(即“Sucesso do Cliente”的 URL),而不是 url 在 else
里面这样试试:
function OnEdit(e) {
const sheet = e.range.getSheet();
if (sheet.getSheetName() == "Formulário" && e.range.getA1Notation() == "D7" || e.range.getValue() == "Sucesso do Cliente") {
var url = "https://docs.google.com/spreadsheets/d/1BbuJfPPOSdbvHZ5b8xVTMndeydNfslDhPLm9ftL1pLU/edit?usp=sharing";
const html = `<script>window.open('${url}', '_blank');google.script.host.close();</script>`;
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), "Carregando...");
} else if (sheet.getSheetName() == "Formulário" || e.range.getA1Notation() == "D7" || e.range.getValue() == "Faturamento") {
var url = "https://docs.google.com/spreadsheets/d/1o1lKauuBXFTXb2jEEF5t9wAtaYLBPFYu9Y3T_XnO5rk/edit#gid=0";
const html = `<script>window.open('${url}', '_blank');google.script.host.close();</script>`;
SpreadsheetApp.getUi().showModalDialog(HtmlService.createHtmlOutput(html), "Carregando...");
}
}
您真的必须阅读代码才能弄清楚它在说什么