我正在使用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"}]
非常感谢任何帮助。
答案 0 :(得分:0)
我相信你必须用"text"
这样的双引号将你想要的项目包围起来,并留下你的数字。
答案 1 :(得分:0)
将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数据和您用于导出的代码。