English 中文(简体)
触发功能发送电子邮件前有些电子表格单元格没有更新
原标题:Some spreadsheet cells not updated before trigger function sends email

我有一个电子表格,用Vmerge和Query公式从其他6个电子表格中提取和积累所有所需数据,所有合并数据将转换为pdf,并使用触发事件邮寄到邮件代号。

每次张贴的附件邮件包含所有信头和其他格式, 但提取的数据没有出现。 似乎 < code> - 将打开相同的电子表格, 之后所有 < code>- (连字符) 将被数据/ 希望所有数据在打开电子表格一段时间后更新 。

link

"https://i.sstatic.net/ioY1i.png" alt="scrapot"/ >

任何人都可以指示我 解决这个问题。

此解决方案应该是 - & gt; 所有数据都应该更新, 然后电子邮件脚本应该工作; 或者要么在电子邮件脚本启动前更新 。

或任何其他更好的想法都会受到赞赏。

最佳回答

一些电子表格公式,例如importRange importXml (以及Apps Script自定义公式),仅在电子表格中登录某人时才被评估。这些函数似乎需要从 importRange 等账户中评估一个账户,如果与某人共享这个电子表格,而不是 importRange 源,当这个人查看这个电子表格时,这些函数将无效(除非您在电子表格中重新填写,且公式已经评估过) 。

底线是,您不能拥有此公式,而使用时间驱动触发的脚本(或其他不要求某人登录的触发器),并期望脚本能够读取这些数据。

工作变通很简单。 执行您脚本中的 < code> importRange 函数 。 例如 。

var source = SpreadsheetApp.openById( source-spreadsheet-key );
var data = source.getSheetByName( List ).getRange( I6:AT500 ).getValues();
//then save it somewhere
var s = Spreadsheet.getActive().getSheetByName( hidden-import );
s.getRange( I6:AT500 ).setValues(data);
SpreadsheetApp.flush(); //force the data to be written
//so all the other formulas on your spreadsheet get updated with the new data

您的所有“ logic” 公式, 如 < code> query 和 < code> vmerge , 对脚本难以模仿, 可以留在电子表格中, 但请直接引用我刚刚发明的“ 隐藏- 进口” 表格, 而不是嵌入 < code > importRange

<强> [编辑]

只复制非空行会这样 :

var data = SpreadsheetApp.openById( source-spreadsheet-key ).
  getSheetByName( List ).getDataRange().getValues();
Spreadsheet.getActive().getSheetByName( hidden-import ).
  getRange(1,1,data.length,data[0].length).setValues(data);
问题回答

暂无回答




相关问题
How to use year counter google app script?

I need an urgent help i have data as follows in a google sheet i need to add a year counter to the column d as follows using google apps script

Google Spreadsheet multiple column filter using OR

I have a Google Spreadsheet with 3 columns that are either blank or have a value. I want to get the count of the number of rows that has A and either B or C populated. If I were writing a SQL query ...

Run Google Apps Script on Google-Spreadsheet event?

If I create a Google apps script, can I hook it up to Google spreadsheet to run based on an event, or must I manually invoke it? I don t know if Google Sheets supports any events. For example: a ...

How do I insert a row in to a Google spreadsheet using c#

I ve seen; Accessing Google Spreadsheets with C# using Google Data API and http://code.google.com/apis/spreadsheets/data/2.0/developers_guide_dotnet.html#CreatingRows However i m still having ...

using Zend_Gdata_Spreadsheets for public spreadsheets?

I have this code which is working, to load a Google Spreadsheet and load some data from it. If the spreadsheet in question is public, how do i modify the code to not require a username/password? $key=...

Programatically updating a Google spreadsheet

I ve got a pre-existing Google spreadsheet. Each month I update this document. I ve got a template workseet in the spreadseet that I d like to clone and then update. I d prefer to clone the ...

热门标签