JavaScript
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
const headers = ['부서', '직원명', '1월(만원)', '2월(만원)', '3월(만원)', '1분기 합계'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#1565C0').foreColor('#fff').font('bold 12px sans-serif').hAlign(1);
sheet.setColumnWidth(c, c < 2 ? 85 : 90);
});
sheet.setRowHeight(0, 34);
const data = [
['영업팀', '김민준', 4200, 3800, 5100],
['영업팀', '이서연', 3500, 4100, 3900],
['개발팀', '박지호', 2800, 3200, 4500],
['개발팀', '최유진', 3100, 2900, 3300],
['마케팅', '정수민', 3800, 4200, 4800],
];
data.forEach((row, r) => {
for (let c = 0; c < 5; c++) sheet.setValue(r + 1, c, row[c]);
sheet.setValue(r + 1, 5, row[2] + row[3] + row[4]);
sheet.getCell(r + 1, 0).backColor(r % 2 === 0 ? '#F0F4FF' : '#fff');
});
function applyPrintInfo(isLandscape) {
const printInfo = new GC.Spread.Sheets.Print.PrintInfo();
// A4 용지 크기 (단위: 1/100인치, A4 = 8.27" × 11.69")
printInfo.paperSize(new GC.Spread.Sheets.Print.PaperSize(827, 1169));
// 여백 설정 (단위: 1/100인치, 75 = 0.75인치)
printInfo.margin({ top: 75, bottom: 75, left: 70, right: 70, header: 30, footer: 30 });
// 페이지 방향
const Orient = GC.Spread.Sheets.Print.PrintPageOrientation;
printInfo.orientation(isLandscape ? Orient.landscape : Orient.portrait);
printInfo.showGridLine(false);
sheet.printInfo(printInfo);
sheet.isPrintLineVisible(true);
}
applyPrintInfo(false);
document.getElementById('btnPortrait')?.addEventListener('click', () => applyPrintInfo(false));
document.getElementById('btnLandscape')?.addEventListener('click', () => applyPrintInfo(true));
document.getElementById('btnPrint')?.addEventListener('click', () => spread.print(0));