我们可以在电子表格的 Google 应用程序脚本中调用函数 "Show formulas"
Can we call the function "Show formulas" in Google app script for Spreadsheet
我目前正在为 google 电子表格编写脚本。此脚本将两个工作表放在一起进行比较,并根据这些工作表之间的差异应用更改。首先,我从工作表中获取数据并将它们放入 array 然后我比较它们并应用更改,然后将它们粘贴到原始工作表上。
我的问题是有公式填充了我工作表的一些单元格。但是,当我 运行 我的脚本时,它只读取出现在单元格中的数据,因此一旦脚本完成,公式就会被删除。但是我想将这些公式保留在我的工作表上..
为了解决问题,我在启动脚本之前 "show formulas" (Ctrl + `),因此脚本读取的是公式而不是单元格的值。
我想从我的 google 脚本中调用这个函数 "Show Formulas" (Ctrl + `),可以吗?如果是,如何?
提前谢谢你,
维克多
是的,这是可能的。
例如,您可以使用 getFormulas()
, and later on, when you paste the data into the destination sheet: setFormulas()
而不是 getValues()
另一种可能性是将数据复制粘贴到临时 sheet 和 copyTo(destination, copyPasteType, transposed)
chosing the copyPasteType PASTE_FORMULA
您也可以使用 Advanced Sheets Service and retrieve and set values with the valueRenderOption FORMULA
我目前正在为 google 电子表格编写脚本。此脚本将两个工作表放在一起进行比较,并根据这些工作表之间的差异应用更改。首先,我从工作表中获取数据并将它们放入 array 然后我比较它们并应用更改,然后将它们粘贴到原始工作表上。
我的问题是有公式填充了我工作表的一些单元格。但是,当我 运行 我的脚本时,它只读取出现在单元格中的数据,因此一旦脚本完成,公式就会被删除。但是我想将这些公式保留在我的工作表上..
为了解决问题,我在启动脚本之前 "show formulas" (Ctrl + `),因此脚本读取的是公式而不是单元格的值。
我想从我的 google 脚本中调用这个函数 "Show Formulas" (Ctrl + `),可以吗?如果是,如何?
提前谢谢你,
维克多
是的,这是可能的。
例如,您可以使用
getFormulas()
, and later on, when you paste the data into the destination sheet:setFormulas()
而不是 另一种可能性是将数据复制粘贴到临时 sheet 和
copyTo(destination, copyPasteType, transposed)
chosing the copyPasteTypePASTE_FORMULA
您也可以使用 Advanced Sheets Service and retrieve and set values with the valueRenderOption
FORMULA
getValues()