Export data from JSON to do well while preserving data type

I am using alasql.js file to export JSON data to excel file. The problem I am running into is that when I export data, it exports without any problem, but columns that are of type as number are exported as text in excel.

Does anyone know of any alternative library for exporting data from json to excel while maintaining data type.

My JSON looks like this: -

[{"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"}]

      

Any help is greatly appreciated.

+3


source to share


2 answers


I believe you will have to surround the elements you want with double quoted strings like "text"

and leave your numbers alone.



0


source


Convert your JSON string to javascript object and then export it.

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]);

      



If you are still unable to resolve this issue, please post the JSON data and the code you are using to export.

0


source







All Articles