【问题标题】:Export data from JSON to excel by preserving data type [closed]通过保留数据类型将数据从 JSON 导出到 excel [关闭]
【发布时间】:2015-08-31 01:46:17
【问题描述】:

我正在使用alasql.js 文件将 JSON 数据导出到 excel 文件中。 我面临的问题是,当我导出数据时,它导出没有任何问题,但是类型为数字的列在 Excel 中导出为文本。

有谁知道任何替代库可以将数据从 json 导出到 excel 并保留数据类型。

我的 JSON 是这样的:--

[{"emplId":"Empl Id","emplName":"Empl Name","formNumber":"Form Number","costCenter":"Cost Center","emplDept":"Empl Dept","invoiceNumber":"Invoice Number","totalPrice":"Total Price","purchaseDate":"Purchase Date","shoesStyle":"Shoes Style","shoesSize":"Shoes Size","shoesWidth":"Shoes Width","companyname":"Companyname","shoePrice":"Shoe Price","taxAmountPaid":"Tax Amount Paid","shippinghandling":"Shippinghandling","typeofPurchase":"Typeof Purchase","storeAccountNumber":"Store Account Number","refundFlag":"Refund Flag","manufacturer":"Manufacturer"},
{"emplId":1234567,"emplName":"Kevin W Hays","formNumber":5734,"costCenter":"PM555","emplDept":"SUPPLY","invoiceNumber":"ACCC1213","totalPrice":201.45,"purchaseDate":"01/05/2015","shoesStyle":"W02053","shoesSize":11,"shoesWidth":"E3","companyname":"XXX","shoePrice":180,"taxAmountPaid":21.45,"shippinghandling":"","typeofPurchase":"Store","storeAccountNumber":"1707401","refundFlag":"N","manufacturer":"XXX"}]

非常感谢任何帮助。

【问题讨论】:

  • 感谢您报告问题!我们为此 github.com/agershun/alasql/issues/305 打开了问题。希望,我们会在一两天内修复它。
  • 你的 json 是什么样的?数字是 "stringed" (aNumber:"2") 还是不是 (aNumber:2)?

标签: javascript json frontend alasql


【解决方案1】:

我相信你必须将你想要的项目用双引号括起来,比如"text",不要管你的数字。

【讨论】:

    【解决方案2】:

    将 JSON 字符串转换为 javascript 对象,然后将其导出。

    var jsonString = "[{\"city\":\"Minsk\",\"population\":100000},{\"city\":\"Riga\",\"population\":200000}]";
    
    var jsonObject = JSON.stringify(jsonString);
    
    alasql("SELECT * INTO XLSX('cities.xlsx',{headers:true}) FROM ? ",[jsonObject]);
    

    如果您仍然无法解决,请发布 JSON 数据和您用于导出的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多