JavaScript
// 소득세 커스텀 함수 정의 (2024년 간이세액표 구간별 근사치)
function IncomeTaxFunction() {
this.name = 'CALC_INCOME_TAX';
this.minArgs = 1;
this.maxArgs = 1;
}
IncomeTaxFunction.prototype = new GC.Spread.CalcEngine.Functions.Function();
IncomeTaxFunction.prototype.evaluate = function(salary) {
if (salary <= 1060000) return 0;
if (salary <= 1500000) return Math.round((salary - 1060000) * 0.06);
if (salary <= 3000000) return Math.round(26400 + (salary - 1500000) * 0.15);
if (salary <= 4500000) return Math.round(251400 + (salary - 3000000) * 0.24);
if (salary <= 8700000) return Math.round(611400 + (salary - 4500000) * 0.35);
return Math.round(2081400 + (salary - 8700000) * 0.38);
};
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
spread.options.tabStripVisible = false;
spread.addCustomFunction(new IncomeTaxFunction());
const sheet = spread.getActiveSheet();
const headers = ['성명', '기본급', '소득세(커스텀 함수)', '공제 후 실수령액'];
const widths = [80, 100, 145, 135];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c)
.backColor('#37474F').foreColor('#FFFFFF')
.font('bold 11px sans-serif')
.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
sheet.setColumnWidth(c, widths[c]);
});
sheet.setRowHeight(0, 36);
const data = [
['김민준', 4200000], ['이서연', 3800000], ['박지호', 3500000],
['최유진', 5100000], ['정수민', 4600000], ['강현우', 4000000],
['윤지아', 5500000], ['임도현', 3600000],
];
data.forEach(([name, salary], r) => {
const row = r + 1;
sheet.setValue(row, 0, name);
sheet.setValue(row, 1, salary);
// 등록한 커스텀 함수를 일반 수식처럼 사용
sheet.setFormula(row, 2, `=CALC_INCOME_TAX(B${row + 1})`);
sheet.setFormula(row, 3, `=B${row + 1}-C${row + 1}`);
const bg = r % 2 === 0 ? '#FFFFFF' : '#F5F5F5';
for (let c = 0; c < 4; c++) sheet.getCell(row, c).backColor(bg);
for (let c = 1; c < 4; c++) {
sheet.getCell(row, c).formatter('#,##0').hAlign(GC.Spread.Sheets.HorizontalAlign.right);
}
sheet.setRowHeight(row, 28);
});