JavaScript
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
spread.options.tabStripVisible = false;
const sheet = spread.getActiveSheet();
const headers = ['성명', '기본급', '공제합계', '실수령액', '공제율(%)'];
const widths = [80, 100, 90, 90, 100];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c)
.backColor('#2E7D32').foreColor('#FFFFFF')
.font('bold 11px sans-serif')
.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
sheet.setColumnWidth(c, widths[c]);
});
sheet.setRowHeight(0, 36);
const employees = [
['김민준', 4200000, 560000], ['이서연', 3800000, 470000],
['박지호', 3500000, 430000], ['최유진', 5100000, 720000],
['정수민', 4600000, 610000], ['강현우', 4000000, 500000],
['윤지아', 5500000, 790000], ['임도현', 3600000, 445000],
['오수진', 3900000, 480000], ['신재원', 4800000, 650000],
];
employees.forEach(([name, salary, deduction], r) => {
const row = r + 1;
sheet.setValue(row, 0, name);
sheet.setValue(row, 1, salary);
sheet.setValue(row, 2, deduction);
sheet.setFormula(row, 3, `=B${row + 1}-C${row + 1}`);
sheet.setFormula(row, 4, `=ROUND(C${row + 1}/B${row + 1}*100,1)`);
const bg = r % 2 === 0 ? '#FFFFFF' : '#F8F9FA';
for (let c = 0; c < 5; c++) sheet.getCell(row, c).backColor(bg);
for (let c = 1; c < 5; c++) {
sheet.getCell(row, c).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
}
for (let c = 1; c < 4; c++) sheet.getCell(row, c).formatter('#,##0');
sheet.getCell(row, 4).formatter('0.0');
sheet.setRowHeight(row, 28);
});
// 조건부 서식 ①: 공제율(E열) 15% 초과 시 주황색 경고
const warningStyle = new GC.Spread.Sheets.Style();
warningStyle.backColor = '#FFF3E0';
warningStyle.foreColor = '#E65100';
warningStyle.font = 'bold 11px sans-serif';
sheet.conditionalFormats.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.GreaterThan,
15, undefined, warningStyle,
[new GC.Spread.Sheets.Range(1, 4, 10, 1)]
);
// 조건부 서식 ②: 공제합계(C열) 70만원 초과 시 빨간색 경고
const alertStyle = new GC.Spread.Sheets.Style();
alertStyle.backColor = '#FFEBEE';
alertStyle.foreColor = '#C62828';
sheet.conditionalFormats.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.GreaterThan,
700000, undefined, alertStyle,
[new GC.Spread.Sheets.Range(1, 2, 10, 1)]
);