Cyb*_*sKO 4 google-sheets google-apps-script
D 我的脚本有问题。我的脚本的一部分:
var a = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("A");
var b = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("B");
a.getRange("A14").setValue("external File");
Utilities.sleep(2000);
a.getRange("A14:C29").copyTo(b.getRange("A1:C15"), {contentsOnly:true});
a.getRange("A14:C29").clearContent();Run Code Online (Sandbox Code Playgroud)
详细说明@Jack Brown的评论,在对电子表格界面进行写入和读取时,Google Apps 脚本不一定会立即执行写入 - 它会尝试优化对电子表格界面的调用以最小化所需的资源。UsingSpreadsheetApp.flush()指示 Apps 脚本引擎对电子表格执行任何未决更改(写入、由于新写入的数据而计算单元格公式等)。
OP的片段将是:
var a = SpreadsheetApp.getActive().getSheetByName("A");
var b = SpreadsheetApp.getActive().getSheetByName("B");
a.getRange("A14").setValue("external File");
// Force the above value to be written (and any cells that refer to A14 to update).
SpreadsheetApp.flush();
// Without flush(), Apps Script may wait until making these calls to perform the write.
a.getRange("A14:C29").copyTo(b.getRange("A1:C16"), {contentsOnly: true});
a.getRange("A14:C29").clearContent();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1431 次 |
| 最近记录: |