const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
// 분기별 매출 데이터
const headers = ['구분', '1분기', '2분기', '3분기', '4분기', '합계'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#37474F').foreColor('#ffffff').font('bold 12px sans-serif');
sheet.setColumnWidth(c, c === 0 ? 80 : 85);
});
sheet.setRowHeight(0, 34);
const sales = [
['제품 A', 12500, 14200, 13800, 16900],
['제품 B', 9800, 10500, 11200, 12300],
['제품 C', 7300, 8100, 7600, 9200],
];
sales.forEach((row, r) => {
row.forEach((val, c) => sheet.setValue(r + 1, c, val));
// 그리드에서는 서버 계산이 필요했던 합계 — SpreadJS는 클라이언트 수식으로 즉시 처리
sheet.setFormula(r + 1, 5, `=SUM(B${r + 2}:E${r + 2})`);
});
for (let r = 1; r <= 3; r++) {
for (let c = 1; c <= 5; c++) {
sheet.getCell(r, c).formatter('#,##0');
}
}
sheet.setValue(4, 0, '← 1~3행 매출 셀을 수정하면 CellChanged 이벤트가 감지됩니다');
sheet.getCell(4, 0).foreColor('#9E9E9E').font('italic 11px sans-serif');
// IBSheet onAfterChange → SpreadJS CellChanged
sheet.bind(GC.Spread.Sheets.Events.CellChanged, function(e, info) {
if (info.propertyName === 'value'
&& info.row >= 1 && info.row <= 3
&& info.col >= 1 && info.col <= 4) {
const val = sheet.getValue(info.row, info.col);
sheet.setValue(4, 0,
`✔ 셀(${info.row}행, ${info.col}열) 변경 감지 — 합계 자동 갱신: ${(val || 0).toLocaleString()}원 입력`
);
sheet.getCell(4, 0).backColor('#FFF9C4').foreColor('#F57F17').font('italic 11px sans-serif');
}
});