2017-02-26 100 views
0

我真的需要幫助,從我的網站/本地主機在谷歌應用腳​​本中運行我的功能。從網站/本地主機運行應用腳本功能

已經在google上搜索,結果必須使用google.script.run。當我嘗試它時,我發現google不起作用的錯誤。

這INI我的應用程序的腳本代碼.gs

/** 
* This script demonstrates the use of objDB using a spreadsheet as a database 
* 
* objDB is a Google Script Library that makes it easy to work with data stored in a spreadsheet. 
* Using the same functions, you can also work with data from a JDBC-connected database. 
* See http://googlescripts.harryonline.net/objdb for full documentation 
* 
* This demo uses the spreadsheet template from the tutorial on the Google Apps Script 
* https://developers.google.com/apps-script/storing_data_spreadsheets#reading 
* 
*/ 

/** 
* To restore the data from the original spreadsheet, run getSpreadsheet() 
* Try out the sample function, and create your own. 
* See the results in the log, as well as on the spreadheet itself 
* You can view the log file using View - Logs, or Alt-Enter 
* Alternatively, put breakpoints at the Logger.log statements and use Debug instead of Run 

/** 
* Create a copy of the tutorial spreadsheet and stores the ID of the newly created spreadsheet 
* in Usersettings, so you can continue using this. 
* Restore data from original tutorial spreadsheet 
*/ 

function getSpreadsheet() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheetByName('Tutorial Data'); 
    sheet.clear(); 
    var tutorialID = '0Aq4s9w_HxMs7dFNtWlh2MHRWZzEtbk5LRW5hTVR1Y1E'; 
    var tutorialDataRange = SpreadsheetApp.openById(tutorialID).getSheets()[0].getDataRange(); 
    var range = sheet.getRange(1,1,tutorialDataRange.getNumRows(), tutorialDataRange.getNumColumns()); 
    range.setValues(tutorialDataRange.getValues()); 
} 

/** 
* Sample: get all data from Engineering employees 
*/ 

function getEngineers() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rows = objDB.getRows(ssDB, 'Tutorial Data', [], {Department:'Engineering'}); 
    Logger.log(rows); 
} 

/** 
* Sample: get John's phone number 
* Note that non-alphanumeric characters are stripped from column names: Phone Number becomes PhoneNumber 
*/ 

function getPhone() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rows = objDB.getRows(ssDB, 'Tutorial Data', ['PhoneNumber'], {FirstName:'John'}); 
    Logger.log(rows); 
} 

/** 
* Delete staff with id's 1342 and 1234 
*/ 

function deleteStaff() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rowCount = objDB.deleteRow(ssDB, 'Tutorial Data', {EmployeeId:[1342,1234]}); 
    Logger.log(rowCount); 
} 

/** 
* Update: staff 3512 goes to marketing 
*/ 

function updateStaff() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rowCount = objDB.updateRow(ssDB, 'Tutorial Data', {Department:'Marketing'}, {EmployeeId:3512}); 
    Logger.log(rowCount); 
} 

/** 
* Add new employee 
*/ 

function addStaff() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    ssDB = objDB.open(ss.getId()); 
    var rowCount = objDB.insertRow(ssDB, 'Tutorial Data', {FirstName:'Harry', LastName:'Potter', EmployeeId:4321, Department:'Magic',PhoneNumber:'(212) 123-4567'}); 
    Logger.log(rowCount); 
} 
+1

不應該在您的頁面中包含任何其他.js文件嗎? – NDFA

+0

@BehradKhodayar我的網頁必須包含哪些JavaScript文件? – DeVoresyah

+0

通常,您應該在文檔中包含第三方庫,以便能夠使用它 – NDFA

回答

1

我讀谷歌徹底的App腳本。應用腳本基本上是爲開發人員提供擴展谷歌應用(電子表格,日曆,Gmail,文檔,...)的服務而設計的,他們是由設計預計將位於谷歌雲服務器並運行。

所以,你不能在你的網站/本地主機上運行它們,因爲GS腳本是在服務器端(谷歌服務器)執行的。

唯一建議的方法,is to make an htmlService app and use ajax from the frontend。我認爲這不是你的情況。

+0

還有另一種方法。請參閱[我的回答](http://stackoverflow.com/a/42474052/1595451) –

+0

@Rubén謝謝,但這裏的情況並不涉及API版本(正如我在回答結束時所建議的)。他正試圖將.gs文件上傳到他的主機/本地主機&...。這就是爲什麼我對錯誤的過程謹慎。 – NDFA

+0

不客氣。看起來我並不像你一樣理解問題,另一方面,你的建議與我的不一樣:) –

0

要從外部網頁或服務運行Google Apps腳本,請使用Google Apps Script Execution API。此鏈接包括多種語言的示例,包括但不限於JavaScript,PHP和Python。

相關問題