如何将此Google脚本转换为脱机工作?

时间:2016-03-18 21:07:05

标签: google-chrome google-apps-script google-sheets offline chromebook

我正在尝试使用Chromebook离线漫游时自动输入数据。

我知道谷歌驱动器是离线启用的,而GAS中的独立脚本理论上应该可以解决这个问题,但我不确定如何将各个部分组合在一起。到目前为止,我有以下代码完全在线工作(陷入"运行"离线),我已经安装了GAS应用程序。任何指导将不胜感激!

function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Invoice/Receipt System')
// creates a menu item "Submit Order"
.addItem('Record Invoice', 'menuItem1')
.addToUi();
}


function menuItem1() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var is = ss.getSpreadsheetByName("Template_Invoice");

  var lastID = is.getRange("j6");
  var nextID = is.getRange("j7");

  var lastIDValue = lastID.getValue();

var source = ss.getSpreadsheetByName("Key_Invoice"); 
// sets the 'Key_DailyInput' Sheet as source
var target = ss.geSpreadsheetByName("DataBase_Invoice");
// sets 'Key_DailyInput' sheet as the target for copying data to.
var sourceData = source.getSheetValues(5,1,source.getLastRow(),15);
// sets range to gather source 'Key_DailyInput' data by finding last row, and Line 5 to Column 15
target.getRange(target.getLastRow()+1, 1, sourceData.length,15).setValues(sourceData);
// finds last row of target 'Orders' and writes to +1 row past last row up to column 15 using setValues of sourceData

// Following simply clears DailyInput so new data can be entered
is.getRange('C5:c8').clearContent();
is.getRange('G7:G8').clearContent();
is.getRange('B12:h28').clearContent();
is.getRange('b31:b34').clearContent();


// increases value by +1 so next Sales Order ID is incremented by 1
var cell = is.getRange("j6");
var cellValue = cell.getValue();
cell.setValue(cellValue + 1);

nextID.setValue(lastIDValue + 1);
}

2 个答案:

答案 0 :(得分:1)

简短回答

Google Apps脚本无法脱机运行,因为它们在服务器端运行。

解释

来自https://developers.google.com/apps-script/overview

  

Google Apps脚本是一种基于JavaScript的脚本语言   让您通过Google Apps,Sheets等Google Apps进行新的炫酷工作   和形式。无需安装 - 我们为您提供代码编辑器   在您的浏览器中,您的脚本在Google的服务器上运行。

答案 1 :(得分:0)

如其他答复所述,答案似乎是“否”。但是,在研究过程中,我确实找到了Apps脚本的命令行界面(clasp)来离线管理和编辑项目。我将其张贴在此处,希望对Apps Script开发人员有所帮助。

CLASP Features
Develop Locally. clasp lets you write code on your own computer and upload it to Apps Script via command line when you're done. You can also download existing Apps Script projects and then edit them locally. Once the code is local, you can use your favorite development tools like git to work on Apps Script projects.
*  Manage Deployment Versions. 
*  Create, update, and view multiple deployments of your project.
*  Structure Code. clasp automatically converts your flat project on script.google.com into folders.

您可以在https://developers.google.com/apps-script/guides/clasp上找到有关表扣的更多信息。但是,您还需要使用these instructions在Chromebook上激活Linux(测试版)。