0
我試圖使用Google腳本每小時從網站下載數據。代碼如下所示。當我手動運行函數CSV_sgj時,我可以通過電子郵件收到所需的信息。但是,當我將函數設置爲時間驅動(每小時)時,我得到的都是#VALUE !.Google腳本中時間驅動的函數
我發現了一個類似的問題,並試圖改變
var sheet = SpreadsheetApp.getActiveSheet();
到
var sheet = SpreadsheetApp.openById("0AtAYfCLk3-h7dDBnckdSZkNXbkZBLXBHV200SGtuZnc");
,但它仍然無法正常工作。
非常感謝您的幫助!
完整代碼如下。
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
Logger.log(row);
}
};
/**
* Adds a custom menu to the active spreadsheet, containing a single menu item
* for invoking the readRows() function specified above.
* The onOpen() function, when defined, is automatically invoked whenever the
* spreadsheet is opened.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function CSV_sgj() {
readRows();
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:N32");
var data = range.getValues();
var csv = "";
for (var i = 0; i < data.length; ++i) {
csv += data[i].join(",") + "\r\n";
}
var csvFiles = [{fileName:"PSI5.csv", content:csv}]
MailApp.sendEmail("[email protected]", "CSV", "", {attachments: csvFiles});
}
嗨Serge insas!非常感謝您的幫助!有用! – user2230101