performance - Google Scripts - 使用 For 循环进行数据映射加载数据非常慢
问题描述
我对谷歌脚本相当陌生。我一直在从 VBA 翻译一个人的代码来为我的属性编写我自己的数据库。目标是将属性数据存储在属性数据库表上,并拥有另一个“摘要表”,允许我查看选定属性的数据,对其进行编辑并将其更新到数据库中。
我通过将汇总表中的单元格 a1Notation 放在数据库表中相应单元格的上方来使用数据映射。我使用for Loop将数据库表中所选属性数据加载到摘要表中,该摘要表在选择属性时使用ONEDIT执行。问题是它太慢了。见下文。我能做些什么来加快速度吗?谢谢!
定义:
var PropRow, PropCol, PropID
var app = SpreadsheetApp;
var activeSheet = app.getActiveSpreadsheet(); //Get current active spreadsheet
var sheetProp = activeSheet.getSheetByName('Properties');
var sheetPropDB = activeSheet.getSheetByName('PropDB');
将属性数据从属性数据库 (sheetPropDB) 加载到汇总表 (sheetProp)。这是非常慢的部分:
function Property_Load(){
sheetProp.activate();
PropRow = sheetProp.getRange('B7').getValue();
for(PropCol = 3; PropCol<43; PropCol++){
var dataLOC = sheetPropDB.getRange(2,PropCol).getValue(); // gets data mapping cell addresses from PropDB tab
var dataVAL = sheetPropDB.getRange(PropRow,PropCol).getValue(); //gets values of cells in PropDB sheet located at the selected properties PropRow and for each PropCol
var dataPASTE = sheetProp.getRange(dataLOC); // highlights the cells on the Property tab given by the addresses in dataLOC
dataPASTE.setValue(dataVAL); // pastes the values from the propDB selected property row into the specified cells of the property tab
}
}
解决方案
推荐阅读
- python - 我应该在我的 Git 存储库中还是在专用的父目录中运行“pip install -r requirements.txt”?
- selenium-webdriver - selenium 有没有办法用动态名称上传最后下载的文件?
- vue.js - 当我尝试控制台日志时,vue axios 返回意外的控制台语句
- python - Web Scraping (Python) 多请求运行时间太慢
- r - 多选所有按钮导致闪亮地图中的交互性问题
- caching - 使用 Redis Pub/Sub 将数据持久化到 RDBMS
- angular - 如何刷新Angular中函数返回的参数
- python - 如果它不是空白、NaN 或空,还有什么可能?
- php - 为什么 php 在尝试连接到本地套接字服务器时会挂起?
- rust - 如何在 Rust 中使用返回类型为 impl trait 的 Fn 特征?