const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
// 샘플 데이터
const q = ['Q1','Q2','Q3','Q4'];
const a = [1200, 1450, 1380, 1620];
const b = [850, 920, 1050, 1180];
sheet.setValue(0, 0, '분기');
sheet.setValue(0, 1, '서울');
sheet.setValue(0, 2, '부산');
[0, 1, 2].forEach(c => {
sheet.getCell(0, c).backColor('#1565C0').foreColor('#fff').font('bold 12px sans-serif');
sheet.setColumnWidth(c, 80);
});
q.forEach((v, r) => {
sheet.setValue(r + 1, 0, v);
sheet.setValue(r + 1, 1, a[r]);
sheet.setValue(r + 1, 2, b[r]);
});
sheet.setRowHeight(0, 32);
sheet.charts.add(
'expChart',
GC.Spread.Sheets.Charts.ChartType.columnClustered,
0, 110, 500, 270,
'A1:C5',
GC.Spread.Sheets.Charts.RowCol.rows
);
// 인쇄 레이아웃 설정 (landscape = 2)
const pi = sheet.printInfo();
pi.showGridLine(false);
pi.orientation(2);
pi.fitPagesWide(1);
// 한글 PDF 폰트 사전 로드 (savePDF 호출 전 완료 필수)
const fontUrl = 'https://cdn.jsdelivr.net/gh/google/fonts@main/ofl/nanumgothic/NanumGothic-Regular.ttf';
const fontPromise = fetch(fontUrl)
.then(r => { if (!r.ok) throw new Error('폰트 응답 오류: ' + r.status); return r.arrayBuffer(); })
.then(buf => {
const b = new Uint8Array(buf);
if (!(b[0] === 0x00 && b[1] === 0x01)) throw new Error('유효하지 않은 TTF');
GC.Spread.Sheets.PDF.PDFFontsManager.registerFont('NanumGothic', { normal: buf });
GC.Spread.Sheets.PDF.PDFFontsManager.fallbackFont = 'NanumGothic';
})
.catch(e => console.warn('한글 폰트 로드 실패:', e.message));
document.getElementById('btnPdf')?.addEventListener('click', () => {
const pdfInfo = { title: 'SpreadJS 차트 보고서', author: 'MESCIUS', sheetIndex: 0 };
fontPromise.then(() => {
spread.savePDF(
function(pdf) {
const url = URL.createObjectURL(pdf);
const link = document.createElement('a');
link.href = url;
link.download = 'chart-report.pdf';
link.click();
URL.revokeObjectURL(url);
},
function(e) { console.error('PDF 내보내기 오류:', e); },
pdfInfo
);
});
});