如何插入参数

问题描述

我需要在其中插入一个参数:

row: workbook.getWorksheet("VittorioZigiotto").getRange("VittorioZigiotto[237]:Vittorioigiotto[241]")

参数需要在现在有“237”的地方,并且需要依赖于工作簿中的一个单元格。例如,MONEYPAGE1!A1+5。有什么想法吗?

解决方法

您可以通过执行以下操作从 MONEYPAGE!A1 中获取您想要的值而不是 237:

const valueFromMPA1 = workbook.getWorksheet("MONEYPAGE").getRange("A1").getValue(); // use getValue for convenience since it's a single cell
const rowString = `VittorioZigiotto[${valueFromMPA1}]:VittorioZigiotto[${valueFromMPA1 + 5}]`; // this is a js/ts way to construct strings with params
// and then pass that in as the argument ...
const row = workbook.getWorksheet("VittorioZigiotto").getRange(rowString);

我不确定您的确切情况,但也可以看看 .getRangeByIndexes(而不是 getRange),它允许您传递数字行/列值,而不必构造字符串参数。