시트를 통합 후 필터링 하는 구문이다.
더보기
function sheets_Filter() {
let wb = SpreadsheetApp.getActiveSpreadsheet(); // wb 선언
let sht = wb.getSheetByName('main'); // sht 선언 (main)
let employee = sht.getRange("F5").getValue();
let item = sht.getRange("g5").getValue();
let shtsE = ['main']
let fx_filter = function(x){return x[0] == employee && x[1] == item;}
let result =[];
let sheets = wb.getSheets(); // 전체 시트 배열
let head;
let first = true;
let data;
for(let i=0; i<sheets.length;i++){
if(shtsE.indexOf(sheets[i].getName()) >= 0) {continue;}; // shtsE 배열에 값이 있다면 / 즉 main 시트이면
data = sheets[i].getRange(1,1).getDataRegion().getDisplayValues();
if (first) { head = data[0]; first = false;}; // main시트가 아닌 첫번째 시트이면
data.shift(); // 배열의 맨 처음 값 삭제 / 두번째 부터는 헤드값 삭제
result = result.concat(data);
}
result = result.filter(fx_filter);
sht.getRange(1,1).getDataRegion().clear(); // 기존 데이터 삭제
result.unshift(head); // 배열의 맨 앞에 값 추가
sht.getRange(1,1,result.length, result[0].length).setValues(result);
}
https://docs.google.com/spreadsheets/d/1s5jSNL8CVRZIFG5XQOOdwFbbsX1wPIBWUuLk8lAUo8I/edit?usp=sharing
시트통합매크로
main Employee,Item,SelDate,Price EEE,Mouse,2023-12-12,40,000 EEE,Mouse,2023-02-17,30,000 EEE,Mouse,2023-06-11,60,000,Employee,item EEE,Mouse,2023-01-09,90,000,EEE,Mouse EEE,Mouse,2023-06-21,40,000 EEE,Mouse,2023-01-26,20,000 EEE,Mouse,2023-07-20,90,000 EEE
docs.google.com
'GAS' 카테고리의 다른 글
[GAS] sheets데이터를 html 문서를 작성해보자 (0) | 2023.04.19 |
---|---|
[GAS] 중복없는 로또번호 만들기 (0) | 2023.04.17 |
[GAS] 시트통합 매크로 (0) | 2023.04.03 |
[GAS] VBA 기초방 #9 [ 데이터 영역 선택하기 ] (0) | 2023.01.08 |
[GAS] `I'm ${name}` (0) | 2022.12.27 |
댓글