const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
// 한국어 견적서 구성
sheet.addSpan(0, 0, 1, 6);
sheet.setValue(0, 0, '견적서');
sheet.getCell(0, 0).font('bold 18px NanumGothic').foreColor('#1A237E').hAlign(1);
sheet.setRowHeight(0, 52);
const cols = ['품목', '규격', '단위', '수량', '단가(원)', '금액(원)'];
cols.forEach((h, c) => {
sheet.setValue(1, c, h);
sheet.getCell(1, c).backColor('#1A237E').foreColor('#fff').font('bold 12px NanumGothic').hAlign(1);
sheet.setColumnWidth(c, c === 0 ? 140 : c === 1 ? 100 : 75);
});
sheet.setRowHeight(1, 32);
const rows = [
['SpreadJS Enterprise', 'v19 서버', 'EA', 1, 8000000, 8000000],
['ActiveReportsJS', 'v5 서버', 'EA', 2, 5500000, 11000000],
['기술지원 서비스', '1년', 'EA', 1, 2000000, 2000000],
['설치·교육', '1일', '건', 2, 1500000, 3000000],
];
rows.forEach((row, r) => {
row.forEach((val, c) => sheet.setValue(r + 2, c, val));
for (let c = 0; c < 6; c++)
sheet.getCell(r + 2, c).backColor(r % 2 === 0 ? '#E8EAF6' : '#fff').font('12px NanumGothic');
});
const total = rows.reduce((s, r) => s + r[5], 0);
sheet.addSpan(6, 0, 1, 5);
sheet.setValue(6, 0, '합계');
sheet.setValue(6, 5, total);
sheet.getCell(6, 0).backColor('#C5CAE9').font('bold 12px NanumGothic').hAlign(1);
sheet.getCell(6, 5).backColor('#C5CAE9').font('bold 12px NanumGothic');
// PrintInfo 적용
const printInfo = new GC.Spread.Sheets.Print.PrintInfo();
printInfo.paperSize(new GC.Spread.Sheets.Print.PaperSize(827, 1169));
printInfo.margin({ top: 100, bottom: 100, left: 90, right: 90, header: 40, footer: 40 });
printInfo.showGridLine(false);
printInfo.pageHeaderFooter({
normal: { footer: { right: '생성일: &D &P / &N 페이지' } }
});
sheet.printInfo(printInfo);
document.getElementById('btnExportPDF')?.addEventListener('click', async () => {
const statusEl = document.getElementById('pdfStatus');
statusEl.textContent = '폰트 로딩 중...';
try {
const fontUrl = 'https://cdn.jsdelivr.net/gh/google/fonts@main/ofl/nanumgothic/NanumGothic-Regular.ttf';
const res = await fetch(fontUrl);
if (!res.ok) throw new Error('폰트 로드 실패');
const fontBuffer = await res.arrayBuffer();
// NanumGothic 폰트 등록
GC.Spread.Sheets.PDF.PDFFontsManager.registerFont('NanumGothic', { normal: fontBuffer });
// 등록되지 않은 CJK 폰트 폴백
GC.Spread.Sheets.PDF.PDFFontsManager.fallbackFont = () => fontBuffer;
statusEl.textContent = 'PDF 생성 중...';
spread.savePDF(
function(blob) {
const url = URL.createObjectURL(blob);
const a = document.getElementById('pdfDownload');
a.href = url;
a.download = 'quotation.pdf';
a.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);
statusEl.textContent = 'PDF 저장 완료!';
},
function(err) {
statusEl.textContent = '오류: ' + err;
console.error(err);
},
{ title: '견적서', author: 'MESCIUS Korea' }
);
} catch (e) {
statusEl.textContent = '오류: ' + e.message;
}
});