2014-06-12 46 views
0

我不確定這是否是實現最終結果的正確方法,但我迄今爲止的工作方式如何。我有一個包含多個數據標籤的Google工作表。當我在特定工作表上選擇一個單元格時,我想要啓動一個本地Windows應用程序(例如mstsc.exe/notepad.exe)。我甚至不確定這是否可能,因爲我沒有找到明確的答案。如何通過Google工作表啓動本地應用程序

我已經使用onEdit函數獲取活動工作表名稱和單元格,然後調用一個子函數,根據設置的值爲單元格着色並更新存儲在其他單元格中的時間。代碼減少提取如下: -

function onEdit(){ 
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); 
var cell = sheet.getActiveCell(); 
if(SpreadsheetApp.getActiveSheet().getName() === "Test Sheet"){ 
    if(cell.getColumn() == 3) { //checks the column 
    // change colors to meet your needs 
    ColourCell() 
    } 
} 


function ColourCell(){ 
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); 
var cell = sheet.getActiveCell(); 
    // change colors to meet your needs 
    var status = cell.getValue(); 
    var color; 
    switch(status) { 
    case "COMPLETE": 
     color = "LIME"; 
     sheet.getActiveCell().setBackgroundColor(color); 
     var nextCell = cell.offset(0, 3); 
     var time = new Date(); 
     time = Utilities.formatDate(time, "GMT+1", "HH:mm:ss"); 
     nextCell.setValue(time) 
    break; 
    case "OPEN": 
     color = "RED"; 
     sheet.getActiveCell().setBackgroundColor(color);  
     var nextCell = cell.offset(0, 1); 
     var time = new Date(); 
     time = Utilities.formatDate(time, "GMT+1", "HH:mm:ss"); 
     nextCell.setValue(time) 
    break; 
} 
}; 

我試圖做的就是添加一個進一步的if語句到onEdit功能,那麼這將調用LaunchApp功能如下圖所示

if(SpreadsheetApp.getActiveSheet().getName() === "Test Sheet"){ 
if(cell.getColumn() == 4) { //checks the column 
    // change colors to meet your needs 
    ColourCell() 
} 
if(cell.getColumn() == 1) { //checks the column 
    // launch mstsc and connect to value in cell 
    LaunchApp() 
} 
} 


function LaunchApp(){ 
// WHAT CODE NEEDS TO BE ADDED HERE ???? 
}; 

但我不能計算出LaunchApp函數需要執行的代碼,或者如前所述,即使這是可能的。

任何人都可以給我一些幫助嗎?

謝謝,

回答

1

Google Apps腳本純粹是基於Web的語言。而且它在服務器端執行。因此在本地啓動應用程序是不可能的。

但是,您可以用某種方式標記選定的單元格(顏色,字體等),然後嘗試使用本地安裝的應用程序檢查標記。該應用必須使用Google Drive API,但您可以使用任何常用編程語言編寫它:https://developers.google.com/drive/web/downloads

相關問題