通过保留数据类型将数据从 JSON 导出到 Excel



我正在使用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"}]

任何帮助将不胜感激。

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

将 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 数据和代码。

相关内容

  • 没有找到相关文章

最新更新