我有一个简单的Web应用程序,可以使用SheetJS从XML生成Excel文件。
代码:
data.push({
"Car Make": car.make,
"Car Model": car.model,
"Engine Type": car.engine.type,
"Engine HP": car.engine.hp
});
var wb = XSLX.utils.book_new();
filename = "Workbook"
wb.Props = {
Title: filename,
Subject: "",
Author: ""
};
wb.sheetNames.push("Cars and Engines");
wb.Sheets["Cars and Engines"] = XLSX.utils.json_to_sheet(data);
输出:
Car Make | Car Model | Engine Type | Engine HP
---------+-----------+-------------+-----------
Ford | F150 | V8 | 290
Dodge | Viper | V10 | 645
代码:
data.push({
"Car":{
"Make":car.make,
"Model":car.model
},
"Engine":{
"Type":engine.type,
"HP":engine.hp
}
});
输出:
Car | Engine
----+-------
|
|
Car | Engine <--.
Make | Model | Type | HP <---'- Two Headers
------+-------+------+-----
Ford | F150 | V8 | 290
Dodge | Viper | V10 | 645
是否可以通过SheetJS来做到这一点?