| | |
| | | let min = null; |
| | | if(val&&val.length>0){ |
| | | val = val.filter(item=>item!=null&&item!=='') |
| | | console.log(val) |
| | | // console.log(val) |
| | | if(val.length>0){ |
| | | min = Math.min(...val) |
| | | } |
| | |
| | | } |
| | | }else{ |
| | | return null; |
| | | } |
| | | } catch (error) { |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计算幂 |
| | | * |
| | | * @param str 字符串形式的幂表达式,例如"2^3" |
| | | * @returns 返回计算后的幂值,如果表达式无效则返回null |
| | | */ |
| | | function CalculatePower(str){ |
| | | try { |
| | | if(str&&str.includes('^')){ |
| | | let arr = str.split('^'); |
| | | if(arr&&arr.length>1){ |
| | | return Math.pow(arr[0],arr[1]); |
| | | }else{ |
| | | return null; |
| | | } |
| | | } |
| | | } catch (error) { |
| | | |
| | |
| | | 'MAX', |
| | | 'MIN', |
| | | 'AVERAGE', |
| | | 'APS', |
| | | 'ABS', |
| | | ] |
| | | f = f.replace(regex, ',') |
| | | f = f.replace(regex, ',').replace(new RegExp('"&', 'g'),'').replace(new RegExp('&"', 'g'),'') |
| | | fouList.forEach(item=>{ |
| | | f = f.replaceAll(item,',') |
| | | f = f.replace(new RegExp(item, 'g'),'') |
| | | }) |
| | | // console.log('f',f) |
| | | let arr = f.split(',').filter(item=>{ |
| | | return item&& /[a-zA-Z]/.test(item)&&item!='undefined'&&item!='null' |
| | | }); |
| | |
| | | // 获取单元格对应值 |
| | | let arr = getAllCell(f) |
| | | for (var a in comValue) { |
| | | if(comValue[a]!=='undefine'&&comValue[a]!=='null'&&comValue[a]!==undefined){ |
| | | arr[a] = comValue[a] |
| | | if(comValue[a]!=='undefined'&&comValue[a]!=='null'&&comValue[a]!==undefined){ |
| | | if(typeof(comValue[a])=='string'&&comValue[a].includes('^')){ |
| | | // 计算幂次 |
| | | arr[a] = CalculatePower(comValue[a]) |
| | | } else if (typeof(comValue[a])=='string'&&comValue[a].includes('/')) { |
| | | arr[a] = comValue[a] |
| | | } else{ |
| | | arr[a] = comValue[a] |
| | | } |
| | | } |
| | | } |
| | | // 解析公式参数,特别是带:的 |
| | |
| | | obj[item] = item |
| | | } |
| | | }) |
| | | str = str.replaceAll(':', '-') |
| | | str = str.replace(new RegExp(':', 'g'),'') |
| | | // 替换参数 |
| | | for (var a in obj) { |
| | | str = str.replaceAll(a, obj[a]) |
| | | str = str.replace(new RegExp(a, 'g'),obj[a]) |
| | | } |
| | | // 计算 |
| | | for (var a in arr) { |
| | | str = str.replaceAll(a, arr[a]) |
| | | str = str.replace(new RegExp(a, 'g'),arr[a]) |
| | | } |
| | | return eval(str) |
| | | } catch (error) { |