2017-09-15 31 views
1

Googleスプレッドシートにこの機能があります。現在、フィールドに=loadOutposts()と入力してトリガーする必要があります。Googleシートをトリガーしてセルに書き込む機能

私は関数の時間トリガを設定しましたが、私のシートにデータは書き込まれません。私は関数にシートとフィールドを宣言していないからです。どのようにして、そのフィールドに=loadOutposts()と入力することなく、この機能を使ってSheet2 A2にデータを書き込ませることができますか?

Thx!

function loadOutposts(){ 
    var outposts= new Array(); 
    var url = "https://api.eveonline.com/eve/ConquerableStationList.xml.aspx"; 
    var parameters = {method : "get", payload : ""}; 
    var xmlFeed = UrlFetchApp.fetch(url, parameters).getContentText(); 
    var xml = XmlService.parse(xmlFeed); 
    if(xml) { 
    var rows=xml.getRootElement().getChild("result").getChild("rowset").getChildren("row"); 
    for(var i = 0; i < rows.length; i++) { 
     outpost=[rows[i].getAttribute("stationID").getValue(), 
       rows[i].getAttribute("stationName").getValue(), 
       rows[i].getAttribute("stationTypeID").getValue(), 
       rows[i].getAttribute("solarSystemID").getValue(), 
       rows[i].getAttribute("corporationID").getValue(), 
       rows[i].getAttribute("corporationName").getValue() 
       ] 
     outposts.push(outpost); 
    } 
    } 
    return outposts; 
} 

答えて

1

は、以下のスクリプトコードを試してみてください詳細についてはhttps://developers.google.com/apps-script/reference/spreadsheet/sheet#getactivecellを参照してください:

function loadOutposts(){ 
    var outposts= new Array(); 
    var url = "https://api.eveonline.com/eve/ConquerableStationList.xml.aspx"; 
    var parameters = {method : "get", payload : ""}; 
    var xmlFeed = UrlFetchApp.fetch(url, parameters).getContentText(); 
    var xml = XmlService.parse(xmlFeed); 
    if(xml) { 
    var rows=xml.getRootElement().getChild("result").getChild("rowset").getChildren("row"); 
    for(var i = 0; i < rows.length; i++) { 
     outpost=[rows[i].getAttribute("stationID").getValue(), 
       rows[i].getAttribute("stationName").getValue(), 
       rows[i].getAttribute("stationTypeID").getValue(), 
       rows[i].getAttribute("solarSystemID").getValue(), 
       rows[i].getAttribute("corporationID").getValue(), 
       rows[i].getAttribute("corporationName").getValue() 
       ] 
     outposts.push(outpost); 
    } 
    } 
    //return outposts; 
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2').getRange(2,1,outposts.length,outposts[0].length).setValues(outposts); 
}; 
+0

再度ありがとうは;)完璧な作品! – user6079228

+0

あなたはおそらく次の答えを知っていますか: 私はこの機能を再び実行すると、検索した新しいデータでSheet2のすべてのデータを置き換えます。 stationIDとstationTypeIDの組み合わせに基づいて新しいデータが新しい行にあるかどうかを確認し、新しい行をシート2の先頭に追加できますか?したがって、すべてのデータを置き換えるわけではなく、新しい行を追加するだけですか? – user6079228

0

Googleのシートの仕組みにより、機能を実行するタイミングを直接指定する必要があります。

Googleのスクリプトはサーバー側で保持されているため、GoogleシートはExcelなどの機能を実行するイベントを受信できません。

あなたはこのようなもので、選択したセルに渡す関数を呼び出すこと、あなたのシート上のボタンを持つことができます:あなたが移入したいセルを選択する必要があります

function buttonClick() 
{ 
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var sheet = ss.getSheets()[0]; 
    // Returns the active cell 
    var cell = sheet.getActiveCell(); 
    cell.setValue(loadOutposts); 
} 

この方法とボタンをクリックします。

関連する問題