JavaScript
// CREDITSCORE(연소득만원, 부채비율%, 담보가치만원) → 신용점수 0~100
class CreditScoreFunction extends GC.Spread.CalcEngine.Functions.Function {
constructor() {
super('CREDITSCORE', 3, 3, {
description: '신용평가 점수: 소득(40%) + 부채비율(40%) + 담보가치(20%)',
parameters: [{ name: 'income' }, { name: 'debtRatio' }, { name: 'collateral' }]
});
}
evaluate(income, debtRatio, collateral) {
const i = parseFloat(income) || 0;
const d = parseFloat(debtRatio) || 0;
const c = parseFloat(collateral) || 0;
const incomeScore = Math.min(i / 100, 100) * 0.4; // 최대 10,000만원 기준
const debtScore = Math.max(100 - d, 0) * 0.4; // 부채 0% = 100점
const collScore = Math.min(c / 500, 100) * 0.2; // 최대 50,000만원 기준
return Math.round(incomeScore + debtScore + collScore);
}
}
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
spread.addCustomFunction(new CreditScoreFunction());
spread.options.tabStripVisible = false;
const sheet = spread.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').hAlign(GC.Spread.Sheets.HorizontalAlign.center);
sheet.setColumnWidth(c, [90, 115, 105, 125, 145][c]);
});
sheet.setRowHeight(0, 36);
const data = [
['김민준', 8000, 25, 30000],
['이서연', 4500, 65, 12000],
['박지호', 12000, 10, 50000],
['최유진', 3000, 80, 5000],
['정수민', 7500, 35, 22000],
['한지원', 5500, 45, 18000],
];
data.forEach((row, r) => {
row.forEach((val, c) => sheet.setValue(r + 1, c, val));
sheet.setFormula(r + 1, 4, `=CREDITSCORE(B${r + 2},C${r + 2},D${r + 2})`);
sheet.getCell(r + 1, 4).hAlign(GC.Spread.Sheets.HorizontalAlign.center).font('bold 13px sans-serif');
const altColor = r % 2 === 0 ? '#F5F5F5' : '#FFFFFF';
for (let c = 0; c < 4; c++) sheet.getCell(r + 1, c).backColor(altColor);
});