JavaScript
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
const headers = ['제품명', '1월', '2월', '3월', '합계', '평균', '최고월'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#1565C0').foreColor('#fff').font('bold 12px sans-serif');
sheet.setColumnWidth(c, c === 0 ? 90 : 80);
});
sheet.setRowHeight(0, 36);
const data = [
['노트북', 1240, 980, 1580],
['스마트폰', 3200, 2850, 3400],
['태블릿', 780, 920, 650],
['모니터', 450, 610, 820],
['키보드', 280, 310, 290],
];
data.forEach(([name, m1, m2, m3], r) => {
sheet.setValue(r + 1, 0, name);
sheet.setValue(r + 1, 1, m1);
sheet.setValue(r + 1, 2, m2);
sheet.setValue(r + 1, 3, m3);
sheet.setFormula(r + 1, 4, `=SUM(B${r+2}:D${r+2})`);
sheet.setFormula(r + 1, 5, `=AVERAGE(B${r+2}:D${r+2})`);
sheet.setFormula(r + 1, 6, `=IF(B${r+2}=MAX(B${r+2}:D${r+2}),"1월",IF(C${r+2}=MAX(B${r+2}:D${r+2}),"2월","3월"))`);
sheet.getCell(r + 1, 4).formatter('#,##0');
sheet.getCell(r + 1, 5).formatter('#,##0.0');
const rowBg = r % 2 === 0 ? '#FAFAFA' : '#FFFFFF';
for (let c = 0; c < 7; c++) sheet.getCell(r + 1, c).backColor(rowBg);
});
const totalRow = data.length + 1;
sheet.setValue(totalRow, 0, '합계');
['B','C','D','E'].forEach((col, i) => {
sheet.setFormula(totalRow, i + 1, `=SUM(${col}2:${col}6)`);
sheet.getCell(totalRow, i + 1).formatter('#,##0');
});
for (let c = 0; c < 7; c++) sheet.getCell(totalRow, c).font('bold 12px sans-serif').backColor('#E3F2FD');
sheet.setRowHeight(totalRow, 32);
const cfs = sheet.conditionalFormats;
const highStyle = new GC.Spread.Sheets.Style();
highStyle.backColor = '#C8E6C9';
cfs.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan,
3500, 0, highStyle,
[new GC.Spread.Sheets.Range(1, 4, 5, 1)]
);
const lowStyle = new GC.Spread.Sheets.Style();
lowStyle.backColor = '#FFCCBC';
cfs.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.lessThan,
2000, 0, lowStyle,
[new GC.Spread.Sheets.Range(1, 4, 5, 1)]
);