概述
这个 demo 用四张工作表展示进度迷你图的不同玩法,包括模式总览、发布准备、服务健康和学习进度。
实现思路
先定义一组可复用的进度图公式和命名区域。
再分别为每个 sheet 填入业务数据和格式化样式。
通过不同的 PROGRESSSPARKLINE 参数,展示条形、分段、环形和带标签的效果。
代码解析
这些公式把单元格数值直接转成迷你图,同时还能按阈值切换颜色和背景。
运行效果
第一张表会列出多种进度模式的公式和结果。
第二张表会显示发布准备状态和风险等级。
第三张表会展示服务健康卡片。
第四张表会显示课程学习完成度。
var spreadNS = window.GC && GC.Spread && GC.Spread.Sheets;
var HA = spreadNS.HorizontalAlign;
var VA = spreadNS.VerticalAlign;
var CF = spreadNS.ConditionalFormatting;
window.onload = function () {
initializeDemo();
};
function initializeDemo() {
var spread = new spreadNS.Workbook(document.getElementById("ss"), { sheetCount: 4 });
spread.suspendPaint();
configureOverviewSheet(spread.getSheet(0));
configureReleaseReadinessSheet(spread.getSheet(1));
configureServiceHealthSheet(spread.getSheet(2));
configureLearningProgressSheet(spread.getSheet(3));
spread.setActiveSheetIndex(0);
spread.resumePaint();
}
function configureSheetBase(sheet, name, rowCount, columnCount) {
sheet.name(name);
sheet.setRowCount(rowCount);
sheet.setColumnCount(columnCount);
}
function styleHeaderRow(sheet, row, columnCount, backColor, foreColor) {
sheet.getRange(row, 0, 1, columnCount)
.font("bold 13px Segoe UI")
.backColor(backColor || "#f3f6fb")
.foreColor(foreColor || "#314155")
.hAlign(HA.center)
.vAlign(VA.center);
}
function applyRangeStyle(range, options) {
if (options.font) {
range.font(options.font);
}
if (options.backColor !== undefined) {
range.backColor(options.backColor);
}
if (options.foreColor !== undefined) {
range.foreColor(options.foreColor);
}
if (options.hAlign !== undefined) {
range.hAlign(options.hAlign);
}
if (options.vAlign !== undefined) {
range.vAlign(options.vAlign);
}
if (options.wordWrap !== undefined) {
range.wordWrap(options.wordWrap);
}
if (options.formatter !== undefined) {
range.formatter(options.formatter);
}
}
function setHeaderValues(sheet, row, values) {
sheet.setArray(row, 0, [values]);
}
function setColumnWidths(sheet, widths) {
for (var col = 0; col < widths.length; col++) {
sheet.setColumnWidth(col, widths[col]);
}
}
function setUniformColumnWidths(sheet, startCol, colCount, width) {
for (var col = startCol; col < startCol + colCount; col++) {
sheet.setColumnWidth(col, width);
}
}
function setRowHeights(sheet, heights) {
for (var row in heights) {
if (Object.prototype.hasOwnProperty.call(heights, row)) {
sheet.setRowHeight(Number(row), heights[row]);
}
}
}
function registerCustomNames(sheet, names) {
for (var name in names) {
if (Object.prototype.hasOwnProperty.call(names, name) && !sheet.getCustomName(name)) {
sheet.addCustomName(name, names[name]);
}
}
}
function createForeColorStyle(color) {
var style = new spreadNS.Style();
style.foreColor = color;
return style;
}
function applySpecificTextColorRules(sheet, ranges, ruleColors) {
for (var text in ruleColors) {
if (Object.prototype.hasOwnProperty.call(ruleColors, text)) {
sheet.conditionalFormats.addSpecificTextRule(
CF.TextComparisonOperators.contains,
text,
createForeColorStyle(ruleColors[text]),
ranges
);
}
}
}
function toColumnMatrix(items, valueSelector) {
return items.map(function (item) {
return [valueSelector(item)];
});
}
function buildServiceHealthFormula(currentRef, targetRef, warningThreshold) {
return '=IF(' + currentRef + '>=' + targetRef + ',"健康",IF(' + currentRef + '>=' + warningThreshold + ',"预警","严重"))';
}
function registerServiceHealthNames(sheet) {
registerCustomNames(sheet, {
HealthyColor: '="#16a34a"',
WarningColor: '="#d97706"',
CriticalColor: '="#dc2626"',
HealthyBandColor: '="#dcfce7"',
WarningBandColor: '="#fef3c7"',
CriticalBandColor: '="#fee2e2"'
});
}
function buildServiceHealthSparklineFormula(currentRef, targetRef, warningThreshold) {
return '=PROGRESSSPARKLINE(' + currentRef + ',9,IF(' + currentRef + '>=' + targetRef + ',HealthyColor,IF(' + currentRef + '>=' + warningThreshold + ',WarningColor,CriticalColor)),IF(' + currentRef + '>=' + targetRef + ',HealthyBandColor,IF(' + currentRef + '>=' + warningThreshold + ',WarningBandColor,CriticalBandColor)),TRUE)';
}
function buildLiteralFormula(value, mode, barColor, bandColor, showValue) {
var formula = "=PROGRESSSPARKLINE(" + value + "," + mode;
if (barColor !== undefined || bandColor !== undefined || showValue !== undefined) {
if (barColor !== undefined && barColor !== null) {
formula += ',"' + escapeFormulaText(barColor) + '"';
} else {
formula += ",";
}
}
if (bandColor !== undefined || showValue !== undefined) {
if (bandColor !== undefined && bandColor !== null) {
formula += ',"' + escapeFormulaText(bandColor) + '"';
} else {
formula += ",";
}
}
if (showValue !== undefined) {
formula += "," + (showValue ? "TRUE" : "FALSE");
}
formula += ")";
return formula;
}
function buildCellFormula(valueColumnIndex, row, mode, barColor, bandColor, showValue) {
var valueRef = columnName(valueColumnIndex) + (row + 1);
return buildLiteralFormula(valueRef, mode, barColor, bandColor, showValue);
}
function escapeFormulaText(value) {
return String(value).replace(/"/g, '""');
}
function columnName(index) {
return String.fromCharCode("A".charCodeAt(0) + index);
}
function createBorder(color) {
return new spreadNS.LineBorder(color, spreadNS.LineStyle.thin);
}
function createReleaseReadinessSource() {
return RELEASE_READINESS_ROWS.map(function (item) {
return {
workstream: item.workstream,
owner: item.owner,
milestone: item.milestone,
targetDate: item.targetDate
};
});
}
function registerReleaseReadinessNames(sheet) {
registerCustomNames(sheet, {
AlertColor: '="#dc2626"',
AtRiskColor: '="#d97706"',
OnTrackColor: '="#4E7BEF"',
TrackColor: '="#DCE7FB"'
});
}
function buildReleaseReadinessRiskFormula(value) {
return '=LET(progress,' + value + ',IF(progress<0.3,"告警",IF(progress<0.5,"有风险","正常")))';
}
function buildReleaseReadinessSparklineFormula(value) {
return '=LET(progress,' + value + ',PROGRESSSPARKLINE(progress,0,IF(progress<0.3,AlertColor,IF(progress<0.5,AtRiskColor,OnTrackColor)),TrackColor,TRUE))';
}
var OVERVIEW_MODE_DEFINITIONS = [
{ mode: 0, label: "条形", value: 0.28, rowHeight: 50, barColor: "#e74c3c", bandColor: "#fce4e4" },
{ mode: 1, label: "条纹", value: 0.46, rowHeight: 50, barColor: "#27ae60", bandColor: null },
{ mode: 2, label: "分段", value: 0.71, rowHeight: 50, barColor: "Accent 4", bandColor: "Accent 4 80" },
{ mode: 3, label: "径向", value: 0.89, rowHeight: 60, barColor: "#2980b9", bandColor: "#d4e6f1" },
{ mode: 4, label: "弧形", value: 0.55, rowHeight: 60, barColor: "#8e44ad", bandColor: "#e8d5f5" },
{ mode: 5, label: "斜线填充", value: 0.50, rowHeight: 50, barColor: "#c0392b", bandColor: "#e6b0aa" },
{ mode: 6, label: "气泡", value: 0.40, rowHeight: 50, barColor: "#16a085", bandColor: null },
{ mode: 7, label: "点状", value: 0.33, rowHeight: 50, barColor: "#d35400", bandColor: "#edbb99" },
{ mode: 8, label: "复选框", value: 0.70, rowHeight: 50, barColor: "#1abc9c", bandColor: "#d5dbdb" },
{ mode: 9, label: "带缺口径向", value: 0.37, rowHeight: 60, barColor: "#c0392b", bandColor: "#bdc3c7" },
{ mode: 10, label: "加粗径向", value: 0.37, rowHeight: 60, barColor: "#e67e22", bandColor: "#d5d5d5" },
{ mode: 11, label: "刻度径向", value: 0.37, rowHeight: 60, barColor: "#27ae60", bandColor: "#d5d5d5" },
{ mode: 12, label: "虚线径向", value: 0.37, rowHeight: 60, barColor: "#2c3e9b", bandColor: "#d5d5d5" },
{ mode: 13, label: "圆点径向", value: 0.37, rowHeight: 60, barColor: "#8e44ad", bandColor: "#d5d5d5" },
{ mode: 14, label: "旋钮径向", value: 0.37, rowHeight: 60, barColor: "#e74c3c", bandColor: "#d5d5d5" }
];
function configureOverviewSheet(sheet) {
var rows = { header: 0, dataStart: 1 };
var cols = { mode: 0, value: 1, sparkline: 2, formula: 3 };
var rowCount = OVERVIEW_MODE_DEFINITIONS.length;
var totalRows = rows.dataStart + rowCount;
var border = createBorder("#d7dee7");
sheet.suspendPaint();
try {
configureSheetBase(sheet, "全部进度模式", totalRows, 4);
setColumnWidths(sheet, [140, 84, 300, 440]);
styleHeaderRow(sheet, rows.header, 4, "#f3f6fb", "#314155");
setHeaderValues(sheet, rows.header, ["模式", "值", "迷你图", "公式"]);
sheet.setRowHeight(rows.header, 30);
applyRangeStyle(sheet.getRange(rows.dataStart, cols.mode, rowCount, 1), {
font: "13px Segoe UI",
foreColor: "#1f2937",
hAlign: HA.center,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(rows.dataStart, cols.value, rowCount, 1), {
font: "13px Segoe UI",
foreColor: "#1f2937",
hAlign: HA.center,
vAlign: VA.center,
formatter: "0%"
});
applyRangeStyle(sheet.getRange(rows.dataStart, cols.sparkline, rowCount, 1), {
backColor: "#ffffff",
hAlign: HA.center,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(rows.dataStart, cols.formula, rowCount, 1), {
font: "13px Consolas",
foreColor: "#44556b",
backColor: "#fbfcfd",
wordWrap: true,
hAlign: HA.left,
vAlign: VA.center
});
OVERVIEW_MODE_DEFINITIONS.forEach(function (item, index) {
var row = rows.dataStart + index;
var formula = buildCellFormula(cols.value, row, item.mode, item.barColor, item.bandColor, true);
sheet.setRowHeight(row, item.rowHeight + 8);
sheet.setValue(row, cols.mode, item.mode + " " + item.label);
sheet.setValue(row, cols.value, item.value);
sheet.setFormula(row, cols.sparkline, formula);
sheet.setValue(row, cols.formula, formula);
});
sheet.getRange(rows.header, 0, OVERVIEW_MODE_DEFINITIONS.length + 1, 4).setBorder(border, { all: true });
sheet.getRange(0, 0, totalRows, 4).vAlign(VA.center);
} finally {
sheet.resumePaint();
}
}
var RELEASE_READINESS_ROWS = [
{ workstream: "结算", owner: "Iris", milestone: "税费与合计对齐", targetDate: "4月8日", value: 0.82 },
{ workstream: "身份认证", owner: "Nolan", milestone: "SSO 回调加固", targetDate: "4月11日", value: 0.64 },
{ workstream: "迁移", owner: "Mia", milestone: "旧版工作簿导入", targetDate: "4月14日", value: 0.58 },
{ workstream: "质量保障", owner: "Owen", milestone: "回归测试签收", targetDate: "4月15日", value: 0.75 },
{ workstream: "通知", owner: "Ethan", milestone: "模板审批", targetDate: "4月18日", value: 0.43 },
{ workstream: "计费", owner: "Chloe", milestone: "支付网关认证", targetDate: "4月19日", value: 0.27 },
{ workstream: "审计", owner: "Liam", milestone: "保留策略复核", targetDate: "4月22日", value: 0.56 },
{ workstream: "无障碍", owner: "Sofia", milestone: "VPAT 证据包", targetDate: "4月24日", value: 0.91 }
];
function configureReleaseReadinessSheet(sheet) {
var headerRow = 0;
var dataStartRow = 1;
var riskColumn = 4;
var readinessColumn = 5;
var rowCount = RELEASE_READINESS_ROWS.length;
var totalRows = dataStartRow + rowCount;
var border = createBorder("#d7dee7");
var source = { rows: createReleaseReadinessSource() };
sheet.suspendPaint();
try {
configureSheetBase(sheet, "发布准备度", totalRows, 6);
registerReleaseReadinessNames(sheet);
setColumnWidths(sheet, [240, 124, 250, 116, 108, 290]);
var table = sheet.tables.add("releaseReadinessTable", headerRow, 0, totalRows, 6, spreadNS.Tables.TableThemes.light2);
var tableColumns = [
new spreadNS.Tables.TableColumn(1, "workstream", "工作流"),
new spreadNS.Tables.TableColumn(2, "owner", "负责人"),
new spreadNS.Tables.TableColumn(3, "milestone", "里程碑"),
new spreadNS.Tables.TableColumn(4, "targetDate", "目标日期"),
new spreadNS.Tables.TableColumn(5, null, "风险"),
new spreadNS.Tables.TableColumn(6, null, "准备度")
];
table.autoGenerateColumns(false);
table.bind(tableColumns, "rows", source);
table.style(spreadNS.Tables.TableThemes["none"]);
table.highlightFirstColumn(false);
table.highlightLastColumn(false);
styleHeaderRow(sheet, headerRow, 6, "#f3f6fb", "#314155");
sheet.setRowHeight(headerRow, 30);
applyRangeStyle(sheet.getRange(dataStartRow, 0, rowCount, 1), {
font: "bold 13px Segoe UI",
foreColor: "#0f172a",
hAlign: HA.left,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(dataStartRow, 1, rowCount, 2), {
font: "13px Segoe UI",
foreColor: "#334155",
hAlign: HA.left,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(dataStartRow, 3, rowCount, 1), {
font: "13px Segoe UI",
foreColor: "#334155",
hAlign: HA.center,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(dataStartRow, riskColumn, rowCount, 1), {
font: "bold 13px Segoe UI",
backColor: "#ffffff",
hAlign: HA.center,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(dataStartRow, readinessColumn, rowCount, 1), {
backColor: "#ffffff",
hAlign: HA.center,
vAlign: VA.center
});
var riskRange = [new spreadNS.Range(dataStartRow, riskColumn, rowCount, 1)];
applySpecificTextColorRules(sheet, riskRange, {
"正常": "#475569",
"有风险": "#d97706",
"告警": "#dc2626"
});
RELEASE_READINESS_ROWS.forEach(function (item, index) {
var row = dataStartRow + index;
var riskFormula = buildReleaseReadinessRiskFormula(item.value);
var readinessFormula = buildReleaseReadinessSparklineFormula(item.value);
sheet.setRowHeight(row, 44);
sheet.setFormula(row, riskColumn, riskFormula);
sheet.setFormula(row, readinessColumn, readinessFormula);
});
sheet.getRange(headerRow, 0, RELEASE_READINESS_ROWS.length + 1, 6).setBorder(border, { all: true });
} finally {
sheet.resumePaint();
}
}
var SERVICE_HEALTH_CARDS = [
{ title: "API 可用性", subtitle: "7 天正常运行率", value: 0.99, target: 0.99, warningThreshold: 0.97, note: "2 起故障已自动恢复" },
{ title: "故障 SLA", subtitle: "P1 响应时间", value: 0.86, target: 0.95, warningThreshold: 0.8, note: "22 条告警中有 3 条超时" },
{ title: "错误预算", subtitle: "本月剩余额度", value: 0.64, target: 0.75, warningThreshold: 0.55, note: "暂不需要冻结发布" },
{ title: "CPU 余量", subtitle: "集群峰值预留", value: 0.72, target: 0.7, warningThreshold: 0.6, note: "扩容窗口仍然开放" },
{ title: "补丁合规率", subtitle: "已打补丁服务器", value: 0.91, target: 0.9, warningThreshold: 0.8, note: "2 个边缘节点等待重启" },
{ title: "队列清理", subtitle: "积压清理进度", value: 0.58, target: 0.7, warningThreshold: 0.5, note: "计费队列仍然偏高" },
{ title: "备份完成率", subtitle: "夜间作业", value: 0.97, target: 0.95, warningThreshold: 0.85, note: "还有一次归档重试待完成" },
{ title: "证书续期", subtitle: "30 天内到期", value: 0.42, target: 0.8, warningThreshold: 0.6, note: "3 个网关尚未轮换" }
];
function configureServiceHealthSheet(sheet) {
var headerRow = 0;
var metricRows = {
subtitle: 1,
current: 2,
target: 3,
health: 4,
note: 5,
progress: 6
};
var serviceStartColumn = 1;
var cardCount = SERVICE_HEALTH_CARDS.length;
var totalRows = 7;
var totalColumns = serviceStartColumn + cardCount;
var border = createBorder("#d8e0ea");
sheet.suspendPaint();
try {
configureSheetBase(sheet, "服务健康度", totalRows, totalColumns);
registerServiceHealthNames(sheet);
sheet.options.gridline.showVerticalGridline = true;
sheet.options.gridline.showHorizontalGridline = true;
sheet.setColumnWidth(0, 165);
setUniformColumnWidths(sheet, serviceStartColumn, cardCount, 210);
styleHeaderRow(sheet, headerRow, totalColumns, "#f3f6fb", "#314155");
sheet.getRange(headerRow, 0, 1, totalColumns).font("bold 14px Segoe UI");
sheet.addSpan(headerRow, 0, 2, 1);
sheet.setValue(headerRow, 0, "指标");
setRowHeights(sheet, {
0: 38,
1: 30,
2: 38,
3: 34,
4: 34,
5: 54,
6: 116
});
sheet.getCell(headerRow, 0)
.hAlign(HA.center)
.vAlign(VA.center);
applyRangeStyle(sheet.getRange(metricRows.subtitle, serviceStartColumn, 1, cardCount), {
backColor: "#f8fafc",
foreColor: "#64748b",
font: "12px Segoe UI",
wordWrap: true,
hAlign: HA.center,
vAlign: VA.center
});
sheet.setArray(metricRows.current, 0, [["当前值"], ["目标值"], ["健康状态"], ["备注"], ["进度"]]);
[metricRows.current, metricRows.target, metricRows.health, metricRows.note, metricRows.progress].forEach(function (row) {
sheet.getCell(row, 0)
.font("bold 14px Segoe UI")
.foreColor("#475569")
.backColor("#f8fafc")
.hAlign(HA.center)
.vAlign(VA.center);
});
applyRangeStyle(sheet.getRange(metricRows.current, serviceStartColumn, 1, cardCount), {
font: "bold 13px Segoe UI",
foreColor: "#0f172a",
hAlign: HA.center,
vAlign: VA.center,
formatter: "0%"
});
applyRangeStyle(sheet.getRange(metricRows.target, serviceStartColumn, 1, cardCount), {
font: "13px Segoe UI",
foreColor: "#475569",
hAlign: HA.center,
vAlign: VA.center,
formatter: "0%"
});
applyRangeStyle(sheet.getRange(metricRows.health, serviceStartColumn, 1, cardCount), {
font: "bold 13px Segoe UI",
backColor: "#ffffff",
hAlign: HA.center,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(metricRows.note, serviceStartColumn, 1, cardCount), {
font: "13px Segoe UI",
foreColor: "#64748b",
backColor: "#ffffff",
wordWrap: true,
hAlign: HA.left,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(metricRows.progress, serviceStartColumn, 1, cardCount), {
backColor: "#ffffff",
hAlign: HA.center,
vAlign: VA.center
});
var healthRange = [new spreadNS.Range(metricRows.health, serviceStartColumn, 1, cardCount)];
applySpecificTextColorRules(sheet, healthRange, {
"健康": "#15803d",
"预警": "#d97706",
"严重": "#dc2626"
});
sheet.setArray(headerRow, serviceStartColumn, [SERVICE_HEALTH_CARDS.map(function (card) { return card.title; })]);
sheet.setArray(metricRows.subtitle, serviceStartColumn, [SERVICE_HEALTH_CARDS.map(function (card) { return card.subtitle; })]);
sheet.setArray(metricRows.current, serviceStartColumn, [SERVICE_HEALTH_CARDS.map(function (card) { return card.value; })]);
sheet.setArray(metricRows.target, serviceStartColumn, [SERVICE_HEALTH_CARDS.map(function (card) { return card.target; })]);
sheet.setArray(metricRows.note, serviceStartColumn, [SERVICE_HEALTH_CARDS.map(function (card) { return card.note; })]);
for (var index = 0; index < SERVICE_HEALTH_CARDS.length; index++) {
var card = SERVICE_HEALTH_CARDS[index];
var col = serviceStartColumn + index;
var currentValueRef = columnName(col) + (metricRows.current + 1);
var targetValueRef = columnName(col) + (metricRows.target + 1);
var healthFormula = buildServiceHealthFormula(currentValueRef, targetValueRef, card.warningThreshold);
var sparklineFormula = buildServiceHealthSparklineFormula(currentValueRef, targetValueRef, card.warningThreshold);
sheet.setFormula(metricRows.health, col, healthFormula);
sheet.setFormula(metricRows.progress, col, sparklineFormula);
}
sheet.getRange(headerRow, 0, metricRows.progress - headerRow + 1, totalColumns).setBorder(border, { all: true });
} finally {
sheet.resumePaint();
}
}
var TRAINING_ROWS = [
{ learner: "Emma Johnson", program: "管理员认证", modulesDone: 11, totalModules: 12, nextStep: "预约最终考试" },
{ learner: "Liam Smith", program: "API 集成课程", modulesDone: 8, totalModules: 12, nextStep: "完成结课实验" },
{ learner: "Olivia Davis", program: "模板设计训练营", modulesDone: 6, totalModules: 10, nextStep: "复习第 7 模块" },
{ learner: "Noah Wilson", program: "迁移专家课程", modulesDone: 4, totalModules: 9, nextStep: "参加辅导会议" },
{ learner: "Ava Martinez", program: "仪表板制作", modulesDone: 12, totalModules: 12, nextStep: "提交认证徽章" },
{ learner: "Ethan Brown", program: "Designer 高级用户", modulesDone: 7, totalModules: 8, nextStep: "安排实操评审" },
{ learner: "Sophia Lee", program: "工作簿自动化", modulesDone: 5, totalModules: 11, nextStep: "完成实验工作簿" },
{ learner: "Mason Taylor", program: "报表制作", modulesDone: 9, totalModules: 14, nextStep: "准备同伴评估" },
{ learner: "Isabella Wang", program: "治理与审计", modulesDone: 10, totalModules: 10, nextStep: "归档完成记录" },
{ learner: "Lucas Chen", program: "计算引擎", modulesDone: 3, totalModules: 8, nextStep: "补齐核心公式课程" }
];
var LEARNING_PROGRESS_FORMATTER = '=PROGRESSSPARKLINE(@,2,"#6B7C93","#E7EDF5",TRUE)';
function configureLearningProgressSheet(sheet) {
var headerRow = 0;
var dataStartRow = 1;
var rowCount = TRAINING_ROWS.length;
var totalRows = dataStartRow + rowCount;
var border = createBorder("#d7dee7");
sheet.suspendPaint();
try {
configureSheetBase(sheet, "学习进度", totalRows, 6);
setColumnWidths(sheet, [170, 210, 110, 110, 320, 210]);
styleHeaderRow(sheet, headerRow, 6, "#f3f6fb", "#314155");
setHeaderValues(sheet, headerRow, ["学员", "课程", "已完成模块", "总模块数", "完成度", "下一步"]);
sheet.setRowHeight(headerRow, 30);
applyRangeStyle(sheet.getRange(dataStartRow, 0, rowCount, 1), {
font: "bold 13px Segoe UI",
foreColor: "#0f172a",
hAlign: HA.left,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(dataStartRow, 1, rowCount, 1), {
font: "12px Segoe UI",
foreColor: "#475569",
hAlign: HA.left,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(dataStartRow, 2, rowCount, 2), {
font: "12px Consolas",
foreColor: "#334155",
hAlign: HA.right,
vAlign: VA.center
});
applyRangeStyle(sheet.getRange(dataStartRow, 4, rowCount, 1), {
backColor: "#ffffff",
hAlign: HA.center,
vAlign: VA.center,
formatter: LEARNING_PROGRESS_FORMATTER
});
applyRangeStyle(sheet.getRange(dataStartRow, 5, rowCount, 1), {
font: "12px Segoe UI",
foreColor: "#475569",
backColor: "#ffffff",
hAlign: HA.left,
vAlign: VA.center
});
sheet.setArray(dataStartRow, 0, toColumnMatrix(TRAINING_ROWS, function (item) { return item.learner; }));
sheet.setArray(dataStartRow, 1, toColumnMatrix(TRAINING_ROWS, function (item) { return item.program; }));
sheet.setArray(dataStartRow, 2, TRAINING_ROWS.map(function (item) { return [item.modulesDone, item.totalModules]; }));
sheet.setArray(dataStartRow, 5, toColumnMatrix(TRAINING_ROWS, function (item) { return item.nextStep; }));
TRAINING_ROWS.forEach(function (item, index) {
var row = dataStartRow + index;
var modulesDoneRef = columnName(2) + (row + 1);
var totalModulesRef = columnName(3) + (row + 1);
var formula = '=IF(' + totalModulesRef + '=0,0,' + modulesDoneRef + '/' + totalModulesRef + ')';
sheet.setRowHeight(row, 44);
sheet.setFormula(row, 4, formula);
});
sheet.getRange(headerRow, 0, TRAINING_ROWS.length + 1, 6).setBorder(border, { all: true });
} finally {
sheet.resumePaint();
}
}
<!doctype html>
<html style="height: 100%; font-size: 14px;">
<head>
<meta charset="utf-8" />
<meta name="spreadjs culture" content="zh-cn" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="ss" class="sample-spreadsheets" aria-live="polite"></div>
<noscript>
<div class="load-error">需要启用 JavaScript 才能加载此 demo。</div>
</noscript>
</body>
</html>
html,
body {
height: 100%;
margin: 0;
}
body {
position: absolute;
inset: 0;
background: #ffffff;
}
.sample-spreadsheets {
width: 100%;
height: 100%;
overflow: hidden;
background: #ffffff;
}