JavaScript
// 프로그레스 바 커스텀 셀 타입 정의
function ProgressBarCellType() {}
ProgressBarCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
ProgressBarCellType.prototype.paint = function(ctx, value, x, y, w, h, style, context) {
if (!ctx) return;
const pct = Math.min(Math.max(Number(value) || 0, 0), 100) / 100;
const barH = 18, barY = y + (h - barH) / 2, padX = 8;
ctx.save();
ctx.rect(x, y, w, h); ctx.clip();
// 배경 트랙
ctx.fillStyle = '#ECEFF1';
ctx.beginPath();
ctx.roundRect(x + padX, barY, w - padX * 2, barH, 4);
ctx.fill();
// 진행 바
if (pct > 0) {
ctx.fillStyle = pct >= 0.8 ? '#43A047' : pct >= 0.5 ? '#FB8C00' : '#E53935';
ctx.beginPath();
ctx.roundRect(x + padX, barY, (w - padX * 2) * pct, barH, 4);
ctx.fill();
}
// 퍼센트 텍스트
ctx.fillStyle = pct > 0.45 ? '#fff' : '#546E7A';
ctx.font = 'bold 11px sans-serif';
ctx.textAlign = 'center'; ctx.textBaseline = 'middle';
ctx.fillText(Math.round(pct * 100) + '%', x + w / 2, barY + barH / 2);
ctx.restore();
};
// 워크북 구성
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
const progBar = new ProgressBarCellType();
const headers = ['담당자', '이번 달 목표', '달성률'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#283593').foreColor('#fff').font('bold 13px sans-serif').hAlign(1);
sheet.setColumnWidth(c, c === 2 ? 200 : 130);
});
sheet.setRowHeight(0, 36);
const data = [
['김민준', '계약 10건', 92], ['이서연', '매출 5억', 68],
['박지호', '신규 고객 20사', 35], ['최유진', '제안서 15건', 81],
];
data.forEach(([name, goal, pct], r) => {
sheet.setValue(r + 1, 0, name);
sheet.setValue(r + 1, 1, goal);
sheet.setValue(r + 1, 2, pct);
sheet.getCell(r + 1, 2).cellType(progBar);
sheet.setRowHeight(r + 1, 42);
});