JavaScript
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
// x-spreadsheet 데이터 구조 (마이그레이션 대상)
const xsData = {
rows: {
0: { cells: { 0: { text: '부서' }, 1: { text: '예산(만원)' }, 2: { text: '집행(만원)' }, 3: { text: '집행률' } } },
1: { cells: { 0: { text: '개발팀' }, 1: { text: '5000' }, 2: { text: '3900' } } },
2: { cells: { 0: { text: '마케팅팀' }, 1: { text: '3200' }, 2: { text: '2912' } } },
3: { cells: { 0: { text: '영업팀' }, 1: { text: '4100' }, 2: { text: '2665' } } },
4: { cells: { 0: { text: '인사팀' }, 1: { text: '1800' }, 2: { text: '1530' } } },
}
};
// x-spreadsheet → SpreadJS 변환 함수
function migrateFromXSpread(xsData, sheet) {
const rows = xsData.rows || {};
Object.entries(rows).forEach(([rowIdx, rowData]) => {
const r = parseInt(rowIdx);
const cells = rowData.cells || {};
Object.entries(cells).forEach(([colIdx, cellData]) => {
const c = parseInt(colIdx);
const text = cellData.text || '';
const num = parseFloat(text);
sheet.setValue(r, c, isNaN(num) ? text : num);
});
});
}
migrateFromXSpread(xsData, sheet);
// 헤더 스타일 적용
const colWidths = [90, 100, 100, 90];
colWidths.forEach((w, c) => sheet.setColumnWidth(c, w));
for (let c = 0; c < 4; c++) {
sheet.getCell(0, c).backColor('#37474F').foreColor('#fff').font('bold 12px sans-serif');
}
sheet.setRowHeight(0, 36);
// SpreadJS에서 수식 추가 — x-spreadsheet에서 불가했던 기능
for (let r = 1; r <= 4; r++) {
sheet.setFormula(r, 3, `=C${r+1}/B${r+1}`);
sheet.getCell(r, 3).formatter('0%');
sheet.getCell(r, 1).formatter('#,##0');
sheet.getCell(r, 2).formatter('#,##0');
const rowBg = r % 2 === 0 ? '#F5F5F5' : '#FFFFFF';
for (let c = 0; c < 4; c++) sheet.getCell(r, c).backColor(rowBg);
}
// 조건부 서식: 집행률 80% 미만이면 노란색 경고
const cfs = sheet.conditionalFormats;
const warnStyle = new GC.Spread.Sheets.Style();
warnStyle.backColor = '#FFF9C4';
cfs.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.lessThan,
0.8, 0, warnStyle,
[new GC.Spread.Sheets.Range(1, 3, 4, 1)]
);
const okStyle = new GC.Spread.Sheets.Style();
okStyle.backColor = '#C8E6C9';
cfs.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan,
0.8, 0, okStyle,
[new GC.Spread.Sheets.Range(1, 3, 4, 1)]
);