const spread = new GC.Spread.Sheets.Workbook(
document.getElementById('spreadContainer'),
{ sheetCount: 0 }
);
const dataManager = spread.dataManager();
const inventoryTable = dataManager.addTable('inventory', {
data: [
{ code: 'PRD-001', name: '노트북 A모델', category: '전자기기', warehouse: '본사창고', stock: 45, price: 1250000, reorder: 10 },
{ code: 'PRD-002', name: '무선 마우스', category: '주변기기', warehouse: '본사창고', stock: 8, price: 35000, reorder: 20 },
{ code: 'PRD-003', name: '모니터 27인치', category: '전자기기', warehouse: '인천물류', stock: 22, price: 450000, reorder: 5 },
{ code: 'PRD-004', name: '기계식 키보드', category: '주변기기', warehouse: '인천물류', stock: 3, price: 120000, reorder: 10 },
{ code: 'PRD-005', name: '웹캠 HD', category: '주변기기', warehouse: '본사창고', stock: 15, price: 85000, reorder: 5 },
{ code: 'PRD-006', name: '서버 랙', category: '인프라', warehouse: '인천물류', stock: 2, price: 3500000, reorder: 2 },
{ code: 'PRD-007', name: 'USB 허브', category: '주변기기', warehouse: '본사창고', stock: 67, price: 28000, reorder: 15 },
{ code: 'PRD-008', name: 'NAS 스토리지', category: '인프라', warehouse: '인천물류', stock: 1, price: 2200000, reorder: 2 },
{ code: 'PRD-009', name: '헤드셋 노이즈캔슬링', category: '주변기기', warehouse: '본사창고', stock: 30, price: 195000, reorder: 8 },
{ code: 'PRD-010', name: '태블릿 B모델', category: '전자기기', warehouse: '인천물류', stock: 12, price: 890000, reorder: 5 },
]
});
const sheet = spread.addSheetTab(0, '재고 마스터', GC.Spread.Sheets.SheetType.tableSheet);
inventoryTable.fetch().then(() => {
const view = inventoryTable.addView('inventoryView', [
{ value: 'code', caption: '품목코드', width: 90 },
{ value: 'name', caption: '품명', width: 160 },
{ value: 'category', caption: '카테고리', width: 90 },
{ value: 'warehouse', caption: '창고', width: 90 },
{ value: 'stock', caption: '재고', width: 70 },
{ value: 'price', caption: '단가(원)', width: 110 },
{ value: 'reorder', caption: '재주문점', width: 80 },
]);
sheet.setDataView(view);
// 카테고리별 재고 합계 + 평균 단가 자동 집계
sheet.groupBy([{
caption: '카테고리',
field: 'category',
width: 110,
style: { backColor: '#F3E5F5' },
summaryFields: [
{
caption: '재고 합계',
formula: '=SUM([stock])',
width: 80,
style: { backColor: '#E1BEE7', formatter: '#,##0', font: 'bold 12px sans-serif' }
},
{
caption: '평균 단가',
formula: '=AVERAGE([price])',
width: 120,
style: { backColor: '#E1BEE7', formatter: '#,##0', font: 'bold 12px sans-serif' }
}
]
}]);
});