JavaScript
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
// 1. 전체 셀을 기본적으로 잠금 해제 (기본은 모두 locked)
const unlockedStyle = new GC.Spread.Sheets.Style();
unlockedStyle.locked = false;
sheet.setDefaultStyle(unlockedStyle);
// 헤더 설정
const headers = ['계정과목', '예산(원)', '실적(원)', '달성률(%)'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#37474F').foreColor('#ffffff').font('bold 12px sans-serif').hAlign(GC.Spread.Sheets.HorizontalAlign.center);
sheet.setColumnWidth(c, c === 0 ? 150 : 130);
});
sheet.setRowHeight(0, 36);
// 계정과목 데이터
const items = [
['급여', 13000000, 12500000],
['복리후생비', 400000, 320000],
['여비교통비', 100000, 85000],
['통신비', 70000, 55000],
['소모품비', 200000, 215000],
['광고선전비', 500000, 480000],
];
items.forEach((item, r) => {
sheet.setValue(r + 1, 0, item[0]);
sheet.setValue(r + 1, 1, item[1]); // 예산 (입력 가능)
sheet.setValue(r + 1, 2, item[2]); // 실적 (입력 가능)
// 달성률 = 수식 셀 (잠금)
sheet.setFormula(r + 1, 3, `=IF(B${r+2}>0,C${r+2}/B${r+2}*100,0)`);
sheet.getCell(r + 1, 1).formatter('#,##0');
sheet.getCell(r + 1, 2).formatter('#,##0');
sheet.getCell(r + 1, 3).formatter('0.0"%"');
for (let c = 0; c < 4; c++) {
sheet.getCell(r + 1, c).backColor(r % 2 === 0 ? '#FAFAFA' : '#FFFFFF');
}
});
// 합계 행 (8행)
const totalRow = items.length + 1;
sheet.setValue(totalRow, 0, '합 계');
sheet.setFormula(totalRow, 1, `=SUM(B2:B${totalRow})`);
sheet.setFormula(totalRow, 2, `=SUM(C2:C${totalRow})`);
sheet.setFormula(totalRow, 3, `=IF(B${totalRow+1}>0,C${totalRow+1}/B${totalRow+1}*100,0)`);
for (let c = 0; c < 4; c++) {
sheet.getCell(totalRow, c).backColor('#CFD8DC').font('bold 12px sans-serif').formatter(c >= 1 ? (c === 3 ? '0.0"%"' : '#,##0') : '@');
}
// 2. D열(달성률) 전체와 합계행 잠금 (locked=true)
new GC.Spread.Sheets.CellRange(sheet, 1, 3, items.length + 1, 1).locked(true);
new GC.Spread.Sheets.CellRange(sheet, totalRow, 1, 1, 3).locked(true);
// 3. 시트 보호 활성화
sheet.options.isProtected = true;
sheet.options.protectionOptions = {
allowSelectLockedCells: true,
allowSelectUnlockedCells: true
};
sheet.setRowHeight(totalRow, 36);