
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
업로드한 파일의 '시트1' 시트의 A:H 데이터를 대시보드로 만들려고해 [아래] 항목을 데이터 대시보드로 만들어주는 구글 앱스크립트를 작성해줘 1행은 제외하고 한글로 주석 달아주고 '대시보드' 시트에 기록해줘 [아래] 1. 제품명별 매출 2. 도시별 매출 3. 고객분류별 카테고리별 매출
> 해당 프롬프트 실행 후 아래처럼 결과값이 나왔는데요
// 구글 스프레드시트에서 대시보드를 생성하는 함수
target function createDashboard() {
// 활성 스프레드시트 가져오기
var ss = SpreadsheetApp.getActiveSpreadsheet();
// 원본 데이터 시트 가져오기 ('시트1')
var source = ss.getSheetByName('시트1');
// 대시보드 시트가 없으면 생성, 있으면 가져오기
var dashboard = ss.getSheetByName('대시보드') || ss.insertSheet('대시보드');
// 기존 내용 지우기
dashboard.clearContents();
// 1행(헤더)을 제외하고 A:H 데이터 가져오기
var lastRow = source.getLastRow();
if (lastRow < 2) return; // 데이터 없으면 종료
var data = source.getRange(2, 1, lastRow - 1, 8).getValues();
// 제품명별 매출 합계 계산
var productTotals = {};
// 도시별 매출 합계 계산
var cityTotals = {};
// 고객분류별 카테고리별 매출 합계 계산
var customerCategoryTotals = {};
// 데이터 순회
data.forEach(function(row) {
var product = row[0]; // A열: 제품명
var city = row[1]; // B열: 도시
var customerClass = row[2]; // C열: 고객분류
var category = row[3]; // D열: 카테고리
var sales = parseFloat(row[7]); // H열: 매출
// 제품명별
if (!productTotals[product]) productTotals[product] = 0;
productTotals[product] += sales;
// 도시별
if (!cityTotals[city]) cityTotals[city] = 0;
cityTotals[city] += sales;
// 고객분류별 카테고리별
if (!customerCategoryTotals[customerClass]) {
customerCategoryTotals[customerClass] = {};
}
if (!customerCategoryTotals[customerClass][category]) {
customerCategoryTotals[customerClass][category] = 0;
}
customerCategoryTotals[customerClass][category] += sales;
});
// 출력 시작 행 설정
var rowIndex = 1;
// 1. 제품명별 매출
dashboard.getRange(rowIndex, 1).setValue('제품명별 매출');
dashboard.getRange(rowIndex + 1, 1, 1, 2).setValues([['제품명', '매출']]);
rowIndex += 2;
for (var prod in productTotals) {
dashboard.getRange(rowIndex, 1, 1, 2).setValues([[prod, productTotals[prod]]]);
rowIndex++;
}
// 한 줄 띄우기
rowIndex++;
// 2. 도시별 매출
dashboard.getRange(rowIndex, 1).setValue('도시별 매출');
dashboard.getRange(rowIndex + 1, 1, 1, 2).setValues([['도시', '매출']]);
rowIndex += 2;
for (var ct in cityTotals) {
dashboard.getRange(rowIndex, 1, 1, 2).setValues([[ct, cityTotals[ct]]]);
rowIndex++;
}
// 한 줄 띄우기
rowIndex++;
// 3. 고객분류별 카테고리별 매출
dashboard.getRange(rowIndex, 1).setValue('고객분류별 카테고리별 매출');
dashboard.getRange(rowIndex + 1, 1, 1, 3).setValues([['고객분류', '카테고리', '매출']]);
rowIndex += 2;
for (var cust in customerCategoryTotals) {
var categories = customerCategoryTotals[cust];
for (var cat in categories) {
dashboard.getRange(rowIndex, 1, 1, 3).setValues([[cust, cat, categories[cat]]]);
rowIndex++;
}
}
}
// 스크립트 실행 시 아래 함수를 호출하세요.
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('대시보드')
.addItem('생성하기', 'createDashboard')
.addToUi();
}
강사님 강의에 따라 저장하려고 봤더니 사진처럼 에러가 뜨네요.
프롬프트 그대로 복사붙여넣기했는데 오류가 뜨는 이유가 있을까요?
보고 계신 화면 전체를 캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요

