const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
spread.options.useTouchLayout = true;
spread.options.tabStripVisible = false;
const sheet = spread.getActiveSheet();
sheet.setColumnCount(4);
sheet.setRowCount(6);
// 헤더
const headers = ['점검 항목', '기준값', '실측값 (입력)', '합격 여부'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#0D47A1').foreColor('#fff').font('bold 13px sans-serif').hAlign(1);
sheet.setColumnWidth(c, c === 0 ? 150 : c === 3 ? 110 : 100);
});
sheet.setRowHeight(0, 42);
const checkItems = [
['압력 (MPa)', '0.40 ~ 0.60'],
['온도 (°C)', '65 ~ 75'],
['유량 (L/min)', '12 ~ 18'],
['진동 (mm/s)', '≤ 2.8'],
['소음 (dB)', '≤ 75'],
];
const standards = [[0.4, 0.6], [65, 75], [12, 18], [0, 2.8], [0, 75]];
checkItems.forEach((row, r) => {
sheet.setValue(r + 1, 0, row[0]);
sheet.setValue(r + 1, 1, row[1]);
const bg = r % 2 === 0 ? '#F5F9FF' : '#FFFFFF';
for (let c = 0; c < 4; c++) sheet.getCell(r + 1, c).backColor(bg);
sheet.getCell(r + 1, 1).hAlign(1);
// 실측값 열 — 입력 가능 표시
sheet.getCell(r + 1, 2).backColor('#FFFDE7').hAlign(1);
sheet.setRowHeight(r + 1, 38);
});
// 보호 설정: 기본 잠금 해제 후 실측값 열(c=2)만 편집 허용
const defStyle = sheet.getDefaultStyle();
defStyle.locked = false;
sheet.setDefaultStyle(defStyle);
[0, 1, 3].forEach(c => sheet.getRange(-1, c, -1, 1).locked(true));
sheet.options.isProtected = true;
sheet.options.protectionOptions = {
allowSelectLockedCells: true,
allowSelectUnlockedCells: true,
};
// CellChanged — 실측값 입력 시 합격 여부 자동 판정
// isProtected=true 환경에서는 RangeChanged 대신 CellChanged + propertyName==='value' 사용
sheet.bind(GC.Spread.Sheets.Events.CellChanged, function (e, info) {
if (info.propertyName !== 'value') return;
const r = info.row;
if (r < 1 || r > checkItems.length || info.col !== 2) return;
const val = parseFloat(sheet.getValue(r, 2));
const std = standards[r - 1];
let result = '', color = '#FFFFFF', textColor = '#333';
if (!isNaN(val) && std) {
if (val >= std[0] && val <= std[1]) {
result = '✔ 합격'; color = '#E8F5E9'; textColor = '#2E7D32';
} else {
result = '✘ 불합격'; color = '#FFEBEE'; textColor = '#C62828';
}
}
spread.suspendPaint();
sheet.setValue(r, 3, result);
sheet.getCell(r, 3).backColor(color).foreColor(textColor).font('bold 12px sans-serif').hAlign(1);
spread.resumePaint();
const msg = document.getElementById('saveMsg');
if (msg) {
msg.style.display = 'block';
setTimeout(() => { msg.style.display = 'none'; }, 2000);
}
});