JavaScript
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
const headers = ['이름', '평균 점수', '등급'];
const colWidths = [110, 120, 90];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c)
.backColor('#37474F').foreColor('#ffffff')
.font('bold 13px sans-serif')
.hAlign(GC.Spread.Sheets.HorizontalAlign.center);
sheet.setColumnWidth(c, colWidths[c]);
});
sheet.setRowHeight(0, 36);
const data = [
['김민준', 90], ['이서연', 76], ['박지호', 63],
['최유진', 95], ['정수민', 52], ['강도윤', 82],
['윤하은', 71], ['임서준', 87], ['오지아', 59], ['한지민', 96],
];
data.forEach(([name, avg], r) => {
const row = r + 1;
sheet.setValue(row, 0, name);
sheet.setValue(row, 1, avg);
// IF 수식으로 등급 자동 계산
sheet.setFormula(row, 2,
`=IF(B${row + 1}>=90,"A",IF(B${row + 1}>=80,"B",IF(B${row + 1}>=70,"C",IF(B${row + 1}>=60,"D","F"))))`
);
sheet.getCell(row, 2).hAlign(GC.Spread.Sheets.HorizontalAlign.center).font('bold 13px sans-serif');
sheet.setRowHeight(row, 30);
});
const CF = GC.Spread.Sheets.ConditionalFormatting;
const scoreRange = [new GC.Spread.Sheets.Range(1, 1, 10, 1)];
// A: 90점 이상 (greaterThan(89) = >=90과 동일)
const styleA = new GC.Spread.Sheets.Style();
styleA.backColor = '#E8F5E9'; styleA.foreColor = '#1B5E20'; styleA.font = 'bold 13px sans-serif';
sheet.conditionalFormats.addCellValueRule(CF.ComparisonOperators.greaterThan, 89, undefined, styleA, scoreRange);
// B: 80~89
const styleB = new GC.Spread.Sheets.Style();
styleB.backColor = '#E3F2FD'; styleB.foreColor = '#0D47A1'; styleB.font = 'bold 13px sans-serif';
sheet.conditionalFormats.addCellValueRule(CF.ComparisonOperators.between, 80, 89, styleB, scoreRange);
// C: 70~79
const styleC = new GC.Spread.Sheets.Style();
styleC.backColor = '#FFFDE7'; styleC.foreColor = '#F57F17';
sheet.conditionalFormats.addCellValueRule(CF.ComparisonOperators.between, 70, 79, styleC, scoreRange);
// D: 60~69
const styleD = new GC.Spread.Sheets.Style();
styleD.backColor = '#FFF3E0'; styleD.foreColor = '#E65100';
sheet.conditionalFormats.addCellValueRule(CF.ComparisonOperators.between, 60, 69, styleD, scoreRange);
// F: 60 미만
const styleF = new GC.Spread.Sheets.Style();
styleF.backColor = '#FFEBEE'; styleF.foreColor = '#B71C1C';
sheet.conditionalFormats.addCellValueRule(CF.ComparisonOperators.lessThan, 60, undefined, styleF, scoreRange);