JavaScript
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
// 헤더 설정
const headers = ['구역', 'kWh 소비', '전력피크(kW)', 'CO₂(kg)', '상태'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#1565C0').foreColor('#ffffff').font('bold 12px sans-serif');
});
sheet.setRowHeight(0, 34);
[90, 85, 105, 80, 70].forEach((w, c) => sheet.setColumnWidth(c, w));
// 구역별 기준 데이터
const zones = ['공장동', '본관', '창고동', '서버실'];
const baseKwh = [280, 145, 320, 95];
const basePeak = [ 42, 22, 51, 18];
const baseCo2 = [112, 58, 128, 38];
const THRESHOLD = 300;
// 각 구역 kWh 셀에 조건부 서식 적용
zones.forEach((_, r) => {
const redStyle = new GC.Spread.Sheets.Style();
redStyle.backColor = '#FFCDD2';
redStyle.foreColor = '#B71C1C';
redStyle.font = 'bold 12px sans-serif';
sheet.conditionalFormats.addCellValueRule(
GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators.greaterThan,
THRESHOLD, 0, redStyle, [new GC.Spread.Sheets.Range(r + 1, 1, 1, 1)]
);
});
// 데이터 갱신 함수
function updateData() {
zones.forEach((zone, r) => {
const row = r + 1;
const kwh = Math.round(baseKwh[r] + (Math.random() - 0.45) * 40);
const peak = Math.round(basePeak[r] + (Math.random() - 0.45) * 8);
const co2 = Math.round(baseCo2[r] + (Math.random() - 0.45) * 15);
const over = kwh > THRESHOLD;
sheet.setValue(row, 0, zone);
sheet.setValue(row, 1, kwh);
sheet.setValue(row, 2, peak);
sheet.setValue(row, 3, co2);
sheet.setValue(row, 4, over ? '⚠️ 초과' : '✅ 정상');
const rowBg = over ? '#FFF9C4' : '#FAFAFA';
[0, 2, 3, 4].forEach(c => sheet.getCell(row, c).backColor(rowBg));
});
const el = document.getElementById('lastUpdate');
if (el) el.textContent = '최종 갱신: ' + new Date().toLocaleTimeString('ko-KR');
}
updateData();
setInterval(updateData, 1500);