| | |
| | | } |
| | | |
| | | /** |
| | | * 获取纯单元格引用公式的坐标名,例如 =F4、=$F$4。 |
| | | * 纯引用应直接复制原值,避免把“外观”等中文文本送入数值计算。 |
| | | */ |
| | | function getDirectReferenceName(f) { |
| | | if (typeof f !== "string") { |
| | | return null; |
| | | } |
| | | const matched = f.trim().match(/^=\s*\$?([A-Za-z]{1,3})\$?(\d{1,7})\s*$/); |
| | | return matched ? `${matched[1].toUpperCase()}${matched[2]}` : null; |
| | | } |
| | | |
| | | /** |
| | | * 按检验项id取当前样品下的检验项信息,取不到时返回空对象,避免公式计算因缺项中断 |
| | | * |
| | | * @param id 检验项id |
| | |
| | | // 如果是函数方法,则执行此方法 |
| | | let comResult = ""; //初始化计算结果 |
| | | try { |
| | | if ( |
| | | const directReferenceName = getDirectReferenceName(item.v.f); |
| | | if (directReferenceName && Object.prototype.hasOwnProperty.call(comValue, directReferenceName)) { |
| | | // =F4 这类公式既可能引用数字,也可能引用中文文本,直接保留源值。 |
| | | comResult = comValue[directReferenceName]; |
| | | } else if ( |
| | | getInspectionValueType(item.i) == 1 || |
| | | isNumericFormula(item.v.f) |
| | | ) { |
| | |
| | | return "断裂脆化"; |
| | | } |
| | | } |
| | | // 参数代入后含中文时(如检验值填了"均匀"),不能再当公式 eval —— |
| | | // eval("均匀") 会抛 ReferenceError,被外层 catch 吞掉后返回 undefined, |
| | | // 该单元格的结果既不写回也不向下游公式传递,整条计算链断在这里 |
| | | if (/[一-龥]/.test(str)) { |
| | | return str.trim(); |
| | | } |
| | | // 计算常规的 |
| | | const value = eval(str); |
| | | // 除零等非有限结果不写回单元格(与 Excel 的 #DIV/0! 一致:不出值) |