const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
// 헤더 행
const headers = ['부서', '직원명', '매출(백만원)', '달성률(%)', '등급'];
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 === 1 ? 90 : c === 0 ? 80 : 100);
});
sheet.setRowHeight(0, 36);
// 샘플 데이터
const data = [
['영업1팀', '김민준', 128, 107, 'S'],
['영업1팀', '이서연', 95, 79, 'C'],
['영업2팀', '박지호', 145, 121, 'S'],
['영업2팀', '최유진', 112, 93, 'B'],
['영업3팀', '정수민', 88, 73, 'D'],
['영업3팀', '한지수', 133, 111, 'S'],
['영업3팀', '오세훈', 101, 84, 'B'],
];
data.forEach((row, r) => {
row.forEach((val, c) => sheet.setValue(r + 1, c, val));
if (r % 2 === 0) {
for (let c = 0; c < 5; c++) sheet.getCell(r + 1, c).backColor('#F5F5F5');
}
});
// 달성률 열(index 3)에 조건부 서식 적용
const greenStyle = new GC.Spread.Sheets.Style();
greenStyle.backColor = '#C8E6C9';
greenStyle.foreColor = '#1B5E20';
const yellowStyle = new GC.Spread.Sheets.Style();
yellowStyle.backColor = '#FFF9C4';
yellowStyle.foreColor = '#F57F17';
const redStyle = new GC.Spread.Sheets.Style();
redStyle.backColor = '#FFCDD2';
redStyle.foreColor = '#B71C1C';
const cf = sheet.conditionalFormats;
const cfRange = [new GC.Spread.Sheets.Range(1, 3, data.length, 1)];
cf.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThanOrEqualsTo,
100, 0, greenStyle, cfRange
);
cf.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.between,
80, 99, yellowStyle, cfRange
);
cf.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.lessThan,
80, 0, redStyle, cfRange
);
// xlsx 내보내기
document.getElementById('btnExport')?.addEventListener('click', () => {
const msg = document.getElementById('exportMsg');
spread.export(blob => {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = '매출_현황.xlsx';
a.click();
URL.revokeObjectURL(url);
if (msg) msg.textContent = '✅ Excel 파일로 내보내기 완료 (조건부 서식 보존)';
}, e => {
console.error(e);
if (msg) msg.textContent = '❌ 내보내기 실패';
}, {
fileType: GC.Spread.Sheets.FileType.excel
});
});