export const ERROR = 'ERROR'; export const ERROR_DIV_ZERO = 'DIV/0'; export const ERROR_NAME = 'NAME'; export const ERROR_NOT_AVALABLE = 'N/A'; export const ERROR_NULL = 'NULL'; export const ERROR_NUM = 'NUM'; export const ERROR_REF = 'REF'; export const ERROR_VALUE = 'VALUE'; const errors: Record = { [ERROR]: '#ERROR!', [ERROR_DIV_ZERO]: '#DIV/0!', // 例: 不存在的操作符, 如 + 号写成了 汉字 [ERROR_NAME]: '#NAME?', [ERROR_NOT_AVALABLE]: '#N/A', [ERROR_NULL]: '#NULL!', [ERROR_NUM]: '#NUM!', [ERROR_REF]: '#REF!', // 计算结果错. 例: isNaN [ERROR_VALUE]: '#VALUE!', }; // DIV/0 => #DIV/0! export function getExcelError(type: string): string | null { type = (type + '').replace(/#|!|\?/g, ''); return errors[type] || null; } export function isValidErrorType(type: string) { return Object.keys(errors).includes(type); }