const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
const headers = ['부서', '직원명', '1분기', '2분기', '3분기', '합계'];
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 < 2 ? 90 : 80);
});
sheet.setRowHeight(0, 36);
const data = [
['영업팀', '김민준', 820, 910, 880, 2610],
['영업팀', '이서연', 760, 840, 790, 2390],
['개발팀', '박지호', 640, 720, 810, 2170],
['개발팀', '최유진', 700, 680, 760, 2140],
['마케팅', '정수민', 560, 620, 590, 1770],
];
function loadData() {
data.forEach((row, r) => {
row.forEach((val, c) => sheet.setValue(r + 1, c, val));
});
const ranges = [new GC.Spread.Sheets.Range(1, 5, data.length, 1)];
const goodStyle = new GC.Spread.Sheets.Style();
goodStyle.backColor = '#E8F5E9';
goodStyle.foreColor = '#2E7D32';
sheet.conditionalFormats.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan,
2400, 0, goodStyle, ranges
);
const warnStyle = new GC.Spread.Sheets.Style();
warnStyle.backColor = '#FFF3E0';
warnStyle.foreColor = '#E65100';
sheet.conditionalFormats.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.lessThan,
2000, 0, warnStyle, ranges
);
}
// jspreadsheet onchange 콜백 → SpreadJS CellChanged 이벤트
spread.bind(GC.Spread.Sheets.Events.CellChanged, (sender, args) => {
// CellChanged는 값뿐 아니라 스타일 등 다른 속성 변경에도 발생하므로 값 변경만 필터링
if (args.propertyName !== "value") return;
const log = document.getElementById('eventLog');
if (log) log.textContent = `CellChanged: [행 ${args.row + 1}, 열 ${args.col + 1}] 새 값 = ${args.newValue}`;
});
document.getElementById('btnLoad')?.addEventListener('click', loadData);
document.getElementById('btnRead')?.addEventListener('click', () => {
const sel = sheet.getSelections()[0];
if (sel) {
const val = sheet.getValue(sel.row, sel.col);
const label = document.getElementById('cellValue');
if (label) label.textContent = `선택 값: ${val ?? '(없음)'}`;
}
});