URL에서 데이터를 가져 와서 기존 스프레드 시트의 시트에 쓰려고하는 짧은 스크립트가 있습니다. 다음과 같이 스크립트입니다 :스프레드 시트에 문자열로 구분 된 텍스트 쓰기
function urlDataImport() {
var input = "https://reports.acc-q-data.com/clientreports/ecaldwell_201206192722/ecaldwell_20122722.txt";
// The code below gets the HTML code.
var response = UrlFetchApp.fetch(input);
var data = response.getContentText();
Logger.log(data);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ptSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("pt");
ptSheet.getActiveRange().setValues(data);
}
데이터의 정보 탭으로 구분하고 로그에 제대로 표시되지만이 문자열이기 때문에 내가 시트 PT에 기입 할 .setValues을 사용할 수 없습니다 다른 방법으로 URL에서 정보를 얻는 방법을 모르겠습니다.
이 질문의 초보적인 특성으로 인해 불편을 끼쳐 드려 죄송합니다. 스크립트 작성에 익숙하지 않으므로 도움을 받으실 수 있습니다.
업데이트 된 코드 :
function ptDataImport() {
var input = "https://reports.acc-q-data.com/clientreports/ecaldwell_201206192722/ecaldwell_2012062.txt";
var response = UrlFetchApp.fetch(input); // Get the data from the URL as an object.
var data = response.getContentText(); // Convet the object to text
var dataSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("pt"); // Get the sheet to write the data to
var rows = data.split('\n'); // Splits the text into rows
dataSheet.clear();
var dataSet = new Array();
for (var i in rows){
dataSet[i] = rows[i].split('\t'); // Split the rows into individual fields and add them to the 2d array
}
dataSet.pop(); // Had a blank row at the bottom that was giving me an error when trying to set the range - need to make this conditional somehow
var numColumns = dataSet[0].length;
var numRows = dataSet.length;
var lastRow = dataSet[(numRows -1)];
dataSheet.getRange(1,1,numRows,numColumns).setValues(dataSet); // Get a range the size of the data and set the values
}
위의 코드는 위의 튜토리얼의 기능보다 훨씬 뛰어났습니다. 나는 여전히 스크립트 시간에 문제가있다. (비록 스프레드 시트를 빠져 나가서 데이터를 다시 열어 본다면 모든 것이 실제로 마비된다.)이 스크립트는 내 스크립트에 문제가있다. 시트에 2000 행? 위의 원래 질문에 업데이트 된 스크립트를 게시했습니다. –
시간 초과를 방지하려면 전체 시트에 대해 2D 배열을 준비한 다음 모든 행에 대해 수행하지 말고 한 번에 setValues ()를 사용합니다. 이것은 훨씬 더 빠를 것입니다. – Srik
업데이트를 얻으려면 약간 시간이 걸리지 만 제대로 작동해야합니다. 업데이트 된 코드를 게시하십시오. 도와 줘서 고마워. –