Exceljs数据验证列表导致Excel女士出错

时间:2017-12-29 08:58:49

标签: node.js exceljs

我使用exceljs节点模块并添加下拉数据验证

 private void trustEveryone() {
 try {
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }});
    SSLContext context = SSLContext.getInstance("TLS");
    context.init(null, new X509TrustManager[]{new X509TrustManager(){
        public void checkClientTrusted(X509Certificate[] chain,
                                       String authType) throws CertificateException {}
        public void checkServerTrusted(X509Certificate[] chain,
                                       String authType) throws CertificateException {}
        public X509Certificate[] getAcceptedIssuers() {
            return new X509Certificate[0];
        }}}, new SecureRandom());
    HttpsURLConnection.setDefaultSSLSocketFactory(
            context.getSocketFactory());
    } catch (Exception e) { // should never happen
    e.printStackTrace();
    }
}

文件已成功生成。但它只能使用Libre Office打开。与Ms.女士打开文件将导致以下错误:

worksheet.getCell(cell).dataValidation = {
  type: 'list',
  allowBlank: true,
  formulae: ['"One,Two,Three,Four"'],
  showErrorMessage: true,
  errorStyle: 'error',
  errorTitle: 'Error',
  error: 'Value must be in the list'
};

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

在数据验证公式中反引号。看起来它仅支持并识别另一个

worksheet.getCell(cell).dataValidation=
{
    type : "list",
    allowBlank : true,
    formulae : ["'One,Two,Three,Four'"],//<--------------------------------Right there
    showErrorMessage : true,
    errorStyle : "error",
    errorTitle : "Error",
    error : "Value must be in the list"
}

};