๋ฐ์ํ
๐ก Apps Script๋ก Google Sheets์์ ํํฐ๋ฅผ ์์ฑํ๊ณ , ์กฐ๊ฑด์ ์ ์ฉํด ๋ณธ๋ค.
๋์๊ฐ ํํฐ ์กฐ๊ฑด์ด ์ ์ฉ๋ ๋ฐ์ดํฐ๋ฅผ ์๋ก์ด ์ํธ๋ก ์ถ์ถํด๋ณธ๋ค.
์๋์ ๊ฐ์ ๋ฐ์ดํฐ๊ฐ ์๋ค.
ํํฐ ์์ฑํ๊ธฐ
function createFilters() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("tempature_all");
const range = sheet.getRange("A:E");
range.createFilter();
}
ํํฐ ์ญ์ ํ๊ธฐ
function createFilters() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("tempature_all");
const range = sheet.getRange("A:E");
const getFilter = range.getFilter();
getFilter.remove();
}
ํํฐ๋ก ์ผ์นํ๋ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
country ๊ฐ ‘KR’์ธ ๋ฐ์ดํฐ๋ง ์ถ์ถํ๋ค.
function createFilters() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("tempature_all");
const range = sheet.getRange("A:E");
const getFilter = range.getFilter();
if ( getFilter == null ) {
const newFilter = range.createFilter();
const coll1 = 1;
const Filter_Criteria1 = SpreadsheetApp.newFilterCriteria().whenTextContains(["KR"]);
newFilter.setColumnFilterCriteria(coll1,Filter_Criteria1);
} else {
getFilter.remove();
}
}
์ค๋ณต ํํฐ ์ ์ฉ
country ๊ฐ ‘KR’์ธ ๋ฐ์ดํฐ๋ง ์ถ์ถํ๋ค.
temperature_air_avg_avg ๊ฐ 50์ ์ด๊ณผํ๋ ๋ฐ์ดํฐ๋ง ์ถ์ถํ๋ค.
function createFilters() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("tempature_all");
const range = sheet.getRange("A:E");
const getFilter = range.getFilter();
if ( getFilter == null ) {
const newFilter = range.createFilter();
const coll1 = 1;
const Filter_Criteria1 = SpreadsheetApp.newFilterCriteria().whenTextContains(["KR"]);
newFilter.setColumnFilterCriteria(coll1,Filter_Criteria1);
const coll3 = 3;
const Filter_Criteria3 = SpreadsheetApp.newFilterCriteria().whenNumberGreaterThan(50);
newFilter.setColumnFilterCriteria(coll3,Filter_Criteria3);
} else {
getFilter.remove();
}
}
์ถ์ถํ ๋ฐ์ดํฐ๋ฅผ ์๋ก์ด sheet ๋ก ์ ์ฅํ๋ค.
ํํฐ๋ก ์ถ์ถ๋ ๋ฐ์ดํฐ๋ฅผ ์๋ก์ด sheet์ ์ ์ฅํ๊ณ ,
์์ฑํ ํํฐ๋ ์ ๊ฑฐํ๋ค.
function createFilters() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("tempature_all");
const range = sheet.getRange("A:E");
const getFilter = range.getFilter();
if ( getFilter == null ) {
const newFilter = range.createFilter();
const coll1 = 1;
const Filter_Criteria1 = SpreadsheetApp.newFilterCriteria().whenTextContains(["KR"]);
newFilter.setColumnFilterCriteria(coll1,Filter_Criteria1);
const coll3 = 3;
const Filter_Criteria3 = SpreadsheetApp.newFilterCriteria().whenNumberGreaterThan(50);
newFilter.setColumnFilterCriteria(coll3,Filter_Criteria3);
const newSheet = ss.insertSheet();
newSheet.setName("KR_Data");
range.copyTo(newSheet.getRange(1,1));
newFilter.remove();
} else {
getFilter.remove();
}
}
์ด ์์ ์
๋ฐ์ดํฐ๋ฅผ ์กฐํ ํ๊ณ , ํน์ ์กฐ๊ฑด์ ์ง์์ ์ผ๋ก ์ถ์ถํด์ผ ํ ๋
์ฌ์ฉํ๋ฉด ์ข์๊ฒ ๊ฐ๋ค.
๋ฐ์ํ