JavaScript
// 폴링 기반 자동 갱신 패턴
function refreshInventory(sheet, apiData) {
spread.suspendPaint();
sheet.setArray(1, 0, apiData);
spread.resumePaint();
}
// 30초마다 자동 갱신
setInterval(() => {
fetch('/api/inventory/warehouse-a')
.then(res => res.json())
.then(data => refreshInventory(sheet, data));
}, 30000);
// RangeChanged 이벤트로 수동 편집 감지
sheet.bind(GC.Spread.Sheets.Events.RangeChanged, (sender, args) => {
const { row, col, newValue } = args;
// 변경 내용 서버 전송
fetch('/api/inventory/update', {
method: 'POST',
body: JSON.stringify({ row, col, value: newValue }),
});
});