const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
const headers = ['항목', '값', '기준', '결과'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#1565C0').foreColor('#ffffff').font('bold 12px sans-serif');
sheet.setColumnWidth(c, c === 0 ? 150 : 110);
});
sheet.setRowHeight(0, 36);
const data = [
['신청인', '김민준', '-', '-'],
['대출 신청금액', 50000000, '-', '-'],
['연소득', 48000000, '-', '-'],
['연간 부채상환', 12000000, '-', '-'],
['DSR', '=B5/B4', '0.4 이하', ''],
['담보 평가액', 150000000, '-', '-'],
['LTV', '=B3/B7', '0.7 이하', ''],
['신용등급', 'A', '-', '-'],
['심사 결과', '최종 승인', '-', '✅'],
];
data.forEach(([label, val, crit, res], r) => {
sheet.setValue(r + 1, 0, label);
if (typeof val === 'string' && val.startsWith('=')) {
sheet.setFormula(r + 1, 1, val);
} else {
sheet.setValue(r + 1, 1, val);
}
sheet.setValue(r + 1, 2, crit);
sheet.setValue(r + 1, 3, res);
if (label === 'DSR' || label === 'LTV') sheet.getCell(r + 1, 1).formatter('0.0%');
if (['대출 신청금액', '연소득', '연간 부채상환', '담보 평가액'].includes(label)) sheet.getCell(r + 1, 1).formatter('#,##0');
sheet.setRowHeight(r + 1, 28);
});
sheet.getCell(9, 1).backColor('#E8F5E9').foreColor('#2E7D32').font('bold 13px sans-serif');
// 인쇄 설정 (print 플러그인 로드 시 적용)
try {
const pi = sheet.printInfo();
pi.showGridLine(false);
pi.orientation(2); // 2 = 가로 방향 (landscape)
pi.fitPagesTall(1);
sheet.printInfo(pi);
} catch (e) { /* print 플러그인 미로드 시 스킵 */ }
// PDF 생성 버튼
document.getElementById('btnPdf')?.addEventListener('click', () => {
spread.savePDF(
(blob) => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url; a.download = '대출심사결과보고서.pdf';
document.body.appendChild(a); a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
},
(err) => alert('PDF 오류: ' + err),
{ title: '대출 심사 결과 보고서', author: '심사팀', creator: 'SpreadJS' }
);
});