일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- matplotlib
- Apache
- google apps script
- c#
- Github
- django
- list
- string
- Tkinter
- PostgreSQL
- numpy
- Google Spreadsheet
- SQL
- Java
- GIT
- Redshift
- gas
- PANDAS
- Google Excel
- math
- Excel
- array
- PySpark
- Python
- Kotlin
- dataframe
- 파이썬
- Mac
- hive
- Today
- Total
달나라 노트
Google Apps Script : setDataValidation (Google Spreadsheet에 체크박스 만들기) 본문
Google Apps Script : setDataValidation (Google Spreadsheet에 체크박스 만들기)
CosmosProject 2021. 8. 6. 13:34


Google Spreadsheet에선 위처럼 셀 안에 체크박스를 만들 수 있습니다.
체크를 안한 경우에는 X, 체크 한 경우에는 O라고 값이 떠있는걸 볼수있죠.
저 체크박스 만드는 것을 코드로 구현해봅시다.
function myFunction() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet1'));
spreadsheet.getRange('B2').activate();
spreadsheet.getActiveRange().setDataValidation(SpreadsheetApp.newDataValidation().requireCheckbox('O', 'X').build());
}
- var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
active spreadsheet 객체를 얻어옵니다.
- spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet1'));
Sheet1에 있는 데이터에서 테스트를 할 것이므로 Sheet1을 activate합니다.
- spreadsheet.getRange('B2').activate();
B2 셀을 activate합니다.
- spreadsheet.getActiveRange().setDataValidation(SpreadsheetApp.newDataValidation().requireCheckbox('O', 'X').build());
getActiveRange() = 현재 active rnage(B2 cell)을 얻어옵니다.
setDataValidation = 여기서 Validation(check box)를 만들거고 check box의 옵션을 setDataValidation의 인자로 전달할것입니다.
SpreadsheetApp.newDataValidation() = 새로운 Data Validation을 만든다는 것입니다.
requireCheckbox('O', 'X') = check box가 체크되었을 때는 O, 체크 해제되었을 때는 X라는 값을 가지게 합니다.
build() = check box를 만듭니다.


코드 실행의 결과입니다.
원하는대로 체크박스가 생성된 것을 볼 수 있죠.
function myFunction() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Sheet1'));
spreadsheet.getRange('B2:C5').activate();
spreadsheet.getActiveRange().setDataValidation(SpreadsheetApp.newDataValidation().requireCheckbox('O', 'X').build());
}
위처럼 Cell의 범위를 선택하여 check box를 설정할 수도 있습니다.

결과는 위와 같으며 B2:C5 범위에 체크박스가 생성된 것을 볼 수 있습니다.