自定义函数 JSA_A_BASE64STRINGTOSTRING base64字符串转字符串

function JSA_A_BASE64STRINGTOSTRING(base64String, label, endianness, hasBom) { // base64String 转 String
       //表格中使用函数,参数留空时,默认值处理
    base64String = (base64String === undefined || base64String === -2147352572) ? undefined : base64String;
    label = (label === undefined || label === -2147352572) ? undefined : label;
    endianness = (endianness === undefined || endianness === -2147352572) ? undefined : endianness;
    hasBom = (hasBom === undefined || hasBom === -2147352572) ? undefined : hasBom;
    
    // 参数验证和默认值处理
    base64String = Array.isArray(base64String.valueOf()) ? base64String.valueOf().flat(Infinity).join("") : base64String.valueOf();
    label = (label || 'utf-8').toLowerCase();
    endianness = (endianness || 'BE').toUpperCase();
    hasBom = hasBom || false;
    
    // 验证参数有效性
    if (base64String === undefined || base64String === "") {
        return "#N/A";
    }
    
    if (!['utf-8', 'utf-16'].includes(label)) {
        return "#N/A";
    }
    
    if (!['BE', 'LE'].includes(endianness)) {
        return "#N/A";
    }
    
    if (label === 'utf-8') {
        let uint8Array = Run("JSA_A_BASE64STRINGTOUINT8ARRAY", base64String);
        let string = Run("JSA_A_UINT8ARRAYTOUTF8TOSTRING", uint8Array, undefined);
        return string;
    }
    
    if (label == 'utf-16') {
        let uint8Array = Run("JSA_A_BASE64STRINGTOUINT8ARRAY", base64String);
        let string = Run("JSA_A_UINT8ARRAYTOUTF16TOSTRING", uint8Array, undefined, endianness, hasBom);
        return string;
    }
}

插入函数对话框、函数参数对话框:

加载宏文件function Workbook_Open(){}中添加以下代码。

Application.MacroOptions("JSA_A_BASE64STRINGTOSTRING", "base64字符串 转 字符串", undefined, undefined, undefined, undefined, 14, undefined, undefined, undefined, ['base64字符串。', '字符串编码。"utf-8"(默认)、"utf-16"。', '字节序,"utf-16"需指定。"BE":大端序(高位字节在前)(默认),"LE":小端序(低位字节在前)。', '是否包含字节序标记(BOM),"utf-16"需指定。TRUE:包含,FALSE:不包含(默认)。']);

云南省
浏览 14
收藏
1
分享
1 +1
1
+1
全部评论 1
 
497128657
关系图:https://bbs.wps.cn/topic/68275
· 云南省
回复