JavaScript
const spread = new GC.Spread.Sheets.Workbook(
document.getElementById('spreadContainer'),
{ sheetCount: 0 }
);
const dataManager = spread.dataManager();
const salesTable = dataManager.addTable('sales', {
data: [
{ region: '서울', product: 'SpreadJS', quarter: 'Q1', amount: 12500000, qty: 5 },
{ region: '서울', product: 'Wijmo', quarter: 'Q1', amount: 8700000, qty: 3 },
{ region: '부산', product: 'SpreadJS', quarter: 'Q1', amount: 9200000, qty: 4 },
{ region: '부산', product: 'Wijmo', quarter: 'Q1', amount: 6100000, qty: 2 },
{ region: '서울', product: 'SpreadJS', quarter: 'Q2', amount: 15300000, qty: 6 },
{ region: '서울', product: 'Wijmo', quarter: 'Q2', amount: 9800000, qty: 4 },
{ region: '부산', product: 'SpreadJS', quarter: 'Q2', amount: 11000000, qty: 5 },
{ region: '부산', product: 'Wijmo', quarter: 'Q2', amount: 7400000, qty: 3 },
{ region: '대전', product: 'SpreadJS', quarter: 'Q1', amount: 6500000, qty: 3 },
{ region: '대전', product: 'Wijmo', quarter: 'Q2', amount: 5200000, qty: 2 },
]
});
const sheet = spread.addSheetTab(0, '지역별 매출', GC.Spread.Sheets.SheetType.tableSheet);
salesTable.fetch().then(() => {
const view = salesTable.addView('salesView', [
{ value: 'region', caption: '지역', width: 80 },
{ value: 'product', caption: '제품', width: 100 },
{ value: 'quarter', caption: '분기', width: 70 },
{ value: 'amount', caption: '매출액', width: 130 },
{ value: 'qty', caption: '수량', width: 70 },
]);
sheet.setDataView(view);
// 지역별 그룹핑 + SUM 집계 행
sheet.groupBy([{
caption: '지역',
field: 'region',
width: 100,
style: { backColor: '#E3F2FD' },
summaryFields: [
{
caption: '합계 매출액',
formula: '=SUM([amount])',
width: 140,
style: { backColor: '#BBDEFB', formatter: '#,##0', font: 'bold 12px sans-serif' }
},
{
caption: '합계 수량',
formula: '=SUM([qty])',
width: 80,
style: { backColor: '#BBDEFB', font: 'bold 12px sans-serif' }
}
]
}]);
});