3

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

任何帮助是极大的赞赏。

4

2 回答 2

0

我相信你将不得不用双引号将你想要的项目作为字符串括起来"text",并留下你的数字。

于 2015-07-04T05:09:59.680 回答
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 数据和您用于导出的代码。

于 2015-07-04T05:38:38.737 回答