주 컨텐츠로 이동
Adaptive Planning
최종 업데이트: 2023-06-23
참조: CCDS Script Example Google Sheets

참조: CCDS Script Example Google Sheets

Prerequisites

Google 드라이브에 연결하려면 몇 가지 예비 단계가 필요합니다.
  1. Google 드라이브로 이동합니다.
  2. 새로 만들기
    를 선택하고
    파일 업로드
    를 선택하여
    csv 파일을 Google 드라이브에 업로드합니다. 예:CCDS Demo.csv
  3. 업로드된 파일을 마우스 오른쪽 버튼으로 클릭하고
    공유
    를 선택합니다.
  4. 사용자 및 그룹과 공유
    창에서 공유 설정을 '
    링크가 있는 모든 사용자에게 공개
    '로 지정합니다.
  5. 공유된 링크에서 Google 문서 ID를 가져옵니다. 예: 샘플 URL
    https://drive.google.com/file/d/1QZYX2345ri6789/view?usp=sharing
    , 파일 ID:
    1QZYX2345ri6789
  6. 스크립트의 파일 ID를 사용합니다. 예:
    var url = 'https://drive.google.com/uc?export=downloade&id=ENTER_FILE_ID_HERE';

Google Sheets 샘플 스크립트

var tableName = 'Csv Example'; //Make sure you adjust the settings to allow people to download this file from your google drive var url = 'https://drive.google.com/uc?export=downloade&id=ENTER_FILE_ID_HERE'; /* Example cvs file: ---------------------------------------------- Heading A,Heading B,Heading C A1,B1,C1 A2,B2,C2 A3,B3,C3 ---------------------------------------------- */ //Create an HTTPS request to send to the Google Drive API using the callApi function. function callApi() { var method = 'GET'; var body = ''; var headers = null; //Construct and send an HTTPS request to get all of the tables. return ai.https.request(url, method, body, headers); } function testConnection(context) { var response = callApi(); var responseCode = response.getHttpCode(); // Interrogate the response to check if it succeeded and that HTTP communication was successful. if (responseCode == 200) { ai.log.logInfo('Test Connection Succeeded'); return true; } else { ai.log.logError('Test Connection Failed','Response code was ' + responseCode); return false; } } function importStructure(context) { //Use the callAPI function to construct and send an HTTPS request to get all the tables var response = callApi(); //Get the structure builder object used to create tables, columns and other needed structures. var builder = context.getStructureBuilder(); var table = createTable(builder, tableName); var lines = extractLines(response); var headingLine = lines[0]; var headings = extractCells(headingLine); //parse the HTTPS response to construct a table for(var i = 0; i < headings.length; i++) { var heading = headings[i]; createColumn(table, heading); } } function importData(context) { var response = callApi(); //Use the passed-in contextual information to create a rowset object. var rowset = context.getRowset(); var lines = extractLines(response); //Skip the heading row and process each row to extract cell values for each column. for(var i = 1; i < lines.length; i++) { var line = lines[i]; if(line === '') continue; var cells = extractCells(line); //Add each row array to the rowset. rowset.addRow(cells); } } function createColumn(table, heading) { var columnId = escape(heading); var column = table.addColumn(columnId); column.setDisplayName(heading); column.setTextColumnType(1000); } function extractLines(response) { var content = response.getBody(); return content.split('\n'); } function extractCells(line) { return line.split(','); } function createTable(builder, name) { var tableId = escape(name); var table = builder.addTable(tableId); table.setDisplayName(name); return table; } //In this example, reuse the import data function with context for previewing the data. //A separate function might be needed to limit the amount of data preview gets back. function previewData(context) { importData(context); }