const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
// 헤더
const headers = ['부서', '이름', '매출(만원)', '달성률(%)'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#1565C0').foreColor('#fff').font('bold 12px sans-serif');
sheet.setColumnWidth(c, c === 1 ? 80 : 110);
});
sheet.setRowHeight(0, 36);
// 샘플 데이터
const data = [
['영업1팀', '김민준', 4800, 96],
['영업2팀', '이서연', 5300, 106],
['영업1팀', '박지호', 3200, 64],
['영업3팀', '최유진', 6100, 122],
['영업2팀', '정수민', 4100, 82],
['영업3팀', '윤채원', 5700, 114],
['영업1팀', '강도현', 2900, 58],
];
data.forEach((row, r) => {
row.forEach((v, c) => sheet.setValue(r + 1, c, v));
const rate = row[3];
const bg = rate >= 100 ? '#E8F5E9' : rate >= 80 ? '#FFF8E1' : '#FFEBEE';
for (let c = 0; c < 4; c++) sheet.getCell(r + 1, c).backColor(bg);
});
sheet.setRowHeight(8, 4);
// SUMIF + 동적 배열 수식 결과 표시 영역
sheet.setValue(9, 0, '영업1팀 합계');
sheet.setValue(9, 1, '매출 목표 달성(100%↑) 인원');
sheet.getCell(9, 0).font('bold 12px sans-serif').backColor('#F5F5F5');
sheet.getCell(9, 1).font('bold 12px sans-serif').backColor('#F5F5F5');
sheet.setColumnWidth(1, 200);
// SpreadJS 수식 엔진: SUMIF + COUNTIF
sheet.setFormula(9, 2, '=SUMIF(A2:A8,"영업1팀",C2:C8)');
sheet.setFormula(9, 3, '=COUNTIF(D2:D8,">=100")');
sheet.getCell(9, 2).formatter('0"만원"').font('bold 12px sans-serif').foreColor('#1565C0');
sheet.getCell(9, 3).formatter('0"명"').font('bold 12px sans-serif').foreColor('#1565C0');
sheet.setRowHeight(9, 36);