JavaScript
const spread = new GC.Spread.Sheets.Workbook(document.getElementById('spreadContainer'));
const sheet = spread.getActiveSheet();
spread.options.tabStripVisible = false;
const colWidths = [160, 90, 140, 80, 80];
colWidths.forEach((w, c) => sheet.setColumnWidth(c, w));
sheet.setRowHeight(0, 36);
const headers = ['검사 항목', '환자값', '정상 범위', '단위', '상태'];
headers.forEach((h, c) => {
sheet.setValue(0, c, h);
sheet.getCell(0, c).backColor('#1565C0').foreColor('#fff').font('bold 12px sans-serif');
});
// [항목, 환자값, 정상하한, 정상상한, 단위, 상태]
const labData = [
['공복혈당 (Glucose)', 182, 70, 100, 'mg/dL', '↑ 높음'],
['크레아티닌 (Creatinine)', 1.62, 0.6, 1.2, 'mg/dL', '↑ 높음'],
['백혈구 (WBC)', 7.2, 4.0, 10.0, '×10³/μL', '정상'],
['헤모글로빈 (Hgb)', 10.8, 12.0, 16.0, 'g/dL', '↓ 낮음'],
['혈소판 (PLT)', 215, 150, 400, '×10³/μL', '정상'],
['ALT (간수치)', 72, 0, 40, 'U/L', '↑ 높음'],
['콜레스테롤 (TC)', 188, 0, 200, 'mg/dL', '정상'],
];
labData.forEach((row, r) => {
const [name, val, lo, hi, unit, status] = row;
sheet.setValue(r + 1, 0, name);
sheet.setValue(r + 1, 1, val);
sheet.setValue(r + 1, 2, `${lo} – ${hi}`);
sheet.setValue(r + 1, 3, unit);
sheet.setValue(r + 1, 4, status);
const rowBg = (r % 2 === 0) ? '#FAFAFA' : '#FFFFFF';
const rowStyle = new GC.Spread.Sheets.Style();
rowStyle.backColor = rowBg;
sheet.setStyle(r + 1, -1, rowStyle);
sheet.setRowHeight(r + 1, 30);
});
const CF = GC.Spread.Sheets.ConditionalFormatting;
labData.forEach((row, r) => {
const [, , lo, hi] = row;
const rng = [new GC.Spread.Sheets.Range(r + 1, 1, 1, 1)];
const redStyle = new GC.Spread.Sheets.Style();
redStyle.backColor = '#FFEBEE';
redStyle.foreColor = '#C62828';
redStyle.font = 'bold 12px sans-serif';
if (hi > 0) {
sheet.conditionalFormats.addCellValueRule(
CF.ComparisonOperators.greaterThan, hi, hi, redStyle, rng);
}
if (lo > 0) {
sheet.conditionalFormats.addCellValueRule(
CF.ComparisonOperators.lessThan, lo, lo, redStyle, rng);
}
});