JavaScript
// DefaultConfig를 깊은 복사해 수정 (원본 훼손 방지)
const config = JSON.parse(JSON.stringify(GC.Spread.Sheets.Designer.DefaultConfig));
// 사용자 정의 명령 등록 — execute의 첫 번째 인자는 Designer 인스턴스
config.commandMap = {
highlightSelection: {
title: '선택 영역을 노란색으로 강조',
text: '강조',
iconClass: 'ribbon-icon-highlight',
bigButton: true,
commandName: 'highlightSelection',
execute: (context) => {
const sheet = context.getWorkbook().getActiveSheet();
sheet.suspendPaint();
sheet.getSelections().forEach(sel => {
sheet.getRange(sel.row, sel.col, sel.rowCount, sel.colCount).backColor('#FFF59D');
});
sheet.resumePaint();
}
},
insertToday: {
title: '활성 셀에 오늘 날짜 입력',
text: '오늘 날짜',
iconClass: 'ribbon-icon-today',
bigButton: true,
commandName: 'insertToday',
execute: (context) => {
const sheet = context.getWorkbook().getActiveSheet();
const row = sheet.getActiveRowIndex();
const col = sheet.getActiveColumnIndex();
sheet.setValue(row, col, new Date());
sheet.getCell(row, col).formatter('yyyy-mm-dd');
}
}
};
// Home 탭 맨 앞에 "사용자 정의" 버튼 그룹 추가
config.ribbon[0].buttonGroups.unshift({
label: '사용자 정의',
commandGroup: {
children: [
{ direction: 'vertical', commands: ['highlightSelection'] },
{ direction: 'vertical', commands: ['insertToday'] }
]
}
});
const designer = new GC.Spread.Sheets.Designer.Designer(
document.getElementById('spreadContainer'), config
);
const sheet = designer.getWorkbook().getActiveSheet();
// 업무 일지 샘플 데이터
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 === 2 ? 200 : 110);
});
const logs = [
['', '김민준', '월결산 보고서 검토', 0.8],
['', '이서연', '거래처 단가표 갱신', 0.5],
['', '박지호', '분기 매출 집계', 1],
];
logs.forEach((row, r) => {
row.forEach((val, c) => { if (val !== '') sheet.setValue(r + 1, c, val); });
sheet.getCell(r + 1, 3).formatter('0%');
});
sheet.setRowHeight(0, 36);
sheet.setActiveCell(1, 0);